all repos — mgba @ 687af6fd2099867d2ba791e3782afa36094a8fa1

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