all repos — mgba @ f6e1d9d741d36532dc227b4648923af1fae464d6

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