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)
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)
295if(NOT DEFINED PSP2)
296 check_function_exists(localtime_r HAVE_LOCALTIME_R)
297endif()
298check_include_files("xlocale.h" HAVE_XLOCALE)
299if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
300 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
301 if(ANDROID AND ANDROID_NDK_MAJOR GREATER 13)
302 set(HAVE_STRTOF_L ON)
303 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
304 # The strtof_l on Linux not actually exposed nor actually strtof_l
305 set(HAVE_STRTOF_L OFF)
306 else()
307 check_function_exists(strtof_l HAVE_STRTOF_L)
308 endif()
309 check_function_exists(newlocale HAVE_NEWLOCALE)
310 check_function_exists(freelocale HAVE_FREELOCALE)
311 check_function_exists(uselocale HAVE_USELOCALE)
312 check_function_exists(setlocale HAVE_SETLOCALE)
313else()
314 if(DEFINED 3DS OR DEFINED WII OR DEFINED SWITCH)
315 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,snprintf_l)
316 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
317 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,strtof_l)
318 check_function_exists(strtof_l HAVE_STRTOF_L)
319 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,newlocale)
320 check_function_exists(newlocale HAVE_NEWLOCALE)
321 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,freelocale)
322 check_function_exists(freelocale HAVE_FREELOCALE)
323 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,uselocale)
324 check_function_exists(uselocale HAVE_USELOCALE)
325 set(CMAKE_REQUIRED_FLAGS -Wl,--require-defined,setlocale)
326 check_function_exists(setlocale HAVE_SETLOCALE)
327 unset(CMAKE_REQUIRED_FLAGS)
328 endif()
329 if(NOT IS_EMBEDDED)
330 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
331 endif()
332 set(BUILD_STATIC ON CACHE BOOL "" FORCE)
333 set(BUILD_SHARED OFF CACHE BOOL "" FORCE)
334 set(DISABLE_FRONTENDS ON)
335 set(MINIMAL_CORE ON)
336 set(ENABLE_EXTRA ON)
337endif()
338
339check_function_exists(chmod HAVE_CHMOD)
340check_function_exists(umask HAVE_UMASK)
341
342if(USE_PTHREADS)
343 check_include_files("pthread.h" HAVE_PTHREAD_H)
344 if(HAVE_PTHREAD_H)
345 check_c_compiler_flag(-pthread HAVE_PTHREAD)
346 if(HAVE_PTHREAD AND NOT APPLE AND NOT HAIKU)
347 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
348 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
349 endif()
350
351 check_function_exists(pthread_create HAVE_PTHREAD_CREATE)
352 if(HAVE_PTHREAD_CREATE)
353 add_definitions(-DUSE_PTHREADS)
354
355 check_include_files("pthread_np.h" HAVE_PTHREAD_NP_H)
356
357 check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
358 check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
359 endif()
360 endif()
361endif()
362
363set(FUNCTION_DEFINES)
364
365if(HAVE_STRDUP)
366 list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
367endif()
368
369if(HAVE_STRNDUP)
370 list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
371endif()
372
373if(HAVE_STRLCPY)
374 list(APPEND FUNCTION_DEFINES HAVE_STRLCPY)
375endif()
376
377if(HAVE_LOCALTIME_R)
378 list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
379endif()
380
381if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE OR APPLE)
382 list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
383 if (HAVE_SNPRINTF_L)
384 list(APPEND FUNCTION_DEFINES HAVE_SNPRINTF_L)
385 endif()
386endif()
387
388if(HAVE_SETLOCALE)
389 list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
390endif()
391
392if (HAVE_STRTOF_L)
393 list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
394endif()
395
396if(HAVE_XLOCALE)
397 list(APPEND FUNCTION_DEFINES HAVE_XLOCALE)
398endif()
399
400if(HAVE_CHMOD)
401 list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
402endif()
403
404if(HAVE_UMASK)
405 list(APPEND FUNCTION_DEFINES HAVE_UMASK)
406endif()
407
408if(HAVE_PTHREAD_NP_H)
409 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_NP_H)
410endif()
411
412if(HAVE_PTHREAD_SETNAME_NP)
413 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SETNAME_NP)
414endif()
415
416if(HAVE_PTHREAD_SET_NAME_NP)
417 list(APPEND FUNCTION_DEFINES HAVE_PTHREAD_SET_NAME_NP)
418endif()
419
420# Feature dependencies
421set(FEATURE_DEFINES)
422set(FEATURE_FLAGS)
423set(FEATURES)
424set(ENABLES)
425if(CMAKE_SYSTEM_NAME MATCHES ".*BSD|DragonFly")
426 set(LIBEDIT_LIBRARIES -ledit)
427 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
428 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
429 endif()
430else()
431 find_feature(USE_EDITLINE "libedit")
432endif()
433if(BUILD_GL)
434 find_package(OpenGL QUIET)
435 if(NOT OPENGL_FOUND)
436 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
437 endif()
438endif()
439if(NOT BUILD_GL)
440 set(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
441endif()
442if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|Darwin|Linux|.*BSD|DragonFly|Haiku)$")
443 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
444 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
445 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
446 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
447 endif()
448endif()
449if(NOT BUILD_GLES2)
450 set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
451endif()
452if(BUILD_GL)
453 list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
454 list(APPEND DEPENDENCY_LIB ${OPENGL_LIBRARY})
455 include_directories(${OPENGL_INCLUDE_DIR})
456endif()
457if(BUILD_GLES2)
458 list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
459 list(APPEND DEPENDENCY_LIB ${OPENGLES2_LIBRARY})
460 include_directories(${OPENGLES2_INCLUDE_DIR})
461endif()
462if(BUILD_GLES3)
463 find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
464 find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
465 if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
466 set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
467 endif()
468endif()
469
470if(DISABLE_DEPS)
471 set(USE_GDB_STUB OFF)
472 set(USE_DISCORD_RPC OFF)
473 set(USE_SQLITE3 OFF)
474 set(USE_PNG OFF)
475 set(USE_ZLIB OFF)
476endif()
477
478set(WANT_ZLIB ${USE_ZLIB})
479set(WANT_PNG ${USE_PNG})
480set(WANT_SQLITE3 ${USE_SQLITE3})
481set(USE_CMOCKA ${BUILD_SUITE})
482
483if(DEFINED VCPKG_TARGET_TRIPLET)
484 find_feature(USE_FFMPEG "FFMPEG")
485 if(FFMPEG_FOUND)
486 set(USE_LIBAVRESAMPLE OFF)
487 set(USE_LIBSWRESAMPLE ON)
488 endif()
489else()
490 find_feature(USE_FFMPEG "libavcodec;libavfilter;libavformat;libavutil;libswscale")
491endif()
492find_feature(USE_ZLIB "ZLIB")
493find_feature(USE_MINIZIP "minizip")
494find_feature(USE_PNG "PNG")
495find_feature(USE_LIBZIP "libzip")
496find_feature(USE_EPOXY "epoxy")
497find_feature(USE_CMOCKA "cmocka")
498find_feature(USE_SQLITE3 "sqlite3")
499find_feature(USE_ELF "libelf")
500find_feature(ENABLE_PYTHON "PythonLibs")
501
502if(USE_FFMPEG AND NOT DEFINED VCPKG_TARGET_TRIPLET)
503 set(USE_LIBAVRESAMPLE ON)
504 set(USE_LIBSWRESAMPLE ON)
505 find_feature(USE_LIBAVRESAMPLE "libavresample")
506 find_feature(USE_LIBSWRESAMPLE "libswresample")
507endif()
508
509# Features
510add_subdirectory(src/debugger)
511add_subdirectory(src/feature)
512
513set(FEATURE_SRC)
514set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
515
516if(USE_EDITLINE)
517 list(APPEND FEATURES EDITLINE)
518 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
519 link_directories(${LIBEDIT_LIBRARY_DIRS})
520 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
521 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
522 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/editline/cli-el-backend.c")
523else()
524 set(DEBUGGER_LIB "")
525endif()
526
527if(USE_GDB_STUB)
528 list(APPEND FEATURES GDB_STUB)
529 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/gdb-stub.c)
530endif()
531source_group("Debugger" FILES ${DEBUGGER_SRC})
532
533if(USE_FFMPEG)
534 list(APPEND FEATURES FFMPEG)
535 if(USE_LIBSWRESAMPLE)
536 list(APPEND FEATURES LIBSWRESAMPLE)
537 else()
538 list(APPEND FEATURES LIBAVRESAMPLE)
539 list(APPEND FEATURES LIBAV)
540 endif()
541 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})
542 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})
543 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-encoder.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-decoder.c")
544 list(APPEND DEPENDENCY_LIB ${FFMPEG_LIBRARIES} ${LIBAVCODEC_LIBRARIES} ${LIBAVFILTER_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES} ${LIBSWRESAMPLE_LIBRARIES})
545 if(WIN32 AND NOT DEFINED VCPKG_TARGET_TRIPLET)
546 list(APPEND DEPENDENCY_LIB bcrypt)
547 endif()
548 if(UNIX)
549 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
550 string(REGEX MATCH "^[0-9]+" LIBAVFILTER_VERSION_MAJOR ${libavfilter_VERSION})
551 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
552 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
553 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
554 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}")
555 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavfilter${LIBAVFILTER_VERSION_MAJOR}|libavfilter-ffmpeg${LIBAVFILTER_VERSION_MAJOR}")
556 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
557 if(USE_LIBSWRESAMPLE)
558 string(REGEX MATCH "^[0-9]+" LIBSWRESAMPLE_VERSION_MAJOR ${libswresample_VERSION})
559 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_MAJOR}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_MAJOR}")
560 else()
561 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
562 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
563 endif()
564 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
565 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
566 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
567 endif()
568 if(APPLE)
569 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
570 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
571 endif()
572endif()
573
574list(APPEND THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
575
576if(WANT_ZLIB AND NOT USE_ZLIB)
577 set(SKIP_INSTALL_ALL ON)
578 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib zlib EXCLUDE_FROM_ALL)
579 set_target_properties(zlibstatic PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/zlib;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib" POSITION_INDEPENDENT_CODE ON)
580 set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
581 set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
582 set(ZLIB_LIBRARY zlibstatic)
583 list(APPEND DEPENDENCY_LIB zlibstatic)
584 set(USE_ZLIB ON)
585endif()
586
587if(USE_ZLIB)
588 list(APPEND FEATURES ZLIB)
589 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
590 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
591 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
592 set(HAVE_CRC32 ON)
593 list(APPEND OS_LIB ${ZLIB_LIBRARIES})
594else()
595 # zlib pulls in crc32
596 check_function_exists(crc32 HAVE_CRC32)
597endif()
598
599if(HAVE_CRC32)
600 list(APPEND FUNCTION_DEFINES HAVE_CRC32)
601endif()
602
603if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
604 set(PNG_STATIC ON CACHE BOOL "" FORCE)
605 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
606 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
607 set(SKIP_INSTALL_ALL ON)
608 if (SWITCH)
609 set(PNG_ARM_NEON "off" CACHE STRING "" FORCE)
610 endif()
611 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng libpng EXCLUDE_FROM_ALL)
612 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)
613 set(PNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
614 list(APPEND DEPENDENCY_LIB png_static)
615 set(USE_PNG ON)
616endif()
617
618if(USE_PNG)
619 list(APPEND FEATURES PNG)
620 include_directories(AFTER ${PNG_INCLUDE_DIRS})
621 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
622 if(PNG_VERSION_STRING)
623 string(REGEX MATCH "^[0-9]+\\.[0-9]+" PNG_VERSION_PARTIAL ${PNG_VERSION_STRING})
624 if(${PNG_VERSION_PARTIAL} STREQUAL "1.6")
625 set(PNG_DEB_VERSION "16-16")
626 else()
627 set(PNG_DEB_VERSION "12-0")
628 endif()
629 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng${PNG_DEB_VERSION}")
630 endif()
631endif()
632
633if(WANT_SQLITE3 AND NOT USE_SQLITE3)
634 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/sqlite3.c)
635 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/)
636 set(USE_SQLITE3 ON)
637endif()
638
639if(USE_LIBZIP)
640 if(TARGET libzip::zip)
641 list(APPEND DEPENDENCY_LIB libzip::zip)
642 else()
643 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
644 link_directories(${LIBZIP_LIBRARY_DIRS})
645 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
646 endif()
647 list(APPEND FEATURES LIBZIP)
648 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
649 string(REGEX MATCH "^[0-9]+" LIBZIP_VERSION_MAJOR "${libzip_VERSION}")
650 if (LIBZIP_VERSION_MAJOR LESS 1)
651 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
652 elseif(LIBZIP_VERSION_MAJOR EQUAL 1 OR NOT LIBZIP_VERSION_MAJOR)
653 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip4|libzip5")
654 else()
655 message(AUTHOR_WARNING "Unknown version of libzip detected: ${libzip_VERSION}")
656 endif()
657elseif(USE_MINIZIP)
658 include_directories(AFTER ${MINIZIP_INCLUDE_DIRS})
659 link_directories(${MINIZIP_LIBRARY_DIRS})
660 list(APPEND DEPENDENCY_LIB ${MINIZIP_LIBRARIES})
661 list(APPEND FEATURES MINIZIP)
662 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
663 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libminizip1")
664elseif(USE_ZLIB)
665 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c
666 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
667 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
668 if(NOT MSVC)
669 set_source_files_properties(
670 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
671 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c
672 PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-implicit-function-declaration")
673 endif()
674endif()
675
676if (USE_LZMA)
677 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma)
678 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
679 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
680 set(LZMA_SRC
681 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
682 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
683 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
684 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
685 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
686 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
687 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zDec.c
688 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
689 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Delta.c
690 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
691 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
692 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra.c
693 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra86.c
694 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
695 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
696 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
697 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
698 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zFile.c
699 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
700 list(APPEND VFS_SRC ${LZMA_SRC})
701 list(APPEND FEATURES LZMA)
702endif()
703
704if(USE_EPOXY)
705 list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
706 add_definitions(-DBUILD_GL -DBUILD_GLES2)
707 list(APPEND FEATURES EPOXY)
708 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
709 link_directories(${EPOXY_LIBRARY_DIRS})
710 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
711 list(APPEND DEPENDENCY_LIB ${EPOXY_LIBRARIES})
712 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
713elseif(BUILD_GL)
714 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgl1|libgles2")
715elseif(BUILD_GLES2)
716 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgles2")
717endif()
718
719if(WIN32 AND NOT SKIP_LIBRARY AND NOT USE_EPOXY)
720 message(FATAL_ERROR "Windows requires epoxy module!")
721endif()
722
723if(USE_SQLITE3)
724 list(APPEND FEATURES SQLITE3)
725 include_directories(AFTER ${SQLITE3_INCLUDE_DIRS})
726 link_directories(${SQLITE3_LIBRARY_DIRS})
727 list(APPEND DEPENDENCY_LIB ${SQLITE3_LIBRARIES})
728 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsqlite3-0")
729 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/sqlite3/no-intro.c")
730endif()
731
732if(USE_ELF)
733 list(APPEND FEATURES ELF)
734 include_directories(AFTER ${LIBELF_INCLUDE_DIRS})
735 link_directories(${LIBELF_LIBRARY_DIRS})
736 list(APPEND DEPENDENCY_LIB ${LIBELF_LIBRARIES})
737 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libelf1")
738endif()
739
740if (USE_DISCORD_RPC)
741 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc discord-rpc EXCLUDE_FROM_ALL)
742 list(APPEND FEATURES DISCORD_RPC)
743 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc/include)
744endif()
745
746if(ENABLE_SCRIPTING)
747 list(APPEND ENABLES SCRIPTING)
748
749 if(BUILD_PYTHON)
750 find_package(PythonLibs ${USE_PYTHON_VERSION})
751 list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
752 include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
753 list(APPEND ENABLES PYTHON)
754 endif()
755endif()
756
757add_subdirectory(src/arm)
758add_subdirectory(src/core)
759add_subdirectory(src/gb)
760add_subdirectory(src/gba)
761add_subdirectory(src/sm83)
762add_subdirectory(src/util)
763
764list(APPEND GUI_SRC ${EXTRA_GUI_SRC})
765list(APPEND UTIL_SRC ${CMAKE_CURRENT_BINARY_DIR}/version.c)
766
767set(TEST_SRC ${CORE_TEST_SRC})
768if(M_CORE_GB)
769 add_definitions(-DM_CORE_GB)
770 list(APPEND CORE_SRC ${SM83_SRC} ${GB_SRC})
771 list(APPEND DEBUGGER_SRC ${SM83_DEBUGGER_SRC} ${GB_DEBUGGER_SRC})
772 list(APPEND TEST_SRC ${SM83_TEST_SRC} ${GB_TEST_SRC})
773endif()
774
775if(M_CORE_GBA)
776 add_definitions(-DM_CORE_GBA)
777 list(APPEND CORE_SRC ${ARM_SRC} ${GBA_SRC})
778 list(APPEND DEBUGGER_SRC ${ARM_DEBUGGER_SRC} ${GBA_DEBUGGER_SRC})
779 list(APPEND TEST_SRC ${ARM_TEST_SRC} ${GBA_TEST_SRC})
780endif()
781
782if(USE_DEBUGGERS)
783 list(APPEND FEATURE_SRC ${DEBUGGER_SRC})
784 list(APPEND TEST_SRC ${DEBUGGER_TEST_SRC})
785 list(APPEND FEATURES DEBUGGERS)
786endif()
787
788foreach(FEATURE IN LISTS FEATURES)
789 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
790endforeach()
791
792foreach(ENABLE IN LISTS ENABLES)
793 list(APPEND FEATURE_DEFINES "ENABLE_${ENABLE}")
794endforeach()
795
796source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
797source_group("Extra features" FILES ${FEATURE_SRC})
798source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
799
800# Platform binaries
801set(OS_DEFINES)
802if(DEFINED 3DS)
803 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/3ds ${CMAKE_CURRENT_BINARY_DIR}/3ds)
804endif()
805
806if(DEFINED WII)
807 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/wii ${CMAKE_CURRENT_BINARY_DIR}/wii)
808endif()
809
810if(DEFINED PSP2)
811 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/psp2 ${CMAKE_CURRENT_BINARY_DIR}/psp2)
812endif()
813
814if(DEFINED SWITCH)
815 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/switch ${CMAKE_CURRENT_BINARY_DIR}/switch)
816endif()
817
818# Binaries
819list(APPEND CORE_SRC
820 ${UTIL_SRC}
821 ${CORE_VFS_SRC}
822 ${OS_SRC}
823 ${THIRD_PARTY_SRC})
824list(APPEND TEST_SRC ${UTIL_TEST_SRC})
825
826set(SRC ${CORE_SRC} ${VFS_SRC})
827if(NOT MINIMAL_CORE)
828 set(ENABLE_EXTRA ON)
829 if(M_CORE_GBA)
830 list(APPEND SRC ${GBA_SIO_SRC})
831 endif()
832 if(M_CORE_GB)
833 list(APPEND SRC ${GB_SIO_SRC})
834 endif()
835 list(APPEND SRC ${FEATURE_SRC})
836endif()
837
838if(ENABLE_EXTRA)
839 if(M_CORE_GBA)
840 list(APPEND SRC ${GBA_EXTRA_SRC})
841 endif()
842 if(M_CORE_GB)
843 list(APPEND SRC ${GB_EXTRA_SRC})
844 endif()
845 list(APPEND SRC ${EXTRA_SRC})
846endif()
847
848if(NOT SKIP_LIBRARY)
849 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
850 set(BUILD_SHARED ON)
851 endif()
852
853 if(BUILD_SHARED)
854 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
855 set(EXPORT_DEFINES MGBA_DLL)
856 if(BUILD_STATIC)
857 add_library(${BINARY_NAME}-static STATIC ${SRC})
858 target_include_directories(${BINARY_NAME}-static BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
859 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES};BUILD_STATIC" COMPILE_OPTIONS "${FEATURE_FLAGS}")
860 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
861 add_dependencies(${BINARY_NAME}-static version-info)
862 endif()
863 else()
864 add_library(${BINARY_NAME} STATIC ${SRC})
865 list(APPEND OS_DEFINES BUILD_STATIC)
866 endif()
867
868 target_include_directories(${BINARY_NAME} BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
869 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}")
870 add_dependencies(${BINARY_NAME} version-info)
871
872 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba-util)
873
874 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
875 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
876 if(BUILD_SHARED)
877 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}-dev NAMELINK_ONLY)
878 endif()
879 if(UNIX AND NOT APPLE AND NOT HAIKU)
880 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
881 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
882 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
883 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
884 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
885 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
886 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
887 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
888 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
889 endif()
890else()
891 set(BUILD_SHARED OFF)
892 set(BUILD_STATIC OFF)
893 find_library(${BINARY_NAME} ${BINARY_NAME})
894 if(NOT ${BINARY_NAME}_FOUND)
895 set(DISABLE_FRONTENDS ON)
896 set(BUILD_PERF OFF)
897 set(BUILD_TEST OFF)
898 set(BUILD_SUITE OFF)
899 endif()
900endif()
901
902if(BUILD_GL)
903 add_definitions(-DBUILD_GL)
904endif()
905
906if(BUILD_GLES2)
907 add_definitions(-DBUILD_GLES2)
908endif()
909
910if(BUILD_GLES3)
911 add_definitions(-DBUILD_GLES3)
912endif()
913
914if(DISABLE_FRONTENDS)
915 set(BUILD_SDL OFF)
916 set(BUILD_QT OFF)
917endif()
918
919if(BUILD_PYTHON)
920 enable_testing()
921 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/python ${CMAKE_CURRENT_BINARY_DIR}/python)
922endif()
923
924if(BUILD_LIBRETRO)
925 file(GLOB RETRO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/libretro/*.c)
926 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
927 add_dependencies(${BINARY_NAME}_libretro version-info)
928 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")
929 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
930 if(MSVC)
931 install(TARGETS ${BINARY_NAME}_libretro RUNTIME DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro)
932 else()
933 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
934 endif()
935endif()
936
937if(BUILD_OPENEMU)
938 find_library(FOUNDATION Foundation)
939 find_library(OPENEMUBASE OpenEmuBase)
940 file(GLOB OE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/*.m)
941 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OS_SRC})
942 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
943 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/Info.plist.in
944 BUNDLE TRUE
945 BUNDLE_EXTENSION oecoreplugin
946 OUTPUT_NAME ${PROJECT_NAME}
947 COMPILE_DEFINITIONS "DISABLE_THREADING;MGBA_STANDALONE;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
948 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
949 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${OE_LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
950endif()
951
952if(BUILD_SDL)
953 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/sdl ${CMAKE_CURRENT_BINARY_DIR}/sdl)
954endif()
955
956if(BUILD_QT)
957 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt)
958endif()
959
960if(NOT USE_CMOCKA)
961 set(BUILD_SUITE OFF)
962endif()
963add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test ${CMAKE_CURRENT_BINARY_DIR}/test)
964
965if(BUILD_EXAMPLE)
966 add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c)
967 target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME})
968 set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
969
970 if(SDL_FOUND)
971 add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)
972 target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
973 set_target_properties(${BINARY_NAME}-example-client PROPERTIES
974 COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}"
975 INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include")
976 endif()
977endif()
978
979file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba)
980configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h)
981install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
982install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba-util DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
983install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT ${BINARY_NAME}-dev)
984
985if(WIN32)
986 set(BIN_DIR ".\\")
987 string(REGEX REPLACE "[^-A-Za-z0-9_.]" "-" CLEAN_VERSION_STRING "${VERSION_STRING}")
988 file(RELATIVE_PATH SETUP_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup")
989 file(RELATIVE_PATH RES_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res")
990 string(REPLACE "/" "\\" SETUP_DIR "${SETUP_DIR_SLASH}")
991 string(REPLACE "/" "\\" RES_DIR "${RES_DIR_SLASH}")
992 if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$")
993 set(WIN_BITS 64)
994 else()
995 set(WIN_BITS 32)
996 endif()
997 if(GIT_TAG)
998 set(IS_RELEASE 1)
999 else()
1000 set(IS_RELEASE 0)
1001 endif()
1002 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup/setup.iss.in" ${CMAKE_CURRENT_BINARY_DIR}/setup.iss)
1003endif()
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 if(INSTALLER_NAME)
1037 set(INSTALLER_TARGET "${INSTALLER_NAME}.exe")
1038 set(ISCC_FLAGS "/F${INSTALLER_NAME}")
1039 else()
1040 set(INSTALLER_TARGET "${PROJECT_NAME}-setup-${CLEAN_VERSION_STRING}-win${WIN_BITS}.exe")
1041 endif()
1042 if(CMAKE_CROSSCOMPILING)
1043 find_program(WINE NAMES wine wine-stable wine-development)
1044 find_file(ISCC ISCC.exe HINTS "$ENV{HOME}/.wine/drive_c/Program Files/" PATH_SUFFIXES "Inno Setup 5")
1045 message(STATUS "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS})
1046 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1047 COMMAND "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1048 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1049 else()
1050 find_program(ISCC NAMES ISCC ISCC.exe PATH_SUFFIXES "Inno Setup 5")
1051 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1052 COMMAND "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1053 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1054 endif()
1055 if(ISCC)
1056 add_custom_target(installer ALL DEPENDS ${INSTALLER_TARGET})
1057 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${INSTALLER_TARGET}" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT installer)
1058 endif()
1059 endif()
1060endif()
1061
1062if(MARKDOWN)
1063 foreach(README ${READMES})
1064 get_filename_component(README_BASE "${README}" NAME_WE)
1065 add_custom_command(OUTPUT ${README_BASE}.html COMMAND ${MARKDOWN} "${README}" > ${README_BASE}.html MAIN_DEPENDENCY "${README}")
1066 add_custom_target(${README_BASE} ALL DEPENDS ${README_BASE}.html)
1067 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${README_BASE}.html DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1068 endforeach()
1069endif()
1070
1071set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
1072set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
1073set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
1074set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
1075set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
1076set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
1077
1078set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
1079set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
1080set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
1081set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
1082set(CPACK_DEBIAN_PACKAGE_SECTION "games")
1083
1084set(CPACK_DEB_COMPONENT_INSTALL ON)
1085
1086if(CMAKE_BUILD_TYPE STREQUAL "Release")
1087 set(CPACK_STRIP_FILES ON)
1088endif()
1089
1090if(DISTBUILD)
1091 set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
1092 if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND BUILD_SHARED)
1093 if(NOT APPLE)
1094 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}>" "$<TARGET_FILE:${BINARY_NAME}>.debug")
1095 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${STRIP}" "$<TARGET_FILE:${BINARY_NAME}>")
1096 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --add-gnu-debuglink "$<TARGET_FILE:${BINARY_NAME}>.debug" "$<TARGET_FILE:${BINARY_NAME}>")
1097 install(FILES "$<TARGET_FILE:${BINARY_NAME}>.debug" DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME}-dbg)
1098 endif()
1099 endif()
1100 if(APPLE)
1101 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf)
1102 set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
1103 elseif(WIN32)
1104 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf installer)
1105 elseif(3DS)
1106 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-3ds ${BINARY_NAME}-perf)
1107 elseif(WII)
1108 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-wii)
1109 elseif(PSP2)
1110 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-psp2)
1111 elseif(SWITCH)
1112 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-switch)
1113 endif()
1114endif()
1115
1116include(CPack)
1117
1118cpack_add_component_group(base)
1119cpack_add_component(${BINARY_NAME} GROUP base)
1120
1121cpack_add_component_group(dev PARENT_GROUP base)
1122if(BUILD_SHARED)
1123 cpack_add_component(lib${BINARY_NAME} GROUP base)
1124 if(BUILD_STATIC)
1125 cpack_add_component(lib${BINARY_NAME}-static GROUP dev)
1126 endif()
1127elseif(BUILD_STATIC)
1128 cpack_add_component(lib${BINARY_NAME} GROUP dev)
1129endif()
1130cpack_add_component(${BINARY_NAME}-dev GROUP dev)
1131
1132if(3DS)
1133 cpack_add_component(${BINARY_NAME}-3ds GROUP base)
1134elseif(PSP2)
1135 cpack_add_component(${BINARY_NAME}-psp2 GROUP base)
1136elseif(WII)
1137 cpack_add_component(${BINARY_NAME}-wii GROUP base)
1138elseif(SWITCH)
1139 cpack_add_component(${BINARY_NAME}-switch GROUP base)
1140endif()
1141
1142if(BUILD_QT)
1143 cpack_add_component_group(qt PARENT_GROUP base)
1144 cpack_add_component(${BINARY_NAME}-qt GROUP qt)
1145endif()
1146
1147if(SDL_FOUND)
1148 cpack_add_component_group(sdl PARENT_GROUP base)
1149 cpack_add_component(${BINARY_NAME}-sdl GROUP sdl)
1150endif()
1151
1152if(DISTBUILD)
1153 cpack_add_component_group(debug PARENT_GROUP dev)
1154 if(BUILD_SHARED AND NOT IS_EMBEDDED)
1155 cpack_add_component(lib${BINARY_NAME}-dbg GROUP debug)
1156 endif()
1157 if(IS_EMBEDDED)
1158 cpack_add_component(${BINARY_NAME}-dbg GROUP debug)
1159 endif()
1160 if(BUILD_QT)
1161 cpack_add_component(${BINARY_NAME}-qt-dbg GROUP debug)
1162 endif()
1163 if(SDL_FOUND)
1164 cpack_add_component(${BINARY_NAME}-sdl-dbg GROUP debug)
1165 endif()
1166 if(WIN32)
1167 cpack_add_component_group(installer PARENT_GROUP base)
1168 endif()
1169endif()
1170
1171cpack_add_component_group(test PARENT_GROUP dev)
1172cpack_add_component(${BINARY_NAME}-perf GROUP test)
1173cpack_add_component(${BINARY_NAME}-test GROUP test)
1174
1175# Summaries
1176set(SUMMARY_GL_LIST)
1177if(USE_EPOXY)
1178 set(SUMMARY_GL_LIST "libepoxy")
1179else()
1180 if(BUILD_GL)
1181 list(APPEND SUMMARY_GL_LIST "OpenGL")
1182 endif()
1183 if(BUILD_GLES2)
1184 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
1185 endif()
1186 if(BUILD_GLES3)
1187 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 3")
1188 endif()
1189endif()
1190if(NOT SUMMARY_GL_LIST)
1191 set(SUMMARY_GL OFF)
1192else()
1193 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
1194endif()
1195if(USE_LIBZIP)
1196 set(SUMMARY_ZIP libzip)
1197elseif(USE_MINIZIP)
1198 set(SUMMARY_ZIP "minizip (external)")
1199elseif(USE_ZLIB)
1200 set(SUMMARY_ZIP "minizip (included)")
1201else()
1202 set(SUMMARY_ZIP OFF)
1203endif()
1204
1205if(NOT QUIET AND NOT LIBMGBA_ONLY)
1206 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1207 message(STATUS "Platforms:")
1208 message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
1209 message(STATUS " Game Boy: ${M_CORE_GB}")
1210 message(STATUS "Features:")
1211 message(STATUS " Debuggers: ${USE_DEBUGGERS}")
1212 if(NOT WIN32)
1213 message(STATUS " CLI debugger: ${USE_EDITLINE}")
1214 endif()
1215 message(STATUS " GDB stub: ${USE_GDB_STUB}")
1216 message(STATUS " GIF/Video recording: ${USE_FFMPEG}")
1217 message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
1218 message(STATUS " ZIP support: ${SUMMARY_ZIP}")
1219 message(STATUS " 7-Zip support: ${USE_LZMA}")
1220 message(STATUS " SQLite3 game database: ${USE_SQLITE3}")
1221 message(STATUS " ELF loading support: ${USE_ELF}")
1222 message(STATUS " Discord Rich Presence support: ${USE_DISCORD_RPC}")
1223 message(STATUS " OpenGL support: ${SUMMARY_GL}")
1224 message(STATUS "Frontends:")
1225 message(STATUS " Qt: ${BUILD_QT}")
1226 message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
1227 message(STATUS " Profiling: ${BUILD_PERF}")
1228 message(STATUS " Test harness: ${BUILD_TEST}")
1229 message(STATUS " Test suite: ${BUILD_SUITE}")
1230 message(STATUS " Video test suite: ${BUILD_CINEMA}")
1231 message(STATUS " Python bindings: ${BUILD_PYTHON}")
1232 message(STATUS " Examples: ${BUILD_EXAMPLE}")
1233 message(STATUS "Cores:")
1234 message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
1235 if(APPLE)
1236 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
1237 endif()
1238 message(STATUS "Libraries:")
1239 message(STATUS " Static: ${BUILD_STATIC}")
1240 message(STATUS " Shared: ${BUILD_SHARED}")
1241endif()