all repos — mgba @ 0.7-b1

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