all repos — mgba @ a921c891876e2e7895374742592a66b7e970118e

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