all repos — mgba @ f3caf890b0e0fd69cf66cdfe7552ab6044971328

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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