CMakeLists.txt (view raw)
1cmake_minimum_required(VERSION 2.6)
2project(mGBA C)
3set(BINARY_NAME mgba CACHE INTERNAL "Name of output binaries")
4set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99")
5set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger")
6set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger")
7set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support")
8set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
9set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable ZIP support")
10set(USE_MAGICK ON CACHE BOOL "Whether or not to enable ImageMagick support")
11set(USE_BLIP ON CACHE BOOL "Whether or not to enable blip_buf support")
12set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
13set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
14set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
15set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
16set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
17set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
18set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
19file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
20file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
21file(GLOB GBA_CHEATS_SRC ${CMAKE_SOURCE_DIR}/src/gba/cheats/*.c)
22file(GLOB GBA_RR_SRC ${CMAKE_SOURCE_DIR}/src/gba/rr/*.c)
23file(GLOB GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/*.c)
24file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs])
25file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/video-software.c)
26file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
27file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c)
28list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
29set(VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c)
30source_group("ARM core" FILES ${ARM_SRC})
31source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC} ${SIO_SRC})
32source_group("GBA supervisor" FILES ${GBA_CHEATS_SRC} ${GBA_SV_SRC} ${GBA_RR_SRC})
33source_group("Utilities" FILES ${UTIL_SRC})
34include_directories(${CMAKE_SOURCE_DIR}/src/arm)
35include_directories(${CMAKE_SOURCE_DIR}/src)
36
37if(NOT CMAKE_BUILD_TYPE)
38 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE)
39endif()
40
41set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
42
43include(GNUInstallDirs)
44
45# Function definitions
46include(FindPkgConfig)
47function(find_feature FEATURE_NAME FEATURE_REQUIRES)
48 if (NOT ${FEATURE_NAME})
49 return()
50 endif()
51 foreach(REQUIRE ${FEATURE_REQUIRES})
52 if(NOT ${REQUIRE}_FOUND)
53 find_package(${REQUIRE} QUIET)
54 if(NOT ${REQUIRE}_FOUND)
55 pkg_search_module(${REQUIRE} ${REQUIRE})
56 if (NOT ${REQUIRE}_FOUND)
57 message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
58 set(${FEATURE_NAME} OFF PARENT_SCOPE)
59 return()
60 endif()
61 endif()
62 endif()
63 string(TOUPPER ${REQUIRE} UREQUIRE)
64 set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
65 set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
66 set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
67 set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
68 set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
69 set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
70 endforeach()
71endfunction()
72
73# Version information
74set(LIB_VERSION_MAJOR 0)
75set(LIB_VERSION_MINOR 3)
76set(LIB_VERSION_PATCH 0)
77set(LIB_VERSION_ABI 0.3)
78set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
79
80execute_process(COMMAND git describe --always --abbrev=40 --dirty OUTPUT_VARIABLE GIT_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
81execute_process(COMMAND git describe --always --dirty OUTPUT_VARIABLE GIT_COMMIT_SHORT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
82execute_process(COMMAND git symbolic-ref --short HEAD OUTPUT_VARIABLE GIT_BRANCH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
83execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE GIT_REV ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
84execute_process(COMMAND git describe --tag --exact-match OUTPUT_VARIABLE GIT_TAG ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
85
86if(GIT_REV STREQUAL "")
87 set(GIT_REV -1)
88endif()
89if(NOT GIT_TAG STREQUAL "")
90 set(VERSION_STRING ${GIT_TAG})
91elseif(GIT_BRANCH STREQUAL "")
92 set(VERSION_STRING ${LIB_VERSION_STRING})
93else()
94 if(GIT_BRANCH STREQUAL "master")
95 set(VERSION_STRING ${GIT_REV}-${GIT_COMMIT_SHORT})
96 else()
97 set(VERSION_STRING ${GIT_BRANCH}-${GIT_REV}-${GIT_COMMIT_SHORT})
98 endif()
99
100 if(NOT LIB_VERSION_ABI STREQUAL GIT_BRANCH)
101 set(VERSION_STRING ${LIB_VERSION_ABI}-${VERSION_STRING})
102 endif()
103endif()
104
105add_custom_target(version-info ALL touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
106 COMMAND ${CMAKE_COMMAND}
107 -DGIT_COMMIT=${GIT_COMMIT}
108 -DGIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
109 -DGIT_BRANCH=${GIT_BRANCH}
110 -DGIT_REV=${GIT_REV}
111 -DBINARY_NAME=${BINARY_NAME}
112 -DPROJECT_NAME=${PROJECT_NAME}
113 -DVERSION_STRING=${VERSION_STRING}
114 -D${BINARY_NAME}_SOURCE_DIR=${CMAKE_SOURCE_DIR}
115 -P ${CMAKE_SOURCE_DIR}/version.cmake
116 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
117
118include(${CMAKE_SOURCE_DIR}/version.cmake)
119list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
120
121# Advanced settings
122set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
123set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
124set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
125set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
126mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
127set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR} -fprofile-arcs")
128set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
129
130if(BUILD_PGO AND NOT PGO_STAGE_2)
131 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
132 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
133 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
134elseif(BUILD_PGO AND PGO_STAGE_2)
135 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
136 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
137 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
138endif()
139
140# Feature dependencies
141set(FEATURES)
142if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
143 set(LIBEDIT_LIBRARIES -ledit)
144 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
145 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
146 endif()
147else()
148 find_feature(USE_CLI_DEBUGGER "libedit")
149endif()
150find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
151find_feature(USE_PNG "ZLIB;PNG")
152find_feature(USE_LIBZIP "libzip")
153find_feature(USE_MAGICK "MagickWand")
154
155# Platform support
156if(WIN32)
157 set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
158 add_definitions(-D_WIN32_WINNT=0x0600)
159 list(APPEND OS_LIB ws2_32)
160 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
161 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
162 source_group("Windows-specific code" FILES ${OS_SRC})
163elseif(UNIX)
164 add_definitions(-DUSE_PTHREADS)
165
166 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
167 add_definitions(-D_BSD_SOURCE -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200809L)
168 endif()
169 if(NOT APPLE AND NOT HAIKU)
170 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
171 endif()
172
173 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
174 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
175 source_group("POSIX-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)
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_PANDORA)
199 add_definitions(-DBUILD_PANDORA)
200endif()
201
202if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
203 enable_language(ASM)
204endif()
205
206include(CheckFunctionExists)
207check_function_exists(strndup HAVE_STRNDUP)
208check_function_exists(snprintf_l HAVE_SNPRINTF_L)
209if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
210 # The strtof_l on Linux not actually exposed nor actually strtof_l
211 set(HAVE_STRTOF_L OFF)
212else()
213 check_function_exists(strtof_l HAVE_STRTOF_L)
214endif()
215check_function_exists(newlocale HAVE_NEWLOCALE)
216check_function_exists(freelocale HAVE_FREELOCALE)
217check_function_exists(uselocale HAVE_USELOCALE)
218
219if(HAVE_STRNDUP)
220 add_definitions(-DHAVE_STRNDUP)
221endif()
222
223if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
224 add_definitions(-DHAVE_LOCALE)
225 if (HAVE_STRTOF_L)
226 add_definitions(-DHAVE_STRTOF_L)
227 endif()
228 if (HAVE_SNPRINTF_L)
229 add_definitions(-DHAVE_SNPRINTF_L)
230 endif()
231endif()
232
233
234# Features
235set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
236set(FEATURE_SRC)
237set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
238
239if(USE_CLI_DEBUGGER)
240 list(APPEND FEATURES CLI_DEBUGGER)
241 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
242 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
243 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
244 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
245 link_directories(${LIBEDIT_LIBRARY_DIRS})
246 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
247 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
248else()
249 set(DEBUGGER_LIB "")
250endif()
251
252if(USE_GDB_STUB)
253 list(APPEND FEATURES GDB_STUB)
254 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
255endif()
256source_group("ARM debugger" FILES ${DEBUGGER_SRC})
257
258if(USE_FFMPEG)
259 list(APPEND FEATURES FFMPEG)
260 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
261 if(NOT LIBSWRESAMPLE_FOUND)
262 list(APPEND FEATURES LIBAV)
263 endif()
264 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
265 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
266 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
267 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
268 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
269 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
270 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
271 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
272 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
273 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}")
274 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
275 if(APPLE)
276 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
277 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
278 endif()
279endif()
280
281if(USE_BLIP)
282 list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
283 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
284else()
285 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
286endif()
287
288if(USE_MAGICK)
289 list(APPEND FEATURES MAGICK)
290 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
291 link_directories(${MAGICKWAND_LIBRARY_DIRS})
292 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
293 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
294 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
295 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
296 set(MAGICKWAND_DEB_VERSION "5")
297 else()
298 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
299 endif()
300 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
301endif()
302
303if(USE_PNG)
304 list(APPEND FEATURES PNG)
305 include_directories(AFTER ${PNG_INCLUDE_DIRS})
306 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
307 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0,zlib1g")
308endif()
309
310if(USE_LIBZIP)
311 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
312 link_directories(${LIBZIP_LIBRARY_DIRS})
313 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
314 list(APPEND FEATURES LIBZIP)
315 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
316 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
317endif()
318
319if (USE_LZMA)
320 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
321 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
322 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
323 set(LZMA_SRC
324 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
325 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
326 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
327 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
328 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
329 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
330 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
331 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
332 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
333 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
334 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
335 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
336 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
337 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
338 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
339 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
340 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
341 list(APPEND FEATURE_SRC ${LZMA_SRC})
342 list(APPEND FEATURES LZMA)
343endif()
344
345set(FEATURE_DEFINES)
346foreach(FEATURE IN LISTS FEATURES)
347 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
348endforeach()
349
350# Binaries
351set(CORE_SRC
352 ${ARM_SRC}
353 ${GBA_SRC}
354 ${GBA_CHEATS_SRC}
355 ${GBA_RR_SRC}
356 ${GBA_SV_SRC}
357 ${DEBUGGER_SRC}
358 ${RENDERER_SRC}
359 ${SIO_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 lib 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 lib 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_LIBRETRO)
403 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
404 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
405 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5")
406 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
407endif()
408
409if(BUILD_SDL)
410 add_definitions(-DBUILD_SDL)
411 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
412endif()
413
414if(BUILD_QT)
415 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
416endif()
417
418if(BUILD_PERF)
419 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
420 if(UNIX AND NOT APPLE)
421 list(APPEND PERF_LIB rt)
422 endif()
423
424 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
425 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
426 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
427 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
428endif()
429
430# Packaging
431set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
432set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
433set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
434set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
435set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
436set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
437
438set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
439set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
440set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
441set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
442set(CPACK_DEBIAN_PACKAGE_SECTION "games")
443
444SET(CPACK_DEB_COMPONENT_INSTALL ON)
445
446set(CPACK_STRIP_FILES ${BINARY_NAME})
447
448install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
449
450include(CPack)
451
452# Summaries
453message(STATUS "Feature summary:")
454message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
455message(STATUS " GDB stub: ${USE_GDB_STUB}")
456message(STATUS " Video recording: ${USE_FFMPEG}")
457message(STATUS " GIF recording: ${USE_MAGICK}")
458message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
459message(STATUS " ZIP support: ${USE_LIBZIP}")
460message(STATUS " 7-Zip support: ${USE_LZMA}")
461message(STATUS " Better audio resampling: ${USE_BLIP}")
462message(STATUS "Frontend summary:")
463message(STATUS " Qt: ${BUILD_QT}")
464message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
465message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
466message(STATUS " Profiling: ${BUILD_PERF}")
467message(STATUS "Library summary:")
468message(STATUS " Static: ${BUILD_STATIC}")
469message(STATUS " Shared: ${BUILD_SHARED}")