all repos — mgba @ 40333fb69c1dfae585b5c5099871b48f3efb1c40

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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