all repos — mgba @ 346f5dc0b53afa8ea1e11d8c94a0090b5d49abc9

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