all repos — mgba @ d772794bdca3e71aa7061c96dcd0a9521696d0f2

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