all repos — mgba @ 453791d28987558d3d2eb3d4facc829b84ab8257

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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