all repos — mgba @ ca0fb2ede6714d31708a8d4e052f6c1a51af0ce1

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