all repos — mgba @ 1a7a544ba7891471fd94f2626a1c1af2c3427228

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")
400
401# Features
402set(DEBUGGER_SRC
403	${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/debugger.c
404	${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/parser.c
405	${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/symbols.c
406	${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/cli-debugger.c)
407
408set(FEATURE_SRC)
409set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
410
411if(DISABLE_DEPS)
412	set(USE_GDB_STUB OFF)
413endif()
414
415if(USE_EDITLINE)
416	list(APPEND FEATURES EDITLINE)
417	include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
418	link_directories(${LIBEDIT_LIBRARY_DIRS})
419	set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
420	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
421	list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/editline/cli-el-backend.c")
422else()
423	set(DEBUGGER_LIB "")
424endif()
425
426if(USE_GDB_STUB)
427	list(APPEND FEATURES GDB_STUB)
428	list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/debugger/gdb-stub.c)
429endif()
430source_group("Debugger" FILES ${DEBUGGER_SRC})
431
432if(USE_FFMPEG)
433	list(APPEND FEATURES FFMPEG)
434	pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
435	if(NOT LIBSWRESAMPLE_FOUND)
436		list(APPEND FEATURES LIBAV)
437	endif()
438	include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
439	link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
440	list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/ffmpeg/ffmpeg-encoder.c")
441	string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
442	string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
443	string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
444	string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
445	string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
446	list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
447	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}")
448	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
449	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
450	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
451	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
452	set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
453	if(APPLE)
454		set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
455		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
456	endif()
457endif()
458
459list(APPEND THIRD_PARTY_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
460
461if(USE_MAGICK)
462	list(APPEND FEATURES MAGICK)
463	include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
464	link_directories(${MAGICKWAND_LIBRARY_DIRS})
465	list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/imagemagick/imagemagick-gif-encoder.c")
466	list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
467	string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
468	string(REGEX MATCH "^[0-9]+" MAGICKWAND_VERSION_MAJOR ${MagickWand_VERSION})
469	if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
470		set(MAGICKWAND_DEB_VERSION "5")
471	elseif(${MagickWand_VERSION} EQUAL "6.9.7")
472		set(MAGICKWAND_DEB_VERSION "-6.q16-3")
473	else()
474		set(MAGICKWAND_DEB_VERSION "-6.q16-2")
475	endif()
476	list(APPEND FEATURE_DEFINES MAGICKWAND_VERSION_MAJOR=${MAGICKWAND_VERSION_MAJOR})
477
478	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
479endif()
480
481if(WANT_ZLIB AND NOT USE_ZLIB)
482	set(SKIP_INSTALL_ALL ON)
483	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib zlib)
484	set_property(TARGET zlibstatic PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/zlib;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib)
485	set_property(TARGET zlib PROPERTY EXCLUDE_FROM_ALL ON)
486	set_property(TARGET example PROPERTY EXCLUDE_FROM_ALL ON)
487	set_property(TARGET minigzip PROPERTY EXCLUDE_FROM_ALL ON)
488	set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
489	set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib ${CMAKE_CURRENT_BINARY_DIR}/zlib)
490	set(ZLIB_LIBRARY zlibstatic)
491	list(APPEND DEPENDENCY_LIB zlibstatic)
492	set(USE_ZLIB ON)
493endif()
494
495if(USE_ZLIB)
496	list(APPEND FEATURES ZLIB)
497	include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
498	list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
499	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
500endif()
501
502if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
503	set(PNG_STATIC ON CACHE BOOL "" FORCE)
504	set(PNG_SHARED OFF CACHE BOOL "" FORCE)
505	set(PNG_TESTS OFF CACHE BOOL "" FORCE)
506	set(SKIP_INSTALL_ALL ON)
507	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng libpng)
508	set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/libpng;${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
509	set(PNG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
510	list(APPEND DEPENDENCY_LIB png16_static)
511	set(USE_PNG ON)
512endif()
513
514if(USE_PNG)
515	list(APPEND FEATURES PNG)
516	include_directories(AFTER ${PNG_INCLUDE_DIRS})
517	list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
518	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
519endif()
520
521if(WANT_SQLITE3 AND NOT USE_SQLITE3)
522	list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/sqlite3.c)
523	include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/sqlite3/)
524	set(USE_SQLITE3 ON)
525endif()
526
527if(USE_LIBZIP)
528	include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
529	link_directories(${LIBZIP_LIBRARY_DIRS})
530	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
531	list(APPEND FEATURES LIBZIP)
532	list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
533	string(REGEX MATCH "^[0-9]+" LIBZIP_VERSION_MAJOR ${libzip_VERSION})
534	if (LIBZIP_VERSION_MAJOR LESS 1)
535		set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
536	elseif(LIBZIP_VERSION_MAJOR EQUAL 1)
537		set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip4")
538	else()
539		message(AUTHOR_WARNING Unknown version of libzip detected: ${libzip_VERSION})
540	endif()
541elseif(USE_MINIZIP)
542	include_directories(AFTER ${MINIZIP_INCLUDE_DIRS})
543	link_directories(${MINIZIP_LIBRARY_DIRS})
544	list(APPEND DEPENDENCY_LIB ${MINIZIP_LIBRARIES})
545	list(APPEND FEATURES MINIZIP)
546	list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
547	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libminizip1")
548elseif(USE_ZLIB)
549	list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-zip.c
550		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
551		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
552	if(NOT MSVC)
553		set_source_files_properties(
554			${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
555			${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c
556			PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-implicit-function-declaration")
557	endif()
558endif()
559
560if (USE_LZMA)
561	include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/third-party/lzma)
562	add_definitions(-D_7ZIP_PPMD_SUPPPORT)
563	list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
564	set(LZMA_SRC
565		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
566		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
567		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
568		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
569		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
570		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
571		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zDec.c
572		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
573		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Delta.c
574		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
575		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
576		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra.c
577		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bra86.c
578		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
579		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
580		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
581		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
582		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zFile.c
583		${CMAKE_CURRENT_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
584	list(APPEND VFS_SRC ${LZMA_SRC})
585	list(APPEND FEATURES LZMA)
586endif()
587
588if(USE_EPOXY)
589	add_definitions(-DBUILD_GL -DBUILD_GLES2)
590	list(APPEND FEATURES EPOXY)
591	include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
592	set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
593	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
594endif()
595
596if(USE_SQLITE3)
597	list(APPEND FEATURES SQLITE3)
598	include_directories(AFTER ${SQLITE3_INCLUDE_DIRS})
599	list(APPEND DEPENDENCY_LIB ${SQLITE3_LIBRARIES})
600	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libsqlite3-0")
601	list(APPEND FEATURE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/feature/sqlite3/no-intro.c")
602endif()
603
604if(ENABLE_SCRIPTING)
605	list(APPEND ENABLES SCRIPTING)
606endif()
607
608set(TEST_SRC ${CORE_TEST_SRC})
609if(M_CORE_GB)
610	add_definitions(-DM_CORE_GB)
611	list(APPEND CORE_SRC
612		${LR35902_SRC}
613		${GB_SRC}
614		${GB_RENDERER_SRC})
615	list(APPEND DEBUGGER_SRC
616		${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/cli-debugger.c
617		${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/debugger.c
618		${CMAKE_CURRENT_SOURCE_DIR}/src/lr35902/debugger/memory-debugger.c
619		${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/cli.c
620		${CMAKE_CURRENT_SOURCE_DIR}/src/gb/debugger/symbols.c)
621	list(APPEND TEST_SRC
622		${LR35902_TEST_SRC}
623		${GB_TEST_SRC})
624endif()
625
626if(M_CORE_GBA)
627	add_definitions(-DM_CORE_GBA)
628	list(APPEND CORE_SRC
629		${ARM_SRC}
630		${GBA_SRC}
631		${GBA_CHEATS_SRC}
632		${GBA_RENDERER_SRC})
633	list(APPEND DEBUGGER_SRC
634		${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/cli-debugger.c
635		${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/debugger.c
636		${CMAKE_CURRENT_SOURCE_DIR}/src/arm/debugger/memory-debugger.c
637		${CMAKE_CURRENT_SOURCE_DIR}/src/gba/debugger/cli.c)
638	list(APPEND TEST_SRC
639		${ARM_TEST_SRC}
640		${GBA_TEST_SRC})
641	if(NOT M_CORE_GB)
642		list(APPEND CORE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/gb/audio.c)
643	endif()
644endif()
645
646if(USE_DEBUGGERS)
647	list(APPEND FEATURE_SRC ${DEBUGGER_SRC})
648	list(APPEND FEATURES DEBUGGERS)
649endif()
650
651foreach(FEATURE IN LISTS FEATURES)
652	list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
653endforeach()
654
655foreach(ENABLE IN LISTS ENABLES)
656	list(APPEND FEATURE_DEFINES "ENABLE_${ENABLE}")
657endforeach()
658
659source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
660source_group("Extra features" FILES ${FEATURE_SRC})
661source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
662
663# Platform binaries
664if(DEFINED 3DS)
665	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/3ds ${CMAKE_CURRENT_BINARY_DIR}/3ds)
666endif()
667
668if(DEFINED WII)
669	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/wii ${CMAKE_CURRENT_BINARY_DIR}/wii)
670endif()
671
672if(DEFINED PSP2)
673	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/psp2 ${CMAKE_CURRENT_BINARY_DIR}/psp2)
674endif()
675
676# Binaries
677list(APPEND CORE_SRC
678	${UTIL_SRC}
679	${CORE_VFS_SRC}
680	${OS_SRC}
681	${THIRD_PARTY_SRC})
682list(APPEND TEST_SRC ${UTIL_TEST_SRC})
683
684set(SRC ${CORE_SRC} ${VFS_SRC})
685if(NOT MINIMAL_CORE)
686	set(ENABLE_EXTRA ON)
687	if(M_CORE_GBA)
688		list(APPEND SRC
689			${GBA_SIO_SRC})
690	endif()
691	if(M_CORE_GB)
692		list(APPEND SRC
693			${GB_SIO_SRC})
694	endif()
695	list(APPEND SRC
696		${FEATURE_SRC})
697endif()
698
699if(ENABLE_EXTRA)
700	if(M_CORE_GBA)
701		list(APPEND SRC
702			${GBA_RR_SRC}
703			${GBA_EXTRA_SRC})
704	endif()
705	if(M_CORE_GB)
706		list(APPEND SRC
707			${GB_EXTRA_SRC})
708	endif()
709	list(APPEND SRC
710		${EXTRA_SRC})
711endif()
712
713if(NOT SKIP_LIBRARY)
714	if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
715		set(BUILD_SHARED ON)
716	endif()
717
718	if(BUILD_SHARED)
719		add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
720		if(BUILD_STATIC)
721			add_library(${BINARY_NAME}-static STATIC ${SRC})
722			set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
723			install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
724			add_dependencies(${BINARY_NAME}-static version-info)
725		endif()
726	else()
727		add_library(${BINARY_NAME} STATIC ${SRC})
728	endif()
729
730	add_dependencies(${BINARY_NAME} version-info)
731	set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
732
733	target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
734	install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
735	if(UNIX AND NOT APPLE AND NOT HAIKU)
736		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
737		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
738		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
739		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
740		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
741		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
742		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
743		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
744		install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
745	endif()
746else()
747	set(BUILD_SHARED OFF)
748	set(BUILD_STATIC OFF)
749	find_library(${BINARY_NAME} ${BINARY_NAME})
750	if(NOT ${BINARY_NAME}_FOUND)
751		set(DISABLE_FRONTENDS ON)
752		set(BUILD_PERF OFF)
753		set(BUILD_TEST OFF)
754		set(BUILD_SUITE OFF)
755	endif()
756endif()
757
758if(BUILD_GL)
759	add_definitions(-DBUILD_GL)
760endif()
761
762if(BUILD_GLES2)
763	add_definitions(-DBUILD_GLES2)
764endif()
765
766if(DISABLE_FRONTENDS)
767	set(BUILD_SDL OFF)
768	set(BUILD_QT OFF)
769endif()
770
771if(BUILD_LIBRETRO)
772	file(GLOB RETRO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/libretro/*.c)
773	add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
774	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")
775	target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
776	install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBRETRO_LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
777endif()
778
779if(BUILD_OPENEMU)
780	find_library(FOUNDATION Foundation)
781	find_library(OPENEMUBASE OpenEmuBase)
782	file(GLOB OE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/*.m)
783	add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OE_SRC})
784	set_target_properties(${BINARY_NAME}-openemu PROPERTIES
785		MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/openemu/Info.plist.in
786		BUNDLE TRUE
787		BUNDLE_EXTENSION oecoreplugin
788		OUTPUT_NAME ${PROJECT_NAME}
789		COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
790	target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
791	install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${OE_LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
792endif()
793
794if(BUILD_SDL)
795	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/sdl ${CMAKE_CURRENT_BINARY_DIR}/sdl)
796	# The SDL platform CMakeLists could decide to disable SDL, so check again before adding the define.
797	if(BUILD_SDL)
798		add_definitions(-DBUILD_SDL)
799	endif()
800endif()
801
802if(BUILD_QT)
803	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt)
804endif()
805
806if(BUILD_PERF)
807	set(PERF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/perf-main.c)
808	if(UNIX AND NOT APPLE)
809		list(APPEND PERF_LIB rt)
810	endif()
811
812	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
813	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB} ${OS_LIB})
814	set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
815	install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
816	install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
817endif()
818
819if(BUILD_TEST)
820	add_executable(${BINARY_NAME}-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/fuzz-main.c)
821	target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
822	set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
823	add_executable(tbl-fuzz ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/tbl-fuzz-main.c)
824	target_link_libraries(tbl-fuzz ${BINARY_NAME})
825	set_target_properties(tbl-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
826	install(TARGETS ${BINARY_NAME}-fuzz tbl-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
827endif()
828
829if(NOT USE_CMOCKA)
830	set(BUILD_SUITE OFF)
831endif()
832if(BUILD_SUITE)
833	enable_testing()
834	include_directories(AFTER ${CMOCKA_INCLUDE_DIRS})
835	link_directories(${CMOCKA_LIBRARY_DIRS})
836
837	add_executable(${BINARY_NAME}-suite ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/test/suite-main.c ${TEST_SRC})
838	target_link_libraries(${BINARY_NAME}-suite ${BINARY_NAME} ${PLATFORM_LIBRARY} cmocka)
839	set_target_properties(${BINARY_NAME}-suite PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
840	add_test(${BINARY_NAME}-suite ${BINARY_NAME}-suite)
841endif()
842
843if(BUILD_PYTHON)
844	enable_testing()
845	add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/python ${CMAKE_CURRENT_BINARY_DIR}/python)
846endif()
847
848if(BUILD_EXAMPLE)
849	add_executable(${BINARY_NAME}-example-server ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/server.c)
850	target_link_libraries(${BINARY_NAME}-example-server ${BINARY_NAME})
851	set_target_properties(${BINARY_NAME}-example-server PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
852
853	if(BUILD_SDL)
854		add_executable(${BINARY_NAME}-example-client ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/example/client-server/client.c)
855		target_link_libraries(${BINARY_NAME}-example-client ${BINARY_NAME} ${SDL_LIBRARY} ${SDLMAIN_LIBRARY} ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
856		set_target_properties(${BINARY_NAME}-example-client PROPERTIES
857		                      COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}"
858		                      INCLUDE_DIRECTORIES "${SDL_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/src;${CMAKE_CURRENT_SOURCE_DIR}/include")
859	endif()
860endif()
861
862configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/core/flags.h.in ${CMAKE_CURRENT_BINARY_DIR}/flags.h)
863install(FILES ${CMAKE_CURRENT_BINARY_DIR}/flags.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mgba COMPONENT lib${BINARY_NAME})
864
865# Packaging
866set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
867set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
868set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
869set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
870set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
871set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
872
873set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
874set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
875set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
876set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
877set(CPACK_DEBIAN_PACKAGE_SECTION "games")
878
879SET(CPACK_DEB_COMPONENT_INSTALL ON)
880
881set(CPACK_STRIP_FILES ${BINARY_NAME})
882
883install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
884
885include(CPack)
886
887# Summaries
888set(SUMMARY_GL_LIST)
889if(USE_EPOXY)
890	set(SUMMARY_GL_LIST "libepoxy")
891else()
892	if(BUILD_GL)
893		list(APPEND SUMMARY_GL_LIST "OpenGL")
894	endif()
895	if(BUILD_GLES2)
896		list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
897	endif()
898endif()
899if(NOT SUMMARY_GL_LIST)
900	set(SUMMARY_GL OFF)
901else()
902	string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
903endif()
904if(USE_LIBZIP)
905	set(SUMMARY_ZIP libzip)
906elseif(USE_MINIZIP)
907	set(SUMMARY_ZIP "minizip (external)")
908elseif(USE_ZLIB)
909	set(SUMMARY_ZIP "minizip (included)")
910else()
911	set(SUMMARY_ZIP OFF)
912endif()
913
914if(NOT QUIET)
915	message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
916	message(STATUS "Platforms:")
917	message(STATUS "	Game Boy Advance: ${M_CORE_GBA}")
918	message(STATUS "	Game Boy: ${M_CORE_GB}")
919	message(STATUS "Features:")
920	message(STATUS "	Debuggers: ${USE_DEBUGGERS}")
921	message(STATUS "	CLI debugger: ${USE_EDITLINE}")
922	message(STATUS "	GDB stub: ${USE_GDB_STUB}")
923	message(STATUS "	Video recording: ${USE_FFMPEG}")
924	message(STATUS "	GIF recording: ${USE_MAGICK}")
925	message(STATUS "	Screenshot/advanced savestate support: ${USE_PNG}")
926	message(STATUS "	ZIP support: ${SUMMARY_ZIP}")
927	message(STATUS "	7-Zip support: ${USE_LZMA}")
928	message(STATUS "	SQLite3 game database: ${USE_SQLITE3}")
929	message(STATUS "	OpenGL support: ${SUMMARY_GL}")
930	message(STATUS "Frontends:")
931	message(STATUS "	Qt: ${BUILD_QT}")
932	message(STATUS "	SDL (${SDL_VERSION}): ${BUILD_SDL}")
933	message(STATUS "	Profiling: ${BUILD_PERF}")
934	message(STATUS "	Test harness: ${BUILD_TEST}")
935	message(STATUS "	Test suite: ${BUILD_SUITE}")
936	message(STATUS "	Python bindings: ${BUILD_PYTHON}")
937	message(STATUS "	Examples: ${BUILD_EXAMPLE}")
938	message(STATUS "Cores:")
939	message(STATUS "	Libretro core: ${BUILD_LIBRETRO}")
940	if(APPLE)
941		message(STATUS "	OpenEmu core: ${BUILD_OPENEMU}")
942	endif()
943	message(STATUS "Libraries:")
944	message(STATUS "	Static: ${BUILD_STATIC}")
945	message(STATUS "	Shared: ${BUILD_SHARED}")
946endif()