all repos — mgba @ b8e9f50c92a55c3d81b2f5f12bbc6d49a84f1a9c

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