all repos — mgba @ 64409d9ca7b3af1e83f7fb68737935015739cd40

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