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