all repos — mgba @ 1b601d005e3e1b5454f33c3022c76d055d188828

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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