all repos — mgba @ e2bcd2e05ad4d8fa879a5b32f56c91e1f5e4c964

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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