CMakeLists.txt (view raw)
1cmake_minimum_required(VERSION 3.1)
2list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/src/platform/cmake/")
3
4if(POLICY CMP0025)
5 cmake_policy(SET CMP0025 NEW)
6endif()
7if(POLICY CMP0072)
8 cmake_policy(SET CMP0072 NEW)
9 set(OpenGL_GL_PREFERENCE LEGACY)
10endif()
11
12project(mGBA)
13
14if(NOT DEFINED LIBMGBA_ONLY)
15 get_directory_property(LIBMGBA_ONLY EXCLUDE_FROM_ALL)
16endif()
17
18if(NOT DEFINED BINARY_NAME)
19 set(BINARY_NAME mgba)
20endif()
21if(NOT LIBMGBA_ONLY)
22 set(BINARY_NAME ${BINARY_NAME} CACHE INTERNAL "Name of output binaries")
23endif()
24
25set(CMAKE_C_STANDARD 99)
26if(NOT MSVC)
27 set(CMAKE_C_STANDARD_REQUIRED ON)
28 set(CMAKE_C_EXTENSIONS OFF)
29 if(SWITCH OR 3DS)
30 set(CMAKE_C_STANDARD 11)
31 set(CMAKE_C_EXTENSIONS ON)
32 elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.3")
33 set(CMAKE_C_EXTENSIONS ON)
34 endif()
35 set(WARNING_FLAGS "-Wall -Wextra -Wno-missing-field-initializers")
36 if(WIN32)
37 # mingw32 likes to complain about using the "wrong" format strings despite them actually working
38 set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-format")
39 endif()
40 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=implicit-function-declaration")
41 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
42else()
43 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146 /wd4267")
44 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146 /wd4267")
45endif()
46
47if(NOT LIBMGBA_ONLY)
48 set(USE_DEBUGGERS ON CACHE BOOL "Whether or not to enable the debugging infrastructure")
49 if (NOT WIN32)
50 set(USE_EDITLINE ON CACHE BOOL "Whether or not to enable the CLI-mode debugger")
51 endif()
52 set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger")
53 set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support")
54 set(USE_ZLIB ON CACHE BOOL "Whether or not to enable zlib support")
55 set(USE_MINIZIP ON CACHE BOOL "Whether or not to enable external minizip support")
56 set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
57 set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable LIBZIP support")
58 set(USE_SQLITE3 ON CACHE BOOL "Whether or not to enable SQLite3 support")
59 set(USE_ELF ON CACHE BOOL "Whether or not to enable ELF support")
60 set(M_CORE_GBA ON CACHE BOOL "Build Game Boy Advance core")
61 set(M_CORE_GB ON CACHE BOOL "Build Game Boy core")
62 set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
63 set(USE_DISCORD_RPC ON CACHE BOOL "Whether or not to enable Discord RPC support")
64 set(ENABLE_SCRIPTING ON CACHE BOOL "Whether or not to enable scripting support")
65 set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
66 set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
67 set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
68 if(APPLE)
69 set(BUILD_OPENEMU OFF CACHE BOOL "Build OpenEmu core")
70 endif()
71 set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
72 set(BUILD_TEST OFF CACHE BOOL "Build testing harness")
73 set(BUILD_SUITE OFF CACHE BOOL "Build test suite")
74 set(BUILD_CINEMA OFF CACHE BOOL "Build video tests suite")
75 set(BUILD_EXAMPLE OFF CACHE BOOL "Build example frontends")
76 set(BUILD_PYTHON OFF CACHE BOOL "Build Python bindings")
77 set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
78 set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
79 set(SKIP_LIBRARY OFF CACHE BOOL "Skip building the library (useful for only building libretro or OpenEmu cores)")
80 set(BUILD_GL ON CACHE BOOL "Build with OpenGL")
81 set(BUILD_GLES2 ON CACHE BOOL "Build with OpenGL|ES 2")
82 set(BUILD_GLES3 OFF CACHE BOOL "Build with OpenGL|ES 3")
83 set(USE_EPOXY ON CACHE STRING "Build with libepoxy")
84 set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies")
85 set(DISTBUILD OFF CACHE BOOL "Build distribution packages")
86 if(WIN32)
87 set(WIN32_UNIX_PATHS OFF CACHE BOOL "Use Unix-like paths")
88 mark_as_advanced(WIN32_UNIX_PATHS)
89 endif()
90else()
91 set(DISABLE_FRONTENDS ON)
92 set(DISABLE_DEPS ON)
93 set(BUILD_STATIC ON)
94 set(BUILD_SHARED OFF)
95 if(NOT DEFINED M_CORE_GBA)
96 set(M_CORE_GBA ON)
97 endif()
98 if(NOT DEFINED M_CORE_GB)
99 set(M_CORE_GB ON)
100 endif()
101endif()
102
103file(GLOB THIRD_PARTY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/inih/*.c)
104set(CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-mem.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fifo.c)
105set(VFS_SRC)
106include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/include)
107
108if(NOT CMAKE_BUILD_TYPE)
109 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release, RelWithDebInfo, or Debug)" FORCE)
110endif()
111
112if(UNIX OR WIN32_UNIX_PATHS)
113 include(GNUInstallDirs)
114else()
115 set(CMAKE_INSTALL_LIBDIR ".")
116 set(CMAKE_INSTALL_BINDIR ".")
117 set(CMAKE_INSTALL_DATADIR ".")
118 set(CMAKE_INSTALL_DOCDIR ".")
119 set(CMAKE_INSTALL_INCLUDEDIR "include")
120endif()
121
122if(NOT DEFINED LIBDIR)
123 set(LIBDIR "${CMAKE_INSTALL_LIBDIR}")
124endif()
125if(NOT LIBMGBA_ONLY)
126 set(LIBDIR "${LIBDIR}" CACHE PATH "Installed library directory")
127 mark_as_advanced(LIBDIR)
128endif()
129
130if (BUILD_LIBRETRO)
131 set(LIBRETRO_LIBDIR "${LIBDIR}" CACHE PATH "Installed library directory (Libretro)")
132 mark_as_advanced(LIBRETRO_LIBDIR)
133endif()
134
135if (BUILD_OPENEMU)
136 set(OE_LIBDIR "${LIBDIR}" CACHE PATH "Installed library directory (OpenEmu)")
137 mark_as_advanced(OE_LIBDIR)
138endif()
139
140if (DISTBUILD)
141 set(EXTRA_LICENSES "" CACHE FILEPATH "Extra licenses to include in distribution packaages")
142 mark_as_advanced(EXTRA_LICENSES)
143endif()
144mark_as_advanced(DISTBUILD)
145
146set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
147
148if (NOT DEFINED MANDIR)
149 set(MANDIR ${CMAKE_INSTALL_MANDIR})
150endif()
151
152include(FindFeature)
153
154# Version information
155add_custom_target(${BINARY_NAME}-version-info ALL
156 COMMAND ${CMAKE_COMMAND}
157 -DBINARY_NAME=${BINARY_NAME}
158 -DCONFIG_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/core/version.c.in
159 -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.c
160 -P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
161 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
162
163include(${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
164configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
165
166source_group("Generated sources" FILES ${CMAKE_CURRENT_BINARY_DIR}/version.c)
167
168# Advanced settings
169if(NOT (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_COMPILER_VERSION VERSION_LESS "4.5"))
170 set(DEFAULT_LTO ON)
171else()
172 set(DEFAULT_LTO OFF)
173endif()
174
175if(NOT LIBMGBA_ONLY)
176 set(BUILD_LTO ${DEFAULT_LTO} CACHE BOOL "Build with link-time optimization")
177 set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
178 set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
179 set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
180 mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
181endif()
182set(PGO_PRE_FLAGS "-fprofile-generate=${PGO_DIR} -fprofile-arcs")
183set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
184
185if(BUILD_PGO AND CMAKE_SYSTEM_NAME STREQUAL "Generic")
186 add_definitions(-DTARGET_POSIX_IO)
187endif()
188
189if(BUILD_PGO AND NOT PGO_STAGE_2)
190 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
191 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
192 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
193 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
194elseif(BUILD_PGO AND PGO_STAGE_2)
195 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
196 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
197 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
198 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
199endif()
200
201# Platform support
202if(WIN32)
203 set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
204 add_definitions(-D_WIN32_WINNT=0x0600)
205 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
206 if(MSVC)
207 add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
208 add_definitions(-D_UNICODE -DUNICODE)
209 else()
210 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -municode")
211 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode")
212 endif()
213 list(APPEND OS_LIB ws2_32 shlwapi)
214 list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/vfs-w32.c)
215 file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c)
216 source_group("Windows-specific code" FILES ${OS_SRC})
217elseif(UNIX)
218 set(USE_PTHREADS ON)
219
220 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
221 add_definitions(-D_GNU_SOURCE)
222 endif()
223
224 list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
225 file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/posix/*.c)
226 source_group("POSIX-specific code" FILES ${OS_SRC})
227endif()
228
229if(APPLE)
230 add_definitions(-D_DARWIN_C_SOURCE)
231 if(CMAKE_SYSTEM_VERSION VERSION_GREATER "10.5.8")
232 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
233 endif()
234endif()
235
236if(NOT HAIKU AND NOT MSVC AND NOT PSP2)
237 set(M_LIBRARY m)
238endif()
239list(APPEND OS_LIB ${M_LIBRARY})
240
241if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
242 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
243 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
244endif()
245
246if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
247 find_program(OBJCOPY ${cross_prefix}objcopy)
248 find_program(STRIP ${cross_prefix}strip)
249
250 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -gdwarf")
251 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf")
252endif()
253
254if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
255 if(NOT BUILD_EGL)
256 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
257 endif()
258endif()
259
260if(BUILD_RASPI)
261 set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
262endif()
263
264if(BUILD_PANDORA)
265 add_definitions(-DBUILD_PANDORA)
266endif()
267
268if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
269 enable_language(ASM)
270endif()
271
272if(PSP2)
273 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
274endif()
275
276if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII OR DEFINED SWITCH)
277 set(IS_EMBEDDED ON)
278 set(USE_DEBUGGERS OFF)
279 set(USE_SQLITE3 OFF)
280 set(USE_DISCORD_RPC OFF)
281 set(USE_LIBZIP OFF CACHE BOOL "")
282endif()
283
284if(DEFINED SWITCH)
285 set(BUILD_GLES2 OFF CACHE BOOL "Build with OpenGL|ES 2" FORCE)
286 set(BUILD_GLES3 ON CACHE BOOL "Build with OpenGL|ES 3" FORCE)
287endif()
288
289if(NOT M_CORE_GBA)
290 set(USE_GDB_STUB OFF)
291endif()
292
293if(NOT USE_DEBUGGERS)
294 set(USE_EDITLINE OFF)
295 set(USE_GDB_STUB OFF)
296endif()
297
298if(WII)
299 add_definitions(-U__STRICT_ANSI__)
300endif()
301
302include(CheckCCompilerFlag)
303include(CheckFunctionExists)
304include(CheckIncludeFiles)
305check_function_exists(strdup HAVE_STRDUP)
306check_function_exists(strndup HAVE_STRNDUP)
307check_function_exists(strlcpy HAVE_STRLCPY)
308check_function_exists(vasprintf HAVE_VASPRINTF)
309if(NOT DEFINED PSP2)
310 check_function_exists(localtime_r HAVE_LOCALTIME_R)
311endif()
312check_include_files("xlocale.h" HAVE_XLOCALE)
313if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
314 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
315 if(ANDROID AND ANDROID_NDK_MAJOR GREATER 13)
316 set(HAVE_STRTOF_L ON)
317 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
318 # The strtof_l on Linux not actually exposed nor actually strtof_l
319 set(HAVE_STRTOF_L OFF)
320 else()
321 check_function_exists(strtof_l HAVE_STRTOF_L)
322 endif()
323 check_function_exists(newlocale HAVE_NEWLOCALE)
324 check_function_exists(freelocale HAVE_FREELOCALE)
325 check_function_exists(uselocale HAVE_USELOCALE)
326 check_function_exists(setlocale HAVE_SETLOCALE)
327else()
328 if(DEFINED 3DS OR DEFINED WII OR DEFINED SWITCH)
329 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,snprintf_l)
330 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
331 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,strtof_l)
332 check_function_exists(strtof_l HAVE_STRTOF_L)
333 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,newlocale)
334 check_function_exists(newlocale HAVE_NEWLOCALE)
335 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,freelocale)
336 check_function_exists(freelocale HAVE_FREELOCALE)
337 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,uselocale)
338 check_function_exists(uselocale HAVE_USELOCALE)
339 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,setlocale)
340 check_function_exists(setlocale HAVE_SETLOCALE)
341 unset(CMAKE_REQUIRED_FLAGS)
342 endif()
343 if(NOT IS_EMBEDDED)
344 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
345 endif()
346 set(BUILD_STATIC ON CACHE BOOL "" FORCE)
347 set(BUILD_SHARED OFF CACHE BOOL "" FORCE)
348 set(DISABLE_FRONTENDS ON)
349 set(MINIMAL_CORE ON)
350 set(ENABLE_EXTRA ON)
351endif()
352
353check_function_exists(chmod HAVE_CHMOD)
354check_function_exists(umask HAVE_UMASK)
355
356if(USE_PTHREADS)
357 check_include_files("pthread.h" HAVE_PTHREAD_H)
358 if(HAVE_PTHREAD_H)
359 check_c_compiler_flag(-pthread HAVE_PTHREAD)
360 if(HAVE_PTHREAD AND NOT APPLE AND NOT HAIKU)
361 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
362 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
363 endif()
364
365 check_function_exists(pthread_create HAVE_PTHREAD_CREATE)
366 if(HAVE_PTHREAD_CREATE)
367 add_definitions(-DUSE_PTHREADS)
368
369 check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
370
371 check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
372 check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
373 endif()
374 endif()
375endif()
376
377set(FUNCTION_DEFINES)
378
379if(HAVE_STRDUP)
380 list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
381endif()
382
383if(HAVE_STRNDUP)
384 list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
385endif()
386
387if(HAVE_STRLCPY)
388 list(APPEND FUNCTION_DEFINES HAVE_STRLCPY)
389endif()
390
391if(HAVE_VASPRINTF)
392 list(APPEND FUNCTION_DEFINES HAVE_VASPRINTF)
393endif()
394
395if(HAVE_LOCALTIME_R)
396 list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
397endif()
398
399if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE OR APPLE)
400 list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
401 if (HAVE_SNPRINTF_L)
402 list(APPEND FUNCTION_DEFINES HAVE_SNPRINTF_L)
403 endif()
404endif()
405
406if(HAVE_SETLOCALE)
407 list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
408endif()
409
410if (HAVE_STRTOF_L)
411 list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
412endif()
413
414if(HAVE_XLOCALE)
415 list(APPEND FUNCTION_DEFINES HAVE_XLOCALE)
416endif()
417
418if(HAVE_CHMOD)
419 list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
420endif()
421
422if(HAVE_UMASK)
423 list(APPEND FUNCTION_DEFINES HAVE_UMASK)
424endif()
425
426if(HAVE_PTHREAD_NP_H)
427 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_NP_H)
428endif()
429
430if(HAVE_PTHREAD_SETNAME_NP)
431 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SETNAME_NP)
432endif()
433
434if(HAVE_PTHREAD_SET_NAME_NP)
435 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SET_NAME_NP)
436endif()
437
438# Feature dependencies
439set(FEATURE_DEFINES)
440set(FEATURE_FLAGS)
441set(FEATURE_SRC)
442set(FEATURES)
443set(ENABLES)
444if(CMAKE_SYSTEM_NAME MATCHES ".*BSD|DragonFly")
445 set(LIBEDIT_LIBRARIES -ledit)
446 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
447 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
448 endif()
449else()
450 find_feature(USE_EDITLINE "libedit")
451endif()
452if(BUILD_GL)
453 find_package(OpenGL QUIET)
454 if(NOT OPENGL_FOUND)
455 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
456 elseif(UNIX AND NOT APPLE AND TARGET OpenGL::GL)
457 set(OPENGL_LIBRARY OpenGL::GL)
458 endif()
459endif()
460if(NOT BUILD_GL AND NOT LIBMGBA_ONLY)
461 set(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
462endif()
463if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|Darwin|Linux|.*BSD|DragonFly|Haiku)$")
464 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
465 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
466 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
467 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
468 endif()
469endif()
470if(NOT BUILD_GLES2 AND NOT LIBMGBA_ONLY)
471 set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
472endif()
473if(BUILD_GL)
474 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
475 list(APPEND FEATURE_DEFINES BUILD_GL)
476 list(APPEND DEPENDENCY_LIB ${OPENGL_LIBRARY})
477 include_directories(${OPENGL_INCLUDE_DIR})
478endif()
479if(BUILD_GLES2)
480 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
481 list(APPEND FEATURE_DEFINES BUILD_GLES2)
482 list(APPEND DEPENDENCY_LIB ${OPENGLES2_LIBRARY})
483 include_directories(${OPENGLES2_INCLUDE_DIR})
484endif()
485if(BUILD_GLES3)
486 find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
487 find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
488 list(APPEND FEATURE_DEFINES BUILD_GLES3)
489 if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
490 set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
491 endif()
492endif()
493
494if(DISABLE_DEPS)
495 set(USE_GDB_STUB OFF)
496 set(USE_DISCORD_RPC OFF)
497 set(USE_SQLITE3 OFF)
498 set(USE_PNG OFF)
499 set(USE_ZLIB OFF)
500endif()
501
502set(WANT_ZLIB ${USE_ZLIB})
503set(WANT_PNG ${USE_PNG})
504set(WANT_SQLITE3 ${USE_SQLITE3})
505set(USE_CMOCKA ${BUILD_SUITE})
506
507if(DEFINED VCPKG_TARGET_TRIPLET)
508 find_feature(USE_FFMPEG "FFMPEG")
509 if(FFMPEG_FOUND)
510 set(LIBAVRESAMPLE_FOUND OFF)
511 set(LIBSWRESAMPLE_FOUND ON)
512 endif()
513else()
514 find_feature(USE_FFMPEG "libavcodec;libavfilter;libavformat;libavutil;libswscale;libswresample|libavresample")
515endif()
516find_feature(USE_ZLIB "ZLIB")
517find_feature(USE_MINIZIP "minizip")
518find_feature(USE_PNG "PNG")
519find_feature(USE_LIBZIP "libzip")
520find_feature(USE_EPOXY "epoxy")
521find_feature(USE_CMOCKA "cmocka")
522find_feature(USE_SQLITE3 "SQLite3|sqlite3")
523find_feature(USE_ELF "libelf")
524find_feature(ENABLE_PYTHON "PythonLibs")
525
526# Features
527add_subdirectory(src/debugger)
528add_subdirectory(src/feature)
529
530set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
531
532if(USE_EDITLINE)
533 list(APPEND FEATURES EDITLINE)
534 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
535 link_directories(${LIBEDIT_LIBRARY_DIRS})
536 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
537 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
538 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/editline/cli-el-backend.c")
539else()
540 set(DEBUGGER_LIB "")
541endif()
542
543if(USE_GDB_STUB)
544 list(APPEND FEATURES GDB_STUB)
545 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/gdb-stub.c)
546endif()
547source_group("Debugger" FILES ${DEBUGGER_SRC})
548
549if(USE_FFMPEG)
550 list(APPEND FEATURES FFMPEG)
551 if(LIBSWRESAMPLE_FOUND)
552 list(APPEND FEATURES LIBSWRESAMPLE)
553 else()
554 list(APPEND FEATURES LIBAVRESAMPLE)
555 list(APPEND FEATURES LIBAV)
556 endif()
557 include_directories(AFTER ${FFMPEG_INCLUDE_DIRS} ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFILTER_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWRESAMPLE_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
558 link_directories(${FFMPEG_LIBRARY_DIRS} ${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFILTER_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWRESAMPLE_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
559 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-encoder.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-decoder.c")
560 list(APPEND DEPENDENCY_LIB ${FFMPEG_LIBRARIES} ${LIBAVCODEC_LIBRARIES} ${LIBAVFILTER_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES} ${LIBSWRESAMPLE_LIBRARIES})
561 if(WIN32 AND NOT DEFINED VCPKG_TARGET_TRIPLET)
562 list(APPEND DEPENDENCY_LIB bcrypt)
563 endif()
564 if(UNIX)
565 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
566 string(REGEX MATCH "^[0-9]+" LIBAVFILTER_VERSION_MAJOR ${libavfilter_VERSION})
567 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
568 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
569 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
570 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
571 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavfilter${LIBAVFILTER_VERSION_MAJOR}|libavfilter-ffmpeg${LIBAVFILTER_VERSION_MAJOR}")
572 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
573 if(LIBSWRESAMPLE_FOUND)
574 string(REGEX MATCH "^[0-9]+" LIBSWRESAMPLE_VERSION_MAJOR ${libswresample_VERSION})
575 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_MAJOR}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_MAJOR}")
576 else()
577 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
578 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
579 endif()
580 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
581 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
582 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
583 endif()
584 if(APPLE)
585 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
586 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
587 endif()
588endif()
589
590list(APPEND THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
591
592if(WANT_ZLIB AND NOT USE_ZLIB)
593 set(SKIP_INSTALL_ALL ON)
594 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib zlib EXCLUDE_FROM_ALL)
595 set_target_properties(zlibstatic PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/zlib;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib" POSITION_INDEPENDENT_CODE ON)
596 set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
597 set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
598 set(ZLIB_LIBRARY zlibstatic)
599 list(APPEND DEPENDENCY_LIB zlibstatic)
600 set(USE_ZLIB ON)
601endif()
602
603if(USE_ZLIB)
604 list(APPEND FEATURES ZLIB)
605 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
606 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
607 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
608 set(HAVE_CRC32 ON)
609 list(APPEND OS_LIB ${ZLIB_LIBRARIES})
610else()
611 # zlib pulls in crc32
612 check_function_exists(crc32 HAVE_CRC32)
613endif()
614
615if(HAVE_CRC32)
616 list(APPEND FUNCTION_DEFINES HAVE_CRC32)
617endif()
618
619if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
620 set(PNG_STATIC ON CACHE BOOL "" FORCE)
621 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
622 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
623 set(SKIP_INSTALL_ALL ON)
624 if (SWITCH)
625 set(PNG_ARM_NEON "off" CACHE STRING "" FORCE)
626 endif()
627 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng libpng EXCLUDE_FROM_ALL)
628 set_target_properties(png_static PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/libpng;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS}" POSITION_INDEPENDENT_CODE ON)
629 set(PNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
630 list(APPEND DEPENDENCY_LIB png_static)
631 set(USE_PNG ON)
632endif()
633
634if(USE_PNG)
635 list(APPEND FEATURES PNG)
636 include_directories(AFTER ${PNG_INCLUDE_DIRS})
637 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
638 if(PNG_VERSION_STRING)
639 string(REGEX MATCH "^[0-9]+\\.[0-9]+" PNG_VERSION_PARTIAL ${PNG_VERSION_STRING})
640 if(${PNG_VERSION_PARTIAL} STREQUAL "1.6")
641 set(PNG_DEB_VERSION "16-16")
642 else()
643 set(PNG_DEB_VERSION "12-0")
644 endif()
645 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng${PNG_DEB_VERSION}")
646 endif()
647endif()
648
649if(WANT_SQLITE3 AND NOT USE_SQLITE3)
650 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/sqlite3.c)
651 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/)
652 set(USE_SQLITE3 ON)
653endif()
654
655if(USE_LIBZIP)
656 if(TARGET libzip::zip)
657 list(APPEND DEPENDENCY_LIB libzip::zip)
658 elseif(TARGET zip)
659 list(APPEND DEPENDENCY_LIB zip)
660 else()
661 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
662 link_directories(${LIBZIP_LIBRARY_DIRS})
663 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
664 endif()
665 list(APPEND FEATURES LIBZIP)
666 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
667 string(REGEX MATCH "^[0-9]+" LIBZIP_VERSION_MAJOR "${libzip_VERSION}")
668 if (LIBZIP_VERSION_MAJOR LESS 1)
669 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
670 elseif(LIBZIP_VERSION_MAJOR EQUAL 1 OR NOT LIBZIP_VERSION_MAJOR)
671 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip4|libzip5")
672 else()
673 message(AUTHOR_WARNING "Unknown version of libzip detected: ${libzip_VERSION}")
674 endif()
675elseif(USE_MINIZIP)
676 include_directories(AFTER ${MINIZIP_INCLUDE_DIRS})
677 link_directories(${MINIZIP_LIBRARY_DIRS})
678 list(APPEND DEPENDENCY_LIB ${MINIZIP_LIBRARIES})
679 list(APPEND FEATURES MINIZIP)
680 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
681 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libminizip1")
682 set(CMAKE_REQUIRED_LIBRARIES ${MINIZIP_LIBRARIES})
683 check_function_exists(unztell64 HAVE_UNZTELL64)
684 unset(CMAKE_REQUIRED_LIBRARIES)
685 if(NOT HAVE_UNZTELL64)
686 add_definitions(-Dunztell64=unzTell64) # Bug in downstream minizip that some distros use
687 endif()
688elseif(USE_ZLIB)
689 list(APPEND FEATURES MINIZIP)
690 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c
691 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
692 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c
693 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/zip.c)
694 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib)
695 if(NOT MSVC)
696 set_source_files_properties(
697 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
698 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c
699 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/zip.c
700 PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-implicit-function-declaration")
701 endif()
702endif()
703
704if (USE_LZMA)
705 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma)
706 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
707 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
708 set(LZMA_SRC
709 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
710 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
711 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
712 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
713 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
714 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
715 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zDec.c
716 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
717 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Delta.c
718 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
719 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
720 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra.c
721 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra86.c
722 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
723 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
724 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
725 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
726 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zFile.c
727 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
728 list(APPEND VFS_SRC ${LZMA_SRC})
729 list(APPEND FEATURES LZMA)
730endif()
731
732if(USE_EPOXY)
733 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
734 list(APPEND FEATURE_DEFINES BUILD_GL BUILD_GLES2)
735 list(APPEND FEATURES EPOXY)
736 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
737 link_directories(${EPOXY_LIBRARY_DIRS})
738 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
739 list(APPEND DEPENDENCY_LIB ${EPOXY_LIBRARIES})
740 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
741elseif(BUILD_GL)
742 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgl1|libgles2")
743elseif(BUILD_GLES2)
744 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgles2")
745endif()
746
747if(WIN32 AND NOT (LIBMGBA_ONLY OR SKIP_LIBRARY OR USE_EPOXY))
748 message(FATAL_ERROR "Windows requires epoxy module!")
749endif()
750
751if(USE_SQLITE3)
752 list(APPEND FEATURES SQLITE3)
753 include_directories(AFTER ${SQLITE3_INCLUDE_DIRS})
754 link_directories(${SQLITE3_LIBRARY_DIRS})
755 list(APPEND DEPENDENCY_LIB ${SQLITE3_LIBRARIES})
756 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsqlite3-0")
757 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/sqlite3/no-intro.c")
758endif()
759
760if(USE_ELF)
761 list(APPEND FEATURES ELF)
762 include_directories(AFTER ${LIBELF_INCLUDE_DIRS})
763 link_directories(${LIBELF_LIBRARY_DIRS})
764 list(APPEND DEPENDENCY_LIB ${LIBELF_LIBRARIES})
765 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libelf1")
766endif()
767
768if (USE_DISCORD_RPC)
769 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc discord-rpc EXCLUDE_FROM_ALL)
770 list(APPEND FEATURES DISCORD_RPC)
771 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc/include)
772endif()
773
774if(ENABLE_SCRIPTING)
775 list(APPEND ENABLES SCRIPTING)
776
777 if(BUILD_PYTHON)
778 find_package(PythonLibs ${USE_PYTHON_VERSION})
779 list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
780 include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
781 list(APPEND ENABLES PYTHON)
782 endif()
783endif()
784
785add_subdirectory(src/arm)
786add_subdirectory(src/core)
787add_subdirectory(src/gb)
788add_subdirectory(src/gba)
789add_subdirectory(src/sm83)
790add_subdirectory(src/util)
791
792list(APPEND GUI_SRC ${EXTRA_GUI_SRC})
793list(APPEND UTIL_SRC ${CMAKE_CURRENT_BINARY_DIR}/version.c)
794
795set(TEST_SRC ${CORE_TEST_SRC})
796if(M_CORE_GB)
797 add_definitions(-DM_CORE_GB)
798 list(APPEND CORE_SRC ${SM83_SRC} ${GB_SRC})
799 list(APPEND DEBUGGER_SRC ${SM83_DEBUGGER_SRC} ${GB_DEBUGGER_SRC})
800 list(APPEND TEST_SRC ${SM83_TEST_SRC} ${GB_TEST_SRC})
801endif()
802
803if(M_CORE_GBA)
804 add_definitions(-DM_CORE_GBA)
805 list(APPEND CORE_SRC ${ARM_SRC} ${GBA_SRC})
806 list(APPEND DEBUGGER_SRC ${ARM_DEBUGGER_SRC} ${GBA_DEBUGGER_SRC})
807 list(APPEND TEST_SRC ${ARM_TEST_SRC} ${GBA_TEST_SRC})
808endif()
809
810if(USE_DEBUGGERS)
811 list(APPEND FEATURE_SRC ${DEBUGGER_SRC})
812 list(APPEND TEST_SRC ${DEBUGGER_TEST_SRC})
813 list(APPEND FEATURES DEBUGGERS)
814endif()
815
816foreach(FEATURE IN LISTS FEATURES)
817 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
818endforeach()
819
820foreach(ENABLE IN LISTS ENABLES)
821 list(APPEND FEATURE_DEFINES "ENABLE_${ENABLE}")
822endforeach()
823
824source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
825source_group("Extra features" FILES ${FEATURE_SRC})
826source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
827
828# Platform binaries
829set(OS_DEFINES)
830if(DEFINED 3DS)
831 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/3ds ${CMAKE_CURRENT_BINARY_DIR}/3ds)
832endif()
833
834if(DEFINED WII)
835 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/wii ${CMAKE_CURRENT_BINARY_DIR}/wii)
836endif()
837
838if(DEFINED PSP2)
839 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/psp2 ${CMAKE_CURRENT_BINARY_DIR}/psp2)
840endif()
841
842if(DEFINED SWITCH)
843 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/switch ${CMAKE_CURRENT_BINARY_DIR}/switch)
844endif()
845
846# Binaries
847list(APPEND CORE_SRC
848 ${UTIL_SRC}
849 ${CORE_VFS_SRC}
850 ${OS_SRC}
851 ${THIRD_PARTY_SRC})
852list(APPEND TEST_SRC ${UTIL_TEST_SRC})
853
854set(SRC ${CORE_SRC} ${VFS_SRC})
855if(NOT MINIMAL_CORE)
856 set(ENABLE_EXTRA ON)
857 if(M_CORE_GBA)
858 list(APPEND SRC ${GBA_SIO_SRC})
859 endif()
860 if(M_CORE_GB)
861 list(APPEND SRC ${GB_SIO_SRC})
862 endif()
863 list(APPEND SRC ${FEATURE_SRC})
864endif()
865
866if(ENABLE_EXTRA)
867 if(M_CORE_GBA)
868 list(APPEND SRC ${GBA_EXTRA_SRC})
869 endif()
870 if(M_CORE_GB)
871 list(APPEND SRC ${GB_EXTRA_SRC})
872 endif()
873 list(APPEND SRC ${EXTRA_SRC})
874endif()
875
876if(NOT SKIP_LIBRARY)
877 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
878 set(BUILD_SHARED ON)
879 endif()
880
881 if(BUILD_SHARED)
882 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
883 set(EXPORT_DEFINES MGBA_DLL)
884 if(BUILD_STATIC)
885 add_library(${BINARY_NAME}-static STATIC ${SRC})
886 target_include_directories(${BINARY_NAME}-static BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
887 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES};BUILD_STATIC" COMPILE_OPTIONS "${FEATURE_FLAGS}")
888 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
889 add_dependencies(${BINARY_NAME}-static ${BINARY_NAME}-version-info)
890 endif()
891 else()
892 add_library(${BINARY_NAME} STATIC ${SRC})
893 list(APPEND OS_DEFINES BUILD_STATIC)
894 endif()
895
896 target_include_directories(${BINARY_NAME} BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
897 set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES};${EXPORT_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}")
898 add_dependencies(${BINARY_NAME} ${BINARY_NAME}-version-info)
899
900 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba-util)
901
902 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
903 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
904 if(BUILD_SHARED)
905 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}-dev NAMELINK_ONLY)
906 endif()
907 if(UNIX AND NOT APPLE AND NOT HAIKU)
908 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
909 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
910 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
911 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
912 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
913 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
914 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
915 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
916 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
917 endif()
918else()
919 set(BUILD_SHARED OFF)
920 set(BUILD_STATIC OFF)
921 find_library(${BINARY_NAME} ${BINARY_NAME})
922 if(NOT ${BINARY_NAME}_FOUND)
923 set(DISABLE_FRONTENDS ON)
924 set(BUILD_PERF OFF)
925 set(BUILD_TEST OFF)
926 set(BUILD_SUITE OFF)
927 endif()
928endif()
929
930if(DISABLE_FRONTENDS)
931 set(BUILD_SDL OFF)
932 set(BUILD_QT OFF)
933endif()
934
935if(BUILD_PYTHON)
936 enable_testing()
937 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/python ${CMAKE_CURRENT_BINARY_DIR}/python)
938endif()
939
940if(BUILD_LIBRETRO)
941 file(GLOB RETRO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/libretro/*.c)
942 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
943 add_dependencies(${BINARY_NAME}_libretro ${BINARY_NAME}-version-info)
944 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "__LIBRETRO__;COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;MGBA_STANDALONE;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=2")
945 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
946 if(MSVC)
947 install(TARGETS ${BINARY_NAME}_libretro RUNTIME DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro)
948 else()
949 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
950 endif()
951endif()
952
953if(BUILD_OPENEMU)
954 find_library(FOUNDATION Foundation)
955 find_library(OPENEMUBASE OpenEmuBase)
956 file(GLOB OE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/*.m)
957 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OS_SRC})
958 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
959 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/Info.plist.in
960 BUNDLE TRUE
961 BUNDLE_EXTENSION oecoreplugin
962 OUTPUT_NAME ${PROJECT_NAME}
963 COMPILE_OPTIONS "-fobjc-arc"
964 COMPILE_DEFINITIONS "DISABLE_THREADING;MGBA_STANDALONE;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
965 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
966 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${OE_LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
967endif()
968
969if(BUILD_SDL)
970 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/sdl ${CMAKE_CURRENT_BINARY_DIR}/sdl)
971endif()
972
973if(BUILD_QT)
974 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt)
975endif()
976
977if(NOT USE_CMOCKA)
978 set(BUILD_SUITE OFF)
979endif()
980if(BUILD_TEST OR BUILD_SUITE OR BUILD_CINEMA)
981 enable_testing()
982endif()
983add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test ${CMAKE_CURRENT_BINARY_DIR}/test)
984
985if(BUILD_EXAMPLE)
986 add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c)
987 target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME})
988 set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
989
990 if(SDL_FOUND)
991 add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)
992 target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
993 set_target_properties(${BINARY_NAME}-example-client PROPERTIES
994 COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}"
995 INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include")
996 endif()
997endif()
998
999file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba)
1000configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h)
1001install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
1002install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba-util DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
1003install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT ${BINARY_NAME}-dev)
1004
1005# Packaging
1006install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/blip_buf.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1007install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/inih.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1008if(USE_DISCORD_RPC)
1009 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/discord-rpc.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1010 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/rapidjson.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1011 if(WIN32)
1012 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/mingw-std-threads.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1013 endif()
1014endif()
1015if(EXTRA_LICENSES)
1016 install(FILES ${EXTRA_LICENSES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1017endif()
1018
1019file(GLOB READMES ${CMAKE_CURRENT_SOURCE_DIR}/README*.md)
1020
1021find_program(UNIX2DOS NAMES unix2dos)
1022find_program(MARKDOWN NAMES markdown kramdown pandoc)
1023
1024if(UNIX OR NOT UNIX2DOS)
1025 if(UNIX OR NOT MARKDOWN)
1026 install(FILES ${READMES} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1027 endif()
1028 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1029else()
1030 add_custom_command(OUTPUT CHANGES.txt COMMAND ${UNIX2DOS} -n "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES")
1031 add_custom_command(OUTPUT LICENSE.txt COMMAND ${UNIX2DOS} -n "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
1032 add_custom_target(CHANGES ALL DEPENDS CHANGES.txt)
1033 add_custom_target(LICENSE ALL DEPENDS LICENSE.txt)
1034 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1035 if(DISTBUILD AND WIN32)
1036 set(BIN_DIR ".\\")
1037 string(REGEX REPLACE "[^-A-Za-z0-9_.]" "-" CLEAN_VERSION_STRING "${VERSION_STRING}")
1038 file(RELATIVE_PATH SETUP_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup")
1039 file(RELATIVE_PATH RES_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res")
1040 string(REPLACE "/" "\\" SETUP_DIR "${SETUP_DIR_SLASH}")
1041 string(REPLACE "/" "\\" RES_DIR "${RES_DIR_SLASH}")
1042 if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$")
1043 set(WIN_BITS 64)
1044 else()
1045 set(WIN_BITS 32)
1046 endif()
1047 if(GIT_TAG)
1048 set(IS_RELEASE 1)
1049 else()
1050 set(IS_RELEASE 0)
1051 endif()
1052 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup/setup.iss.in" setup.iss)
1053 set_source_files_properties(setup.iss PROPERTIES GENERATED ON)
1054
1055 if(INSTALLER_NAME)
1056 set(INSTALLER_TARGET "${INSTALLER_NAME}.exe")
1057 set(ISCC_FLAGS "/F${INSTALLER_NAME}")
1058 else()
1059 set(INSTALLER_TARGET "${PROJECT_NAME}-setup-${CLEAN_VERSION_STRING}-win${WIN_BITS}.exe")
1060 endif()
1061 if(CMAKE_CROSSCOMPILING)
1062 find_program(WINE NAMES wine wine-stable wine-development)
1063 find_file(ISCC ISCC.exe HINTS "$ENV{HOME}/.wine/drive_c/Program Files/" PATH_SUFFIXES "Inno Setup 5")
1064 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1065 COMMAND "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1066 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl setup.iss CHANGES LICENSE)
1067 else()
1068 find_program(ISCC NAMES ISCC ISCC.exe PATH_SUFFIXES "Inno Setup 5")
1069 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1070 COMMAND "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1071 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl setup.iss CHANGES LICENSE)
1072 endif()
1073 if(ISCC)
1074 add_custom_target(installer ALL DEPENDS ${INSTALLER_TARGET})
1075 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${INSTALLER_TARGET}" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT installer)
1076 endif()
1077 endif()
1078endif()
1079
1080if(MARKDOWN)
1081 foreach(README ${READMES})
1082 get_filename_component(README_BASE "${README}" NAME_WE)
1083 add_custom_command(OUTPUT ${README_BASE}.html COMMAND ${MARKDOWN} "${README}" > ${README_BASE}.html MAIN_DEPENDENCY "${README}")
1084 add_custom_target(${README_BASE} ALL DEPENDS ${README_BASE}.html)
1085 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${README_BASE}.html DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1086 endforeach()
1087endif()
1088
1089set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
1090set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
1091set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
1092set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
1093set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
1094set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
1095
1096set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
1097set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
1098set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
1099set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
1100set(CPACK_DEBIAN_PACKAGE_SECTION "games")
1101
1102set(CPACK_DEB_COMPONENT_INSTALL ON)
1103
1104if(CMAKE_BUILD_TYPE STREQUAL "Release")
1105 set(CPACK_STRIP_FILES ON)
1106endif()
1107
1108if(DISTBUILD)
1109 set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
1110 if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND BUILD_SHARED)
1111 if(NOT APPLE)
1112 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}>" "$<TARGET_FILE:${BINARY_NAME}>.debug")
1113 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${STRIP}" "$<TARGET_FILE:${BINARY_NAME}>")
1114 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --add-gnu-debuglink "$<TARGET_FILE:${BINARY_NAME}>.debug" "$<TARGET_FILE:${BINARY_NAME}>")
1115 install(FILES "$<TARGET_FILE:${BINARY_NAME}>.debug" DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME}-dbg)
1116 endif()
1117 endif()
1118 if(APPLE)
1119 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf)
1120 set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
1121 elseif(WIN32)
1122 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf installer)
1123 elseif(3DS)
1124 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-3ds ${BINARY_NAME}-perf)
1125 elseif(WII)
1126 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-wii ${BINARY_NAME}-perf)
1127 elseif(PSP2)
1128 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-psp2 ${BINARY_NAME}-perf)
1129 elseif(SWITCH)
1130 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-switch)
1131 endif()
1132endif()
1133
1134include(CPack)
1135
1136cpack_add_component_group(base)
1137cpack_add_component(${BINARY_NAME} GROUP base)
1138
1139cpack_add_component_group(dev PARENT_GROUP base)
1140if(BUILD_SHARED)
1141 cpack_add_component(lib${BINARY_NAME} GROUP base)
1142 if(BUILD_STATIC)
1143 cpack_add_component(lib${BINARY_NAME}-static GROUP dev)
1144 endif()
1145elseif(BUILD_STATIC)
1146 cpack_add_component(lib${BINARY_NAME} GROUP dev)
1147endif()
1148cpack_add_component(${BINARY_NAME}-dev GROUP dev)
1149
1150if(3DS)
1151 cpack_add_component(${BINARY_NAME}-3ds GROUP base)
1152elseif(PSP2)
1153 cpack_add_component(${BINARY_NAME}-psp2 GROUP base)
1154elseif(WII)
1155 cpack_add_component(${BINARY_NAME}-wii GROUP base)
1156elseif(SWITCH)
1157 cpack_add_component(${BINARY_NAME}-switch GROUP base)
1158endif()
1159
1160if(BUILD_QT)
1161 cpack_add_component_group(qt PARENT_GROUP base)
1162 cpack_add_component(${BINARY_NAME}-qt GROUP qt)
1163endif()
1164
1165if(SDL_FOUND)
1166 cpack_add_component_group(sdl PARENT_GROUP base)
1167 cpack_add_component(${BINARY_NAME}-sdl GROUP sdl)
1168endif()
1169
1170if(DISTBUILD)
1171 cpack_add_component_group(debug PARENT_GROUP dev)
1172 if(BUILD_SHARED AND NOT IS_EMBEDDED)
1173 cpack_add_component(lib${BINARY_NAME}-dbg GROUP debug)
1174 endif()
1175 if(IS_EMBEDDED)
1176 cpack_add_component(${BINARY_NAME}-dbg GROUP debug)
1177 endif()
1178 if(BUILD_QT)
1179 cpack_add_component(${BINARY_NAME}-qt-dbg GROUP debug)
1180 endif()
1181 if(SDL_FOUND)
1182 cpack_add_component(${BINARY_NAME}-sdl-dbg GROUP debug)
1183 endif()
1184 if(WIN32)
1185 cpack_add_component_group(installer PARENT_GROUP base)
1186 endif()
1187endif()
1188
1189cpack_add_component_group(test PARENT_GROUP dev)
1190cpack_add_component(${BINARY_NAME}-perf GROUP test)
1191cpack_add_component(${BINARY_NAME}-test GROUP test)
1192
1193# Summaries
1194set(SUMMARY_GL_LIST)
1195if(USE_EPOXY)
1196 set(SUMMARY_GL_LIST "libepoxy")
1197else()
1198 if(BUILD_GL)
1199 list(APPEND SUMMARY_GL_LIST "OpenGL")
1200 endif()
1201 if(BUILD_GLES2)
1202 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
1203 endif()
1204 if(BUILD_GLES3)
1205 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 3")
1206 endif()
1207endif()
1208if(NOT SUMMARY_GL_LIST)
1209 set(SUMMARY_GL OFF)
1210else()
1211 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
1212endif()
1213if(USE_LIBZIP)
1214 set(SUMMARY_ZIP libzip)
1215elseif(USE_MINIZIP)
1216 set(SUMMARY_ZIP "minizip (external)")
1217elseif(USE_ZLIB)
1218 set(SUMMARY_ZIP "minizip (included)")
1219else()
1220 set(SUMMARY_ZIP OFF)
1221endif()
1222
1223if(NOT QUIET AND NOT LIBMGBA_ONLY)
1224 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1225 message(STATUS "Platforms:")
1226 message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
1227 message(STATUS " Game Boy: ${M_CORE_GB}")
1228 message(STATUS "Features:")
1229 message(STATUS " Debuggers: ${USE_DEBUGGERS}")
1230 if(NOT WIN32)
1231 message(STATUS " CLI debugger: ${USE_EDITLINE}")
1232 endif()
1233 message(STATUS " GDB stub: ${USE_GDB_STUB}")
1234 message(STATUS " GIF/Video recording: ${USE_FFMPEG}")
1235 message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
1236 message(STATUS " ZIP support: ${SUMMARY_ZIP}")
1237 message(STATUS " 7-Zip support: ${USE_LZMA}")
1238 message(STATUS " SQLite3 game database: ${USE_SQLITE3}")
1239 message(STATUS " ELF loading support: ${USE_ELF}")
1240 message(STATUS " Discord Rich Presence support: ${USE_DISCORD_RPC}")
1241 message(STATUS " OpenGL support: ${SUMMARY_GL}")
1242 message(STATUS "Frontends:")
1243 message(STATUS " Qt: ${BUILD_QT}")
1244 message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
1245 message(STATUS " Profiling: ${BUILD_PERF}")
1246 message(STATUS " Test harness: ${BUILD_TEST}")
1247 message(STATUS " Test suite: ${BUILD_SUITE}")
1248 message(STATUS " Video test suite: ${BUILD_CINEMA}")
1249 message(STATUS " Python bindings: ${BUILD_PYTHON}")
1250 message(STATUS " Examples: ${BUILD_EXAMPLE}")
1251 message(STATUS "Cores:")
1252 message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
1253 if(APPLE)
1254 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
1255 endif()
1256 message(STATUS "Libraries:")
1257 message(STATUS " Static: ${BUILD_STATIC}")
1258 message(STATUS " Shared: ${BUILD_SHARED}")
1259endif()