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