all repos — mgba @ f6755a6e1b7b0cf2b944cd8ca842746f11d6bf82

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