all repos — mgba @ bb6ecd41cb8446d1df43b6d7a0cb4638091a5c7b

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