all repos — mgba @ d01190bf90b52cf974e5072a5edc1e7eb6d784bd

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