all repos — mgba @ 246142fd551a1e8ba3cd41a49a1821505ed874da

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