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