all repos — mgba @ 63d7927b60565c68fc0913d4b67f2c5813027f25

mGBA Game Boy Advance Emulator

CMakeLists.txt (view raw)

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