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