all repos — mgba @ 145a31868a21454ab91e2070ed6103bde333bbc9

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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