all repos — mgba @ ade940257846eeed35116398849499acc0e1043f

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