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 ON 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|DragonFly")
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(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
466endif()
467if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|Darwin|Linux|.*BSD|DragonFly|Haiku)$")
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_GL)
478 list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
479 list(APPEND OS_LIB ${OPENGL_LIBRARY})
480 include_directories(${OPENGL_INCLUDE_DIR})
481endif()
482if(BUILD_GLES2)
483 list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
484 list(APPEND OS_LIB ${OPENGLES2_LIBRARY})
485 include_directories(${OPENGLES2_INCLUDE_DIR})
486endif()
487if(BUILD_GLES3)
488 find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
489 find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
490 if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
491 set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
492 endif()
493endif()
494
495if(DISABLE_DEPS)
496 set(USE_GDB_STUB OFF)
497 set(USE_DISCORD_RPC OFF)
498 set(USE_SQLITE3 OFF)
499 set(USE_PNG OFF)
500 set(USE_ZLIB OFF)
501endif()
502
503set(WANT_ZLIB ${USE_ZLIB})
504set(WANT_PNG ${USE_PNG})
505set(WANT_SQLITE3 ${USE_SQLITE3})
506set(USE_CMOCKA ${BUILD_SUITE})
507
508find_feature(USE_FFMPEG "libavcodec;libavformat;libavutil;libswscale")
509find_feature(USE_ZLIB "ZLIB")
510find_feature(USE_MINIZIP "minizip")
511find_feature(USE_PNG "PNG")
512find_feature(USE_LIBZIP "libzip")
513find_feature(USE_MAGICK "MagickWand")
514find_feature(USE_EPOXY "epoxy")
515find_feature(USE_CMOCKA "cmocka")
516find_feature(USE_SQLITE3 "sqlite3")
517find_feature(USE_ELF "libelf")
518find_feature(ENABLE_PYTHON "PythonLibs")
519
520if(USE_FFMPEG)
521 set(USE_LIBAVRESAMPLE ON)
522 set(USE_LIBSWRESAMPLE ON)
523 find_feature(USE_LIBAVRESAMPLE "libavresample")
524 find_feature(USE_LIBSWRESAMPLE "libswresample")
525endif()
526
527# Features
528set(DEBUGGER_SRC
529 ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/debugger.c
530 ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/parser.c
531 ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/symbols.c
532 ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/cli-debugger.c)
533
534file(GLOB DEBUGGER_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/test/*.c)
535
536set(FEATURE_SRC)
537set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
538
539if(USE_EDITLINE)
540 list(APPEND FEATURES EDITLINE)
541 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
542 link_directories(${LIBEDIT_LIBRARY_DIRS})
543 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
544 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
545 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/editline/cli-el-backend.c")
546else()
547 set(DEBUGGER_LIB "")
548endif()
549
550if(USE_GDB_STUB)
551 list(APPEND FEATURES GDB_STUB)
552 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/gdb-stub.c)
553endif()
554source_group("Debugger" FILES ${DEBUGGER_SRC})
555
556if(USE_FFMPEG)
557 list(APPEND FEATURES FFMPEG)
558 if(USE_LIBSWRESAMPLE)
559 list(APPEND FEATURES LIBSWRESAMPLE)
560 else()
561 list(APPEND FEATURES LIBAVRESAMPLE)
562 list(APPEND FEATURES LIBAV)
563 endif()
564 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWRESAMPLE_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
565 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWRESAMPLE_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
566 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-encoder.c")
567 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
568 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
569 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
570 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
571 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES} ${LIBSWRESAMPLE_LIBRARIES})
572 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}")
573 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
574 if(USE_LIBSWRESAMPLE)
575 string(REGEX MATCH "^[0-9]+" LIBSWRESAMPLE_VERSION_MAJOR ${libswresample_VERSION})
576 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_MAJOR}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_MAJOR}")
577 else()
578 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
579 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
580 endif()
581 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
582 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
583 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
584 if(APPLE)
585 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
586 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
587 endif()
588endif()
589
590list(APPEND THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
591
592if(USE_MAGICK)
593 list(APPEND FEATURES MAGICK)
594 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
595 link_directories(${MAGICKWAND_LIBRARY_DIRS})
596 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/imagemagick/imagemagick-gif-encoder.c")
597 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
598 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
599 string(REGEX MATCH "^[0-9]+" MAGICKWAND_VERSION_MAJOR ${MagickWand_VERSION})
600 if(${MAGICKWAND_VERSION_PARTIAL} STREQUAL "6.7")
601 set(MAGICKWAND_DEB_VERSION "5")
602 elseif(${MagickWand_VERSION} STREQUAL "6.9.10")
603 set(MAGICKWAND_DEB_VERSION "-6.q16-6")
604 elseif(${MagickWand_VERSION} STREQUAL "6.9.7")
605 set(MAGICKWAND_DEB_VERSION "-6.q16-3")
606 else()
607 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
608 endif()
609 list(APPEND FEATURE_DEFINES MAGICKWAND_VERSION_MAJOR=${MAGICKWAND_VERSION_MAJOR})
610 list(APPEND FEATURE_FLAGS ${MAGICKWAND_CFLAGS_OTHER})
611
612 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
613endif()
614
615if(WANT_ZLIB AND NOT USE_ZLIB)
616 set(SKIP_INSTALL_ALL ON)
617 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib zlib EXCLUDE_FROM_ALL)
618 set_target_properties(zlibstatic PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/zlib;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib" POSITION_INDEPENDENT_CODE ON)
619 set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
620 set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
621 set(ZLIB_LIBRARY zlibstatic)
622 list(APPEND DEPENDENCY_LIB zlibstatic)
623 set(USE_ZLIB ON)
624endif()
625
626if(USE_ZLIB)
627 list(APPEND FEATURES ZLIB)
628 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
629 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
630 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
631 set(HAVE_CRC32 ON)
632 list(APPEND OS_LIB ${ZLIB_LIBRARIES})
633else()
634 # zlib pulls in crc32
635 check_function_exists(crc32 HAVE_CRC32)
636endif()
637
638if(HAVE_CRC32)
639 list(APPEND FUNCTION_DEFINES HAVE_CRC32)
640endif()
641
642if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
643 set(PNG_STATIC ON CACHE BOOL "" FORCE)
644 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
645 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
646 set(SKIP_INSTALL_ALL ON)
647 if (SWITCH)
648 set(PNG_ARM_NEON "off" CACHE STRING "" FORCE)
649 endif()
650 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng libpng EXCLUDE_FROM_ALL)
651 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)
652 set(PNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
653 list(APPEND DEPENDENCY_LIB png_static)
654 set(USE_PNG ON)
655endif()
656
657if(USE_PNG)
658 list(APPEND FEATURES PNG)
659 include_directories(AFTER ${PNG_INCLUDE_DIRS})
660 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
661 if(PNG_VERSION_STRING)
662 string(REGEX MATCH "^[0-9]+\\.[0-9]+" PNG_VERSION_PARTIAL ${PNG_VERSION_STRING})
663 if(${PNG_VERSION_PARTIAL} STREQUAL "1.6")
664 set(PNG_DEB_VERSION "16-16")
665 else()
666 set(PNG_DEB_VERSION "12-0")
667 endif()
668 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng${PNG_DEB_VERSION}")
669 endif()
670endif()
671
672if(WANT_SQLITE3 AND NOT USE_SQLITE3)
673 list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/sqlite3.c)
674 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/)
675 set(USE_SQLITE3 ON)
676endif()
677
678if(USE_LIBZIP)
679 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
680 link_directories(${LIBZIP_LIBRARY_DIRS})
681 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
682 list(APPEND FEATURES LIBZIP)
683 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
684 string(REGEX MATCH "^[0-9]+" LIBZIP_VERSION_MAJOR ${libzip_VERSION})
685 if (LIBZIP_VERSION_MAJOR LESS 1)
686 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
687 elseif(LIBZIP_VERSION_MAJOR EQUAL 1)
688 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip4")
689 else()
690 message(AUTHOR_WARNING Unknown version of libzip detected: ${libzip_VERSION})
691 endif()
692elseif(USE_MINIZIP)
693 include_directories(AFTER ${MINIZIP_INCLUDE_DIRS})
694 link_directories(${MINIZIP_LIBRARY_DIRS})
695 list(APPEND DEPENDENCY_LIB ${MINIZIP_LIBRARIES})
696 list(APPEND FEATURES MINIZIP)
697 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
698 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libminizip1")
699elseif(USE_ZLIB)
700 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c
701 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
702 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
703 if(NOT MSVC)
704 set_source_files_properties(
705 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
706 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c
707 PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-implicit-function-declaration")
708 endif()
709endif()
710
711if (USE_LZMA)
712 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma)
713 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
714 list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
715 set(LZMA_SRC
716 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
717 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
718 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
719 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
720 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
721 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
722 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zDec.c
723 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
724 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Delta.c
725 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
726 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
727 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra.c
728 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra86.c
729 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
730 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
731 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
732 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
733 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zFile.c
734 ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
735 list(APPEND VFS_SRC ${LZMA_SRC})
736 list(APPEND FEATURES LZMA)
737endif()
738
739if(USE_EPOXY)
740 add_definitions(-DBUILD_GL -DBUILD_GLES2)
741 list(APPEND FEATURES EPOXY)
742 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
743 link_directories(${EPOXY_LIBRARY_DIRS})
744 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
745 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
746elseif(BUILD_GL)
747 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgl1|libgles2")
748elseif(BUILD_GLES2)
749 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libgles2")
750endif()
751
752if(USE_SQLITE3)
753 list(APPEND FEATURES SQLITE3)
754 include_directories(AFTER ${SQLITE3_INCLUDE_DIRS})
755 link_directories(${SQLITE3_LIBRARY_DIRS})
756 list(APPEND DEPENDENCY_LIB ${SQLITE3_LIBRARIES})
757 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsqlite3-0")
758 list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/sqlite3/no-intro.c")
759endif()
760
761if(USE_ELF)
762 list(APPEND FEATURES ELF)
763 include_directories(AFTER ${LIBELF_INCLUDE_DIRS})
764 link_directories(${LIBELF_LIBRARY_DIRS})
765 list(APPEND DEPENDENCY_LIB ${LIBELF_LIBRARIES})
766 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libelf1")
767endif()
768
769if (USE_DISCORD_RPC)
770 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc discord-rpc EXCLUDE_FROM_ALL)
771 list(APPEND FEATURES DISCORD_RPC)
772 include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/discord-rpc/include)
773endif()
774
775if(ENABLE_SCRIPTING)
776 list(APPEND ENABLES SCRIPTING)
777
778 if(BUILD_PYTHON)
779 find_package(PythonLibs ${USE_PYTHON_VERSION})
780 list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
781 include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
782 list(APPEND ENABLES PYTHON)
783 endif()
784endif()
785
786set(TEST_SRC ${CORE_TEST_SRC})
787if(M_CORE_GB)
788 add_definitions(-DM_CORE_GB)
789 list(APPEND CORE_SRC
790 ${LR35902_SRC}
791 ${GB_SRC}
792 ${GB_RENDERER_SRC})
793 list(APPEND DEBUGGER_SRC
794 ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/cli-debugger.c
795 ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c
796 ${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/memory-debugger.c
797 ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/cli.c
798 ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/debugger.c
799 ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/symbols.c)
800 list(APPEND TEST_SRC
801 ${LR35902_TEST_SRC}
802 ${GB_TEST_SRC})
803endif()
804
805if(M_CORE_GBA)
806 add_definitions(-DM_CORE_GBA)
807 list(APPEND CORE_SRC
808 ${ARM_SRC}
809 ${GBA_SRC}
810 ${GBA_CHEATS_SRC}
811 ${GBA_RENDERER_SRC})
812 list(APPEND DEBUGGER_SRC
813 ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/cli-debugger.c
814 ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/debugger.c
815 ${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/memory-debugger.c
816 ${CMAKE_CURRENT_SOURCE_DIR}/src/gba/debugger/cli.c)
817 list(APPEND TEST_SRC
818 ${ARM_TEST_SRC}
819 ${GBA_TEST_SRC})
820 if(NOT M_CORE_GB)
821 list(APPEND CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/audio.c)
822 endif()
823endif()
824
825if(USE_DEBUGGERS)
826 list(APPEND FEATURE_SRC ${DEBUGGER_SRC})
827 list(APPEND TEST_SRC ${DEBUGGER_TEST_SRC})
828 list(APPEND FEATURES DEBUGGERS)
829endif()
830
831foreach(FEATURE IN LISTS FEATURES)
832 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
833endforeach()
834
835foreach(ENABLE IN LISTS ENABLES)
836 list(APPEND FEATURE_DEFINES "ENABLE_${ENABLE}")
837endforeach()
838
839source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
840source_group("Extra features" FILES ${FEATURE_SRC})
841source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
842
843# Platform binaries
844if(DEFINED 3DS)
845 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/3ds ${CMAKE_CURRENT_BINARY_DIR}/3ds)
846endif()
847
848if(DEFINED WII)
849 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/wii ${CMAKE_CURRENT_BINARY_DIR}/wii)
850endif()
851
852if(DEFINED PSP2)
853 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/psp2 ${CMAKE_CURRENT_BINARY_DIR}/psp2)
854endif()
855
856if(DEFINED SWITCH)
857 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/switch ${CMAKE_CURRENT_BINARY_DIR}/switch)
858endif()
859
860# Binaries
861list(APPEND CORE_SRC
862 ${UTIL_SRC}
863 ${CORE_VFS_SRC}
864 ${OS_SRC}
865 ${THIRD_PARTY_SRC})
866list(APPEND TEST_SRC ${UTIL_TEST_SRC})
867
868set(SRC ${CORE_SRC} ${VFS_SRC})
869if(NOT MINIMAL_CORE)
870 set(ENABLE_EXTRA ON)
871 if(M_CORE_GBA)
872 list(APPEND SRC
873 ${GBA_SIO_SRC})
874 endif()
875 if(M_CORE_GB)
876 list(APPEND SRC
877 ${GB_SIO_SRC})
878 endif()
879 list(APPEND SRC
880 ${FEATURE_SRC})
881endif()
882
883if(ENABLE_EXTRA)
884 if(M_CORE_GBA)
885 list(APPEND SRC
886 ${GBA_RR_SRC}
887 ${GBA_EXTRA_SRC})
888 endif()
889 if(M_CORE_GB)
890 list(APPEND SRC
891 ${GB_EXTRA_SRC})
892 endif()
893 list(APPEND SRC
894 ${EXTRA_SRC})
895endif()
896
897if(NOT SKIP_LIBRARY)
898 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
899 set(BUILD_SHARED ON)
900 endif()
901
902 if(BUILD_SHARED)
903 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
904 if(BUILD_STATIC)
905 add_library(${BINARY_NAME}-static STATIC ${SRC})
906 target_include_directories(${BINARY_NAME}-static BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
907 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}" COMPILE_OPTIONS "${FEATURE_FLAGS}")
908 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
909 add_dependencies(${BINARY_NAME}-static version-info)
910 endif()
911 else()
912 add_library(${BINARY_NAME} STATIC ${SRC})
913 endif()
914
915 target_include_directories(${BINARY_NAME} BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)
916 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}")
917 add_dependencies(${BINARY_NAME} version-info)
918
919 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
920 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
921 if(UNIX AND NOT APPLE AND NOT HAIKU)
922 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
923 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
924 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
925 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
926 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
927 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
928 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
929 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
930 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT ${BINARY_NAME})
931 endif()
932else()
933 set(BUILD_SHARED OFF)
934 set(BUILD_STATIC OFF)
935 find_library(${BINARY_NAME} ${BINARY_NAME})
936 if(NOT ${BINARY_NAME}_FOUND)
937 set(DISABLE_FRONTENDS ON)
938 set(BUILD_PERF OFF)
939 set(BUILD_TEST OFF)
940 set(BUILD_SUITE OFF)
941 endif()
942endif()
943
944if(BUILD_GL)
945 add_definitions(-DBUILD_GL)
946endif()
947
948if(BUILD_GLES2)
949 add_definitions(-DBUILD_GLES2)
950endif()
951
952if(BUILD_GLES3)
953 add_definitions(-DBUILD_GLES3)
954endif()
955
956if(DISABLE_FRONTENDS)
957 set(BUILD_SDL OFF)
958 set(BUILD_QT OFF)
959endif()
960
961if(BUILD_PYTHON)
962 enable_testing()
963 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/python ${CMAKE_CURRENT_BINARY_DIR}/python)
964endif()
965
966if(BUILD_LIBRETRO)
967 file(GLOB RETRO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/libretro/*.c)
968 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
969 add_dependencies(${BINARY_NAME} version-info)
970 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")
971 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
972 if(MSVC)
973 install(TARGETS ${BINARY_NAME}_libretro RUNTIME DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro)
974 else()
975 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
976 endif()
977endif()
978
979if(BUILD_OPENEMU)
980 find_library(FOUNDATION Foundation)
981 find_library(OPENEMUBASE OpenEmuBase)
982 file(GLOB OE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/*.m)
983 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OS_SRC})
984 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
985 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/Info.plist.in
986 BUNDLE TRUE
987 BUNDLE_EXTENSION oecoreplugin
988 OUTPUT_NAME ${PROJECT_NAME}
989 COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
990 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
991 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${OE_LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
992endif()
993
994if(BUILD_SDL)
995 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/sdl ${CMAKE_CURRENT_BINARY_DIR}/sdl)
996endif()
997
998if(BUILD_QT)
999 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt)
1000endif()
1001
1002if(BUILD_PERF)
1003 set(PERF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/perf-main.c)
1004 if(UNIX AND NOT APPLE)
1005 list(APPEND PERF_LIB rt)
1006 endif()
1007
1008 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
1009 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB} ${OS_LIB})
1010 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
1011 install(TARGETS ${BINARY_NAME}-perf DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-perf)
1012 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/perf.py DESTINATION "${LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
1013endif()
1014
1015if(BUILD_TEST)
1016 add_executable(${BINARY_NAME}-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/fuzz-main.c)
1017 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
1018 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
1019 add_executable(tbl-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/tbl-fuzz-main.c)
1020 target_link_libraries(tbl-fuzz ${BINARY_NAME})
1021 set_target_properties(tbl-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
1022 install(TARGETS ${BINARY_NAME}-fuzz tbl-fuzz DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test)
1023endif()
1024
1025if(NOT USE_CMOCKA)
1026 set(BUILD_SUITE OFF)
1027endif()
1028if(BUILD_SUITE)
1029 enable_testing()
1030 include_directories(AFTER ${CMOCKA_INCLUDE_DIRS})
1031 link_directories(${CMOCKA_LIBRARY_DIRS})
1032
1033 foreach(TEST IN LISTS TEST_SRC)
1034 string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" TEST_NAME "${TEST}")
1035 string(REPLACE "/" "-" TEST_NAME "${TEST_NAME}")
1036 string(REPLACE "-test" "" TEST_NAME "${TEST_NAME}")
1037 string(REPLACE ".c" "" TEST_NAME "${TEST_NAME}")
1038 add_executable(test-${TEST_NAME} ${TEST})
1039 target_link_libraries(test-${TEST_NAME} ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka)
1040 set_target_properties(test-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
1041 add_test(${TEST_NAME} test-${TEST_NAME})
1042 endforeach()
1043endif()
1044
1045if(BUILD_EXAMPLE)
1046 add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c)
1047 target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME})
1048 set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
1049
1050 if(SDL_FOUND)
1051 add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)
1052 target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
1053 set_target_properties(${BINARY_NAME}-example-client PROPERTIES
1054 COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}"
1055 INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include")
1056 endif()
1057endif()
1058
1059file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba)
1060configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h)
1061install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
1062install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba-util DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
1063install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT ${BINARY_NAME}-dev)
1064
1065if(WIN32)
1066 set(BIN_DIR ".\\")
1067 string(REGEX REPLACE "[^-A-Za-z0-9_.]" "-" CLEAN_VERSION_STRING "${VERSION_STRING}")
1068 file(RELATIVE_PATH SETUP_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup")
1069 file(RELATIVE_PATH RES_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res")
1070 string(REPLACE "/" "\\" SETUP_DIR "${SETUP_DIR_SLASH}")
1071 string(REPLACE "/" "\\" RES_DIR "${RES_DIR_SLASH}")
1072 if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$")
1073 set(WIN_BITS 64)
1074 else()
1075 set(WIN_BITS 32)
1076 endif()
1077 if(GIT_TAG)
1078 set(IS_RELEASE 1)
1079 else()
1080 set(IS_RELEASE 0)
1081 endif()
1082 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup/setup.iss.in" ${CMAKE_CURRENT_BINARY_DIR}/setup.iss)
1083endif()
1084
1085# Packaging
1086install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/blip_buf.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1087install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/inih.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1088if(USE_DISCORD_RPC)
1089 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/discord-rpc.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1090 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/rapidjson.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1091 if(WIN32)
1092 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/mingw-std-threads.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1093 endif()
1094endif()
1095if(EXTRA_LICENSES)
1096 install(FILES ${EXTRA_LICENSES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1097endif()
1098
1099file(GLOB READMES ${CMAKE_CURRENT_SOURCE_DIR}/README*.md)
1100
1101find_program(UNIX2DOS NAMES unix2dos)
1102find_program(MARKDOWN NAMES markdown kramdown pandoc)
1103
1104if(UNIX OR NOT UNIX2DOS)
1105 if(UNIX OR NOT MARKDOWN)
1106 install(FILES ${READMES} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1107 endif()
1108 install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1109else()
1110 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")
1111 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")
1112 add_custom_target(CHANGES ALL DEPENDS CHANGES.txt)
1113 add_custom_target(LICENSE ALL DEPENDS LICENSE.txt)
1114 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1115 if(DISTBUILD AND WIN32)
1116 if(INSTALLER_NAME)
1117 set(INSTALLER_TARGET "${INSTALLER_NAME}.exe")
1118 set(ISCC_FLAGS "/F${INSTALLER_NAME}")
1119 else()
1120 set(INSTALLER_TARGET "${PROJECT_NAME}-setup-${CLEAN_VERSION_STRING}-win${WIN_BITS}.exe")
1121 endif()
1122 if(CMAKE_CROSSCOMPILING)
1123 find_program(WINE NAMES wine wine-stable wine-development)
1124 find_file(ISCC ISCC.exe HINTS "$ENV{HOME}/.wine/drive_c/Program Files/" PATH_SUFFIXES "Inno Setup 5")
1125 message(STATUS "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS})
1126 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1127 COMMAND "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1128 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1129 else()
1130 find_program(ISCC NAMES ISCC ISCC.exe PATH_SUFFIXES "Inno Setup 5")
1131 add_custom_command(OUTPUT ${INSTALLER_TARGET}
1132 COMMAND "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1133 DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1134 endif()
1135 if(ISCC)
1136 add_custom_target(installer ALL DEPENDS ${INSTALLER_TARGET})
1137 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${INSTALLER_TARGET}" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT installer)
1138 endif()
1139 endif()
1140endif()
1141
1142if(MARKDOWN)
1143 foreach(README ${READMES})
1144 get_filename_component(README_BASE "${README}" NAME_WE)
1145 add_custom_command(OUTPUT ${README_BASE}.html COMMAND ${MARKDOWN} "${README}" > ${README_BASE}.html MAIN_DEPENDENCY "${README}")
1146 add_custom_target(${README_BASE} ALL DEPENDS ${README_BASE}.html)
1147 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${README_BASE}.html DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1148 endforeach()
1149endif()
1150
1151set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
1152set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
1153set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
1154set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
1155set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
1156set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
1157
1158set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
1159set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
1160set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
1161set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
1162set(CPACK_DEBIAN_PACKAGE_SECTION "games")
1163
1164set(CPACK_DEB_COMPONENT_INSTALL ON)
1165
1166if(CMAKE_BUILD_TYPE STREQUAL "Release")
1167 set(CPACK_STRIP_FILES ON)
1168endif()
1169
1170if(DISTBUILD)
1171 set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
1172 if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND BUILD_SHARED)
1173 if(NOT APPLE)
1174 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}>" "$<TARGET_FILE:${BINARY_NAME}>.dSYM")
1175 add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${STRIP}" -S "$<TARGET_FILE:${BINARY_NAME}>")
1176 install(FILES "$<TARGET_FILE:${BINARY_NAME}>.dSYM" DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME}-dbg)
1177 endif()
1178 endif()
1179 if(APPLE)
1180 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf)
1181 set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
1182 elseif(WIN32)
1183 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf installer)
1184 elseif(3DS)
1185 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-3ds ${BINARY_NAME}-perf)
1186 elseif(WII)
1187 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-wii)
1188 elseif(PSP2)
1189 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-psp2)
1190 elseif(SWITCH)
1191 set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-switch)
1192 endif()
1193endif()
1194
1195include(CPack)
1196
1197cpack_add_component_group(base)
1198cpack_add_component(${BINARY_NAME} GROUP base)
1199
1200cpack_add_component_group(dev PARENT_GROUP base)
1201if(BUILD_SHARED)
1202 cpack_add_component(lib${BINARY_NAME} GROUP base)
1203 if(BUILD_STATIC)
1204 cpack_add_component(lib${BINARY_NAME}-static GROUP dev)
1205 endif()
1206elseif(BUILD_STATIC)
1207 cpack_add_component(lib${BINARY_NAME} GROUP dev)
1208endif()
1209cpack_add_component(${BINARY_NAME}-dev GROUP dev)
1210
1211if(3DS)
1212 cpack_add_component(${BINARY_NAME}-3ds GROUP base)
1213elseif(PSP2)
1214 cpack_add_component(${BINARY_NAME}-psp2 GROUP base)
1215elseif(WII)
1216 cpack_add_component(${BINARY_NAME}-wii GROUP base)
1217elseif(SWITCH)
1218 cpack_add_component(${BINARY_NAME}-switch GROUP base)
1219endif()
1220
1221if(BUILD_QT)
1222 cpack_add_component_group(qt PARENT_GROUP base)
1223 cpack_add_component(${BINARY_NAME}-qt GROUP qt)
1224endif()
1225
1226if(SDL_FOUND)
1227 cpack_add_component_group(sdl PARENT_GROUP base)
1228 cpack_add_component(${BINARY_NAME}-sdl GROUP sdl)
1229endif()
1230
1231if(DISTBUILD)
1232 cpack_add_component_group(debug PARENT_GROUP dev)
1233 if(BUILD_SHARED AND NOT IS_EMBEDDED)
1234 cpack_add_component(lib${BINARY_NAME}-dbg GROUP debug)
1235 endif()
1236 if(IS_EMBEDDED)
1237 cpack_add_component(${BINARY_NAME}-dbg GROUP debug)
1238 endif()
1239 if(BUILD_QT)
1240 cpack_add_component(${BINARY_NAME}-qt-dbg GROUP debug)
1241 endif()
1242 if(SDL_FOUND)
1243 cpack_add_component(${BINARY_NAME}-sdl-dbg GROUP debug)
1244 endif()
1245 if(WIN32)
1246 cpack_add_component_group(installer PARENT_GROUP base)
1247 endif()
1248endif()
1249
1250cpack_add_component_group(test PARENT_GROUP dev)
1251cpack_add_component(${BINARY_NAME}-perf GROUP test)
1252cpack_add_component(${BINARY_NAME}-fuzz GROUP test)
1253cpack_add_component(tbl-fuzz GROUP test)
1254
1255# Summaries
1256set(SUMMARY_GL_LIST)
1257if(USE_EPOXY)
1258 set(SUMMARY_GL_LIST "libepoxy")
1259else()
1260 if(BUILD_GL)
1261 list(APPEND SUMMARY_GL_LIST "OpenGL")
1262 endif()
1263 if(BUILD_GLES2)
1264 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
1265 endif()
1266 if(BUILD_GLES3)
1267 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 3")
1268 endif()
1269endif()
1270if(NOT SUMMARY_GL_LIST)
1271 set(SUMMARY_GL OFF)
1272else()
1273 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
1274endif()
1275if(USE_LIBZIP)
1276 set(SUMMARY_ZIP libzip)
1277elseif(USE_MINIZIP)
1278 set(SUMMARY_ZIP "minizip (external)")
1279elseif(USE_ZLIB)
1280 set(SUMMARY_ZIP "minizip (included)")
1281else()
1282 set(SUMMARY_ZIP OFF)
1283endif()
1284
1285if(NOT QUIET AND NOT LIBMGBA_ONLY)
1286 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1287 message(STATUS "Platforms:")
1288 message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
1289 message(STATUS " Game Boy: ${M_CORE_GB}")
1290 message(STATUS "Features:")
1291 message(STATUS " Debuggers: ${USE_DEBUGGERS}")
1292 if(NOT WIN32)
1293 message(STATUS " CLI debugger: ${USE_EDITLINE}")
1294 endif()
1295 message(STATUS " GDB stub: ${USE_GDB_STUB}")
1296 message(STATUS " Video recording: ${USE_FFMPEG}")
1297 message(STATUS " GIF recording: ${USE_MAGICK}")
1298 message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
1299 message(STATUS " ZIP support: ${SUMMARY_ZIP}")
1300 message(STATUS " 7-Zip support: ${USE_LZMA}")
1301 message(STATUS " SQLite3 game database: ${USE_SQLITE3}")
1302 message(STATUS " ELF loading support: ${USE_ELF}")
1303 message(STATUS " Discord Rich Presence support: ${USE_DISCORD_RPC}")
1304 message(STATUS " OpenGL support: ${SUMMARY_GL}")
1305 message(STATUS "Frontends:")
1306 message(STATUS " Qt: ${BUILD_QT}")
1307 message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
1308 message(STATUS " Profiling: ${BUILD_PERF}")
1309 message(STATUS " Test harness: ${BUILD_TEST}")
1310 message(STATUS " Test suite: ${BUILD_SUITE}")
1311 message(STATUS " Python bindings: ${BUILD_PYTHON}")
1312 message(STATUS " Examples: ${BUILD_EXAMPLE}")
1313 message(STATUS "Cores:")
1314 message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
1315 if(APPLE)
1316 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
1317 endif()
1318 message(STATUS "Libraries:")
1319 message(STATUS " Static: ${BUILD_STATIC}")
1320 message(STATUS " Shared: ${BUILD_SHARED}")
1321endif()