all repos — mgba @ 9ed7c9129d63194b40fd3ae2453ea6d6f6bafe0f

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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