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