all repos — mgba @ 9262475cb47c1bbfd4422591394b789ce18f6b6b

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