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