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