all repos — mgba @ 7fa535380165fdb517433a65f1adec435a941950

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