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