all repos — mgba @ 9ba0a0250f3e16a1600afb1a00ff010e984417c5

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