all repos — mgba @ 3b61005f2e8daead50352a1abba4160cdb2784c1

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 -std=c99")
  6else()
  7	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS /wd4003 /wd4244 /wd4146")
  8endif()
  9set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger")
 10set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger")
 11set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support")
 12set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
 13set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable ZIP support")
 14set(USE_MAGICK ON CACHE BOOL "Whether or not to enable ImageMagick support")
 15set(USE_BLIP ON CACHE BOOL "Whether or not to enable blip_buf support")
 16set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
 17set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
 18set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
 19set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
 20set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
 21set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
 22set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
 23set(BUILD_GL ON CACHE STRING "Build with OpenGL")
 24set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2")
 25file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
 26file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
 27file(GLOB GBA_CHEATS_SRC ${CMAKE_SOURCE_DIR}/src/gba/cheats/*.c)
 28file(GLOB GBA_RR_SRC ${CMAKE_SOURCE_DIR}/src/gba/rr/*.c)
 29file(GLOB GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/*.c)
 30file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs])
 31file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c)
 32file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
 33file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c)
 34list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
 35set(VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c)
 36source_group("ARM core" FILES ${ARM_SRC})
 37source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC} ${SIO_SRC})
 38source_group("GBA supervisor" FILES ${GBA_CHEATS_SRC} ${GBA_SV_SRC} ${GBA_RR_SRC})
 39source_group("Utilities" FILES ${UTIL_SRC})
 40include_directories(${CMAKE_SOURCE_DIR}/src/arm)
 41include_directories(${CMAKE_SOURCE_DIR}/src)
 42
 43if(NOT CMAKE_BUILD_TYPE)
 44	set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE)
 45endif()
 46
 47set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
 48
 49include(GNUInstallDirs)
 50
 51if (NOT DEFINED LIBDIR)
 52	set(LIBDIR "lib")
 53endif()
 54
 55if (NOT DEFINED MANDIR)
 56	set(MANDIR ${CMAKE_INSTALL_MANDIR})
 57endif()
 58
 59# Function definitions
 60include(FindPkgConfig)
 61function(find_feature FEATURE_NAME FEATURE_REQUIRES)
 62	if (NOT ${FEATURE_NAME})
 63		return()
 64	endif()
 65	foreach(REQUIRE ${FEATURE_REQUIRES})
 66		if(NOT ${REQUIRE}_FOUND)
 67			find_package(${REQUIRE} QUIET)
 68			if(NOT ${REQUIRE}_FOUND)
 69				pkg_search_module(${REQUIRE} ${REQUIRE})
 70				if (NOT ${REQUIRE}_FOUND)
 71					message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
 72					set(${FEATURE_NAME} OFF PARENT_SCOPE)
 73					return()
 74				endif()
 75			endif()
 76		endif()
 77		string(TOUPPER ${REQUIRE} UREQUIRE)
 78		set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
 79		set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
 80		set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
 81		set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
 82		set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
 83		set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
 84	endforeach()
 85endfunction()
 86
 87# Version information
 88add_custom_target(version-info ALL ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
 89	COMMAND ${CMAKE_COMMAND}
 90	-DBINARY_NAME=${BINARY_NAME}
 91	-DCONFIG_FILE=${CMAKE_SOURCE_DIR}/src/util/version.c.in
 92	-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.c
 93	-P ${CMAKE_SOURCE_DIR}/version.cmake
 94	WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 95
 96include(${CMAKE_SOURCE_DIR}/version.cmake)
 97configure_file(${CMAKE_SOURCE_DIR}/src/util/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
 98list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
 99source_group("Generated sources" FILES ${CMAKE_BINARY_DIR}/version.c)
100
101# Advanced settings
102set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
103set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
104set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
105set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
106mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
107set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR} -fprofile-arcs")
108set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
109
110if(BUILD_PGO AND NOT PGO_STAGE_2)
111	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
112	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
113	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
114elseif(BUILD_PGO AND PGO_STAGE_2)
115	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
116	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
117	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
118endif()
119
120# Feature dependencies
121set(FEATURES)
122if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
123	set(LIBEDIT_LIBRARIES -ledit)
124	if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
125		list(APPEND LIBEDIT_LIBRARIES -ltermcap)
126	endif()
127else()
128	find_feature(USE_CLI_DEBUGGER "libedit")
129endif()
130if(BUILD_GL)
131	find_package(OpenGL QUIET)
132	if(NOT OPENGL_FOUND)
133		set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
134	endif()
135endif()
136if(BUILD_GLES2 AND NOT BUILD_RASPI)
137	find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
138	find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
139	if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
140		set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
141	endif()
142endif()
143find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
144find_feature(USE_PNG "ZLIB;PNG")
145find_feature(USE_LIBZIP "libzip")
146find_feature(USE_MAGICK "MagickWand")
147
148# Platform support
149if(WIN32)
150	set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
151	add_definitions(-D_WIN32_WINNT=0x0600)
152	list(APPEND OS_LIB ws2_32 shlwapi)
153	list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
154	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
155	source_group("Windows-specific code" FILES ${OS_SRC})
156elseif(UNIX)
157	add_definitions(-DUSE_PTHREADS)
158
159	if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
160		add_definitions(-D_GNU_SOURCE)
161	endif()
162	if(NOT APPLE AND NOT HAIKU)
163		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
164	endif()
165
166	list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
167	file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
168	source_group("POSIX-specific code" FILES ${OS_SRC})
169endif()
170
171if(APPLE)
172	add_definitions(-D_DARWIN_C_SOURCE)
173	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
174endif()
175
176if(NOT HAIKU AND NOT MSVC)
177	list(APPEND OS_LIB m)
178endif()
179
180if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
181	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
182	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
183endif()
184
185if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
186	if(NOT BUILD_EGL)
187		add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
188	endif()
189endif()
190
191if(BUILD_RASPI)
192	set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
193endif()
194
195if(BUILD_PANDORA)
196	add_definitions(-DBUILD_PANDORA)
197endif()
198
199if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
200	enable_language(ASM)
201endif()
202
203include(CheckFunctionExists)
204check_function_exists(strdup HAVE_STRDUP)
205check_function_exists(strndup HAVE_STRNDUP)
206check_function_exists(snprintf_l HAVE_SNPRINTF_L)
207if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
208	# The strtof_l on Linux not actually exposed nor actually strtof_l
209	set(HAVE_STRTOF_L OFF)
210else()
211	check_function_exists(strtof_l HAVE_STRTOF_L)
212endif()
213check_function_exists(newlocale HAVE_NEWLOCALE)
214check_function_exists(freelocale HAVE_FREELOCALE)
215check_function_exists(uselocale HAVE_USELOCALE)
216check_function_exists(setlocale HAVE_SETLOCALE)
217
218if(HAVE_STRDUP)
219	add_definitions(-DHAVE_STRDUP)
220endif()
221
222if(HAVE_STRNDUP)
223	add_definitions(-DHAVE_STRNDUP)
224endif()
225
226if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
227	add_definitions(-DHAVE_LOCALE)
228	if (HAVE_STRTOF_L)
229		add_definitions(-DHAVE_STRTOF_L)
230	endif()
231	if (HAVE_SNPRINTF_L)
232		add_definitions(-DHAVE_SNPRINTF_L)
233	endif()
234endif()
235
236if(HAVE_SETLOCALE)
237	add_definitions(-DHAVE_SETLOCALE)
238endif()
239
240# Features
241set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
242set(FEATURE_SRC)
243set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
244
245if(USE_CLI_DEBUGGER)
246	list(APPEND FEATURES CLI_DEBUGGER)
247	list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
248	list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
249	list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
250	include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
251	link_directories(${LIBEDIT_LIBRARY_DIRS})
252	set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
253	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
254else()
255	set(DEBUGGER_LIB "")
256endif()
257
258if(USE_GDB_STUB)
259	list(APPEND FEATURES GDB_STUB)
260	list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
261endif()
262source_group("ARM debugger" FILES ${DEBUGGER_SRC})
263
264if(USE_FFMPEG)
265	list(APPEND FEATURES FFMPEG)
266	pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
267	if(NOT LIBSWRESAMPLE_FOUND)
268		list(APPEND FEATURES LIBAV)
269	endif()
270	include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
271	link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
272	list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
273	string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
274	string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
275	string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
276	string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
277	string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
278	list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
279	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR},libavformat${LIBAVFORMAT_VERSION_MAJOR},libavresample${LIBAVRESAMPLE_VERSION_MAJOR},libavutil${LIBAVUTIL_VERSION_MAJOR},libswscale${LIBSWSCALE_VERSION_MAJOR}")
280	set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
281	if(APPLE)
282		set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
283		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
284	endif()
285endif()
286
287if(USE_BLIP)
288	list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
289	add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
290else()
291	add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
292endif()
293
294if(USE_MAGICK)
295	list(APPEND FEATURES MAGICK)
296	include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
297	link_directories(${MAGICKWAND_LIBRARY_DIRS})
298	list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
299	list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
300	string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
301	if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
302		set(MAGICKWAND_DEB_VERSION "5")
303	else()
304		set(MAGICKWAND_DEB_VERSION "-6.q16-2")
305	endif()
306	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
307endif()
308
309if(USE_PNG)
310	list(APPEND FEATURES PNG)
311	include_directories(AFTER ${PNG_INCLUDE_DIRS})
312	list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
313	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0,zlib1g")
314endif()
315
316if(USE_LIBZIP)
317	include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
318	link_directories(${LIBZIP_LIBRARY_DIRS})
319	list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
320	list(APPEND FEATURES LIBZIP)
321	list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
322	set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
323endif()
324
325if (USE_LZMA)
326	include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
327	add_definitions(-D_7ZIP_PPMD_SUPPPORT)
328	list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
329	set(LZMA_SRC
330		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
331		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
332		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
333		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
334		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
335		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
336		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
337		${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
338		${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
339		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
340		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
341		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
342		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
343		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
344		${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
345		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
346		${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
347	list(APPEND FEATURE_SRC ${LZMA_SRC})
348	list(APPEND FEATURES LZMA)
349endif()
350
351set(FEATURE_DEFINES)
352foreach(FEATURE IN LISTS FEATURES)
353	list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
354endforeach()
355
356source_group("Virtual files" FILES ${VFS_SRC})
357source_group("Extra features" FILES ${FEATURE_SRC})
358source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
359
360# Binaries
361set(CORE_SRC
362	${ARM_SRC}
363	${GBA_SRC}
364	${GBA_CHEATS_SRC}
365	${GBA_RR_SRC}
366	${GBA_SV_SRC}
367	${DEBUGGER_SRC}
368	${RENDERER_SRC}
369	${SIO_SRC}
370	${UTIL_SRC}
371	${VFS_SRC}
372	${OS_SRC}
373	${THIRD_PARTY_SRC})
374
375set(SRC
376	${CORE_SRC}
377	${FEATURE_SRC})
378
379if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
380	set(BUILD_SHARED ON)
381endif()
382
383if(BUILD_SHARED)
384	add_library(${BINARY_NAME} SHARED ${SRC})
385	set_target_properties(${BINARY_NAME} PROPERTIES SOVERSION ${LIB_VERSION_ABI})
386	if(BUILD_STATIC)
387		add_library(${BINARY_NAME}-static STATIC ${SRC})
388		set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
389		install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
390		add_dependencies(${BINARY_NAME}-static version-info)
391	endif()
392else()
393	add_library(${BINARY_NAME} STATIC ${SRC})
394endif()
395
396add_dependencies(${BINARY_NAME} version-info)
397
398target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
399install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
400if(UNIX AND NOT APPLE)
401	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
402	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
403	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
404	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
405	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
406	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
407	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
408	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
409	install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
410endif()
411set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
412
413if(BUILD_GL)
414	add_definitions(-DBUILD_GL)
415endif()
416
417if(BUILD_GLES2)
418	add_definitions(-DBUILD_GLES2)
419endif()
420
421if(BUILD_LIBRETRO)
422	file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
423	add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
424	set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5")
425	target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
426endif()
427
428if(BUILD_SDL)
429	add_definitions(-DBUILD_SDL)
430	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
431endif()
432
433if(BUILD_QT)
434	add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
435endif()
436
437if(BUILD_PERF)
438	set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
439	if(UNIX AND NOT APPLE)
440		list(APPEND PERF_LIB rt)
441	endif()
442
443	add_executable(${BINARY_NAME}-perf ${PERF_SRC})
444	target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
445	install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
446	install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
447endif()
448
449# Packaging
450set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
451set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
452set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
453set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
454set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
455set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
456
457set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
458set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
459set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
460set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
461set(CPACK_DEBIAN_PACKAGE_SECTION "games")
462
463SET(CPACK_DEB_COMPONENT_INSTALL ON)
464
465set(CPACK_STRIP_FILES ${BINARY_NAME})
466
467install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
468
469include(CPack)
470
471# Summaries
472message(STATUS "Feature summary:")
473message(STATUS "	CLI debugger: ${USE_CLI_DEBUGGER}")
474message(STATUS "	GDB stub: ${USE_GDB_STUB}")
475message(STATUS "	Video recording: ${USE_FFMPEG}")
476message(STATUS "	GIF recording: ${USE_MAGICK}")
477message(STATUS "	Screenshot/advanced savestate support: ${USE_PNG}")
478message(STATUS "	ZIP support: ${USE_LIBZIP}")
479message(STATUS "	7-Zip support: ${USE_LZMA}")
480message(STATUS "	Better audio resampling: ${USE_BLIP}")
481message(STATUS "Frontend summary:")
482message(STATUS "	Qt: ${BUILD_QT}")
483message(STATUS "	SDL (${SDL_VERSION}): ${BUILD_SDL}")
484message(STATUS "	Libretro core: ${BUILD_LIBRETRO}")
485message(STATUS "	Profiling: ${BUILD_PERF}")
486message(STATUS "Library summary:")
487message(STATUS "	Static: ${BUILD_STATIC}")
488message(STATUS "	Shared: ${BUILD_SHARED}")