all repos — mgba @ appveyor

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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