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