all repos — mgba @ 0230e654a30643c9035007adc3fb323a12405885

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(BUILD_PERF)
 932	set(PERF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/perf-main.c)
 933	if(UNIX AND NOT APPLE)
 934		list(APPEND PERF_LIB rt)
 935	endif()
 936
 937	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
 938	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB} ${OS_LIB})
 939	set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 940	install(TARGETS ${BINARY_NAME}-perf DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-perf)
 941	install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/perf.py DESTINATION "${LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
 942endif()
 943
 944if(BUILD_TEST)
 945	add_executable(${BINARY_NAME}-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/fuzz-main.c)
 946	target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
 947	set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 948	add_executable(tbl-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/tbl-fuzz-main.c)
 949	target_link_libraries(tbl-fuzz ${BINARY_NAME})
 950	set_target_properties(tbl-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 951	install(TARGETS ${BINARY_NAME}-fuzz tbl-fuzz DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test)
 952endif()
 953
 954if(NOT USE_CMOCKA)
 955	set(BUILD_SUITE OFF)
 956endif()
 957if(BUILD_SUITE)
 958	enable_testing()
 959	include_directories(AFTER ${CMOCKA_INCLUDE_DIRS})
 960	link_directories(${CMOCKA_LIBRARY_DIRS})
 961
 962	foreach(TEST IN LISTS TEST_SRC)
 963		string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" TEST_NAME "${TEST}")
 964		string(REPLACE "/" "-" TEST_NAME "${TEST_NAME}")
 965		string(REPLACE "-test" "" TEST_NAME "${TEST_NAME}")
 966		string(REPLACE ".c" "" TEST_NAME "${TEST_NAME}")
 967		add_executable(test-${TEST_NAME} ${TEST})
 968		target_link_libraries(test-${TEST_NAME} ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka)
 969		set_target_properties(test-${TEST_NAME} PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 970		add_test(${TEST_NAME} test-${TEST_NAME})
 971	endforeach()
 972endif()
 973
 974if(BUILD_EXAMPLE)
 975	add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c)
 976	target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME})
 977	set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
 978
 979	if(SDL_FOUND)
 980		add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)
 981		target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
 982		set_target_properties(${BINARY_NAME}-example-client PROPERTIES
 983		                      COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}"
 984		                      INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include")
 985	endif()
 986endif()
 987
 988file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/mgba)
 989configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h)
 990install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
 991install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mgba-util DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT ${BINARY_NAME}-dev FILES_MATCHING PATTERN "*.h")
 992install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/mgba/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT ${BINARY_NAME}-dev)
 993
 994if(WIN32)
 995	set(BIN_DIR ".\\")
 996	string(REGEX REPLACE "[^-A-Za-z0-9_.]" "-" CLEAN_VERSION_STRING "${VERSION_STRING}")
 997	file(RELATIVE_PATH SETUP_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup")
 998	file(RELATIVE_PATH RES_DIR_SLASH "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res")
 999	string(REPLACE "/" "\\" SETUP_DIR "${SETUP_DIR_SLASH}")
1000	string(REPLACE "/" "\\" RES_DIR "${RES_DIR_SLASH}")
1001	if(CMAKE_SYSTEM_PROCESSOR MATCHES ".*64$")
1002		set(WIN_BITS 64)
1003	else()
1004		set(WIN_BITS 32)
1005	endif()
1006	if(GIT_TAG)
1007		set(IS_RELEASE 1)
1008	else()
1009		set(IS_RELEASE 0)
1010	endif()
1011	configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/setup/setup.iss.in" ${CMAKE_CURRENT_BINARY_DIR}/setup.iss)
1012endif()
1013
1014# Packaging
1015install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/blip_buf.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1016install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/inih.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1017if(USE_DISCORD_RPC)
1018	install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/discord-rpc.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1019	install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/rapidjson.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1020	if(WIN32)
1021		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/licenses/mingw-std-threads.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1022	endif()
1023endif()
1024if(EXTRA_LICENSES)
1025	install(FILES ${EXTRA_LICENSES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT ${BINARY_NAME})
1026endif()
1027
1028file(GLOB READMES ${CMAKE_CURRENT_SOURCE_DIR}/README*.md)
1029
1030find_program(UNIX2DOS NAMES unix2dos)
1031find_program(MARKDOWN NAMES markdown kramdown pandoc)
1032
1033if(UNIX OR NOT UNIX2DOS)
1034	if(UNIX OR NOT MARKDOWN)
1035		install(FILES ${READMES} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1036	endif()
1037	install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/CHANGES" "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1038else()
1039	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")
1040	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")
1041	add_custom_target(CHANGES ALL DEPENDS CHANGES.txt)
1042	add_custom_target(LICENSE ALL DEPENDS LICENSE.txt)
1043	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CHANGES.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1044	if(DISTBUILD AND WIN32)
1045		if(INSTALLER_NAME)
1046			set(INSTALLER_TARGET "${INSTALLER_NAME}.exe")
1047			set(ISCC_FLAGS "/F${INSTALLER_NAME}")
1048		else()
1049			set(INSTALLER_TARGET "${PROJECT_NAME}-setup-${CLEAN_VERSION_STRING}-win${WIN_BITS}.exe")
1050		endif()
1051		if(CMAKE_CROSSCOMPILING)
1052			find_program(WINE NAMES wine wine-stable wine-development)
1053			find_file(ISCC ISCC.exe HINTS "$ENV{HOME}/.wine/drive_c/Program Files/" PATH_SUFFIXES "Inno Setup 5")
1054			message(STATUS "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS})
1055			add_custom_command(OUTPUT ${INSTALLER_TARGET}
1056			                   COMMAND "${WINE}" "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1057			                   DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1058		else()
1059			find_program(ISCC NAMES ISCC ISCC.exe PATH_SUFFIXES "Inno Setup 5")
1060			add_custom_command(OUTPUT ${INSTALLER_TARGET}
1061			                   COMMAND "${ISCC}" setup.iss /Q ${ISCC_FLAGS}
1062			                   DEPENDS ${BINARY_NAME}-qt ${BINARY_NAME}-sdl CHANGES LICENSE)
1063		endif()
1064		if(ISCC)
1065			add_custom_target(installer ALL DEPENDS ${INSTALLER_TARGET})
1066			install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${INSTALLER_TARGET}" DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT installer)
1067		endif()
1068	endif()
1069endif()
1070
1071if(MARKDOWN)
1072	foreach(README ${READMES})
1073		get_filename_component(README_BASE "${README}" NAME_WE)
1074		add_custom_command(OUTPUT ${README_BASE}.html COMMAND ${MARKDOWN} "${README}" > ${README_BASE}.html MAIN_DEPENDENCY "${README}")
1075		add_custom_target(${README_BASE} ALL DEPENDS ${README_BASE}.html)
1076		install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${README_BASE}.html DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT ${BINARY_NAME})
1077	endforeach()
1078endif()
1079
1080set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
1081set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
1082set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
1083set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
1084set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
1085set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
1086
1087set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
1088set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
1089set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
1090set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
1091set(CPACK_DEBIAN_PACKAGE_SECTION "games")
1092
1093set(CPACK_DEB_COMPONENT_INSTALL ON)
1094
1095if(CMAKE_BUILD_TYPE STREQUAL "Release")
1096	set(CPACK_STRIP_FILES ON)
1097endif()
1098
1099if(DISTBUILD)
1100	set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
1101	if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND BUILD_SHARED)
1102		if(NOT APPLE)
1103			add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${BINARY_NAME}>" "$<TARGET_FILE:${BINARY_NAME}>.debug")
1104			add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${STRIP}" "$<TARGET_FILE:${BINARY_NAME}>")
1105			add_custom_command(TARGET ${BINARY_NAME} POST_BUILD COMMAND "${OBJCOPY}" --add-gnu-debuglink "$<TARGET_FILE:${BINARY_NAME}>.debug" "$<TARGET_FILE:${BINARY_NAME}>")
1106			install(FILES "$<TARGET_FILE:${BINARY_NAME}>.debug" DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME}-dbg)
1107		endif()
1108	endif()
1109	if(APPLE)
1110		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf)
1111		set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
1112	elseif(WIN32)
1113		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-qt ${BINARY_NAME}-sdl ${BINARY_NAME}-qt-dbg ${BINARY_NAME}-sdl-dbg ${BINARY_NAME}-perf installer)
1114	elseif(3DS)
1115		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-3ds ${BINARY_NAME}-perf)
1116	elseif(WII)
1117		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-wii)
1118	elseif(PSP2)
1119		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-psp2)
1120	elseif(SWITCH)
1121		set(CPACK_COMPONENTS_ALL ${BINARY_NAME} ${BINARY_NAME}-dbg ${BINARY_NAME}-switch)
1122	endif()
1123endif()
1124
1125include(CPack)
1126
1127cpack_add_component_group(base)
1128cpack_add_component(${BINARY_NAME} GROUP base)
1129
1130cpack_add_component_group(dev PARENT_GROUP base)
1131if(BUILD_SHARED)
1132	cpack_add_component(lib${BINARY_NAME} GROUP base)
1133	if(BUILD_STATIC)
1134		cpack_add_component(lib${BINARY_NAME}-static GROUP dev)
1135	endif()
1136elseif(BUILD_STATIC)
1137	cpack_add_component(lib${BINARY_NAME} GROUP dev)
1138endif()
1139cpack_add_component(${BINARY_NAME}-dev GROUP dev)
1140
1141if(3DS)
1142	cpack_add_component(${BINARY_NAME}-3ds GROUP base)
1143elseif(PSP2)
1144	cpack_add_component(${BINARY_NAME}-psp2 GROUP base)
1145elseif(WII)
1146	cpack_add_component(${BINARY_NAME}-wii GROUP base)
1147elseif(SWITCH)
1148	cpack_add_component(${BINARY_NAME}-switch GROUP base)
1149endif()
1150
1151if(BUILD_QT)
1152	cpack_add_component_group(qt PARENT_GROUP base)
1153	cpack_add_component(${BINARY_NAME}-qt GROUP qt)
1154endif()
1155
1156if(SDL_FOUND)
1157	cpack_add_component_group(sdl PARENT_GROUP base)
1158	cpack_add_component(${BINARY_NAME}-sdl GROUP sdl)
1159endif()
1160
1161if(DISTBUILD)
1162	cpack_add_component_group(debug PARENT_GROUP dev)
1163	if(BUILD_SHARED AND NOT IS_EMBEDDED)
1164		cpack_add_component(lib${BINARY_NAME}-dbg GROUP debug)
1165	endif()
1166	if(IS_EMBEDDED)
1167		cpack_add_component(${BINARY_NAME}-dbg GROUP debug)
1168	endif()
1169	if(BUILD_QT)
1170		cpack_add_component(${BINARY_NAME}-qt-dbg GROUP debug)
1171	endif()
1172	if(SDL_FOUND)
1173		cpack_add_component(${BINARY_NAME}-sdl-dbg GROUP debug)
1174	endif()
1175	if(WIN32)
1176		cpack_add_component_group(installer PARENT_GROUP base)
1177	endif()
1178endif()
1179
1180cpack_add_component_group(test PARENT_GROUP dev)
1181cpack_add_component(${BINARY_NAME}-perf GROUP test)
1182cpack_add_component(${BINARY_NAME}-fuzz GROUP test)
1183cpack_add_component(tbl-fuzz GROUP test)
1184
1185# Summaries
1186set(SUMMARY_GL_LIST)
1187if(USE_EPOXY)
1188	set(SUMMARY_GL_LIST "libepoxy")
1189else()
1190	if(BUILD_GL)
1191		list(APPEND SUMMARY_GL_LIST "OpenGL")
1192	endif()
1193	if(BUILD_GLES2)
1194		list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
1195	endif()
1196	if(BUILD_GLES3)
1197		list(APPEND SUMMARY_GL_LIST "OpenGL|ES 3")
1198	endif()
1199endif()
1200if(NOT SUMMARY_GL_LIST)
1201	set(SUMMARY_GL OFF)
1202else()
1203	string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
1204endif()
1205if(USE_LIBZIP)
1206	set(SUMMARY_ZIP libzip)
1207elseif(USE_MINIZIP)
1208	set(SUMMARY_ZIP "minizip (external)")
1209elseif(USE_ZLIB)
1210	set(SUMMARY_ZIP "minizip (included)")
1211else()
1212	set(SUMMARY_ZIP OFF)
1213endif()
1214
1215if(NOT QUIET AND NOT LIBMGBA_ONLY)
1216	message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1217	message(STATUS "Platforms:")
1218	message(STATUS "	Game Boy Advance: ${M_CORE_GBA}")
1219	message(STATUS "	Game Boy: ${M_CORE_GB}")
1220	message(STATUS "Features:")
1221	message(STATUS "	Debuggers: ${USE_DEBUGGERS}")
1222	if(NOT WIN32)
1223		message(STATUS "	CLI debugger: ${USE_EDITLINE}")
1224	endif()
1225	message(STATUS "	GDB stub: ${USE_GDB_STUB}")
1226	message(STATUS "	GIF/Video recording: ${USE_FFMPEG}")
1227	message(STATUS "	Screenshot/advanced savestate support: ${USE_PNG}")
1228	message(STATUS "	ZIP support: ${SUMMARY_ZIP}")
1229	message(STATUS "	7-Zip support: ${USE_LZMA}")
1230	message(STATUS "	SQLite3 game database: ${USE_SQLITE3}")
1231	message(STATUS "	ELF loading support: ${USE_ELF}")
1232	message(STATUS "	Discord Rich Presence support: ${USE_DISCORD_RPC}")
1233	message(STATUS "	OpenGL support: ${SUMMARY_GL}")
1234	message(STATUS "Frontends:")
1235	message(STATUS "	Qt: ${BUILD_QT}")
1236	message(STATUS "	SDL (${SDL_VERSION}): ${BUILD_SDL}")
1237	message(STATUS "	Profiling: ${BUILD_PERF}")
1238	message(STATUS "	Test harness: ${BUILD_TEST}")
1239	message(STATUS "	Test suite: ${BUILD_SUITE}")
1240	message(STATUS "	Python bindings: ${BUILD_PYTHON}")
1241	message(STATUS "	Examples: ${BUILD_EXAMPLE}")
1242	message(STATUS "Cores:")
1243	message(STATUS "	Libretro core: ${BUILD_LIBRETRO}")
1244	if(APPLE)
1245		message(STATUS "	OpenEmu core: ${BUILD_OPENEMU}")
1246	endif()
1247	message(STATUS "Libraries:")
1248	message(STATUS "	Static: ${BUILD_STATIC}")
1249	message(STATUS "	Shared: ${BUILD_SHARED}")
1250endif()