all repos — mgba @ 817f1573d3b9fcdc8dc95acdd9ee2eaf86d70af0

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