all repos — mgba @ 64bdb02eebb551c7e0b425656a046cca3d180777

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