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