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_ZLIB ON CACHE BOOL "Whether or not to enable zlib support")
13set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
14set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable ZIP support")
15set(USE_MAGICK ON CACHE BOOL "Whether or not to enable ImageMagick support")
16set(USE_BLIP ON CACHE BOOL "Whether or not to enable blip_buf support")
17set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
18set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
19set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
20set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
21set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
22set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
23set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
24set(BUILD_GL ON CACHE STRING "Build with OpenGL")
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
47set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
48
49include(GNUInstallDirs)
50
51# Function definitions
52include(FindPkgConfig)
53function(find_feature FEATURE_NAME FEATURE_REQUIRES)
54 if (NOT ${FEATURE_NAME})
55 return()
56 endif()
57 foreach(REQUIRE ${FEATURE_REQUIRES})
58 if(NOT ${REQUIRE}_FOUND)
59 find_package(${REQUIRE} QUIET)
60 if(NOT ${REQUIRE}_FOUND)
61 pkg_search_module(${REQUIRE} ${REQUIRE})
62 if (NOT ${REQUIRE}_FOUND)
63 message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
64 set(${FEATURE_NAME} OFF PARENT_SCOPE)
65 return()
66 endif()
67 endif()
68 endif()
69 string(TOUPPER ${REQUIRE} UREQUIRE)
70 set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
71 set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
72 set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
73 set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
74 set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
75 set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
76 endforeach()
77endfunction()
78
79# Version information
80set(LIB_VERSION_MAJOR 0)
81set(LIB_VERSION_MINOR 3)
82set(LIB_VERSION_PATCH 0)
83set(LIB_VERSION_ABI 0.3)
84set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
85
86execute_process(COMMAND git describe --always --abbrev=40 --dirty OUTPUT_VARIABLE GIT_COMMIT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
87execute_process(COMMAND git describe --always --dirty OUTPUT_VARIABLE GIT_COMMIT_SHORT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
88execute_process(COMMAND git symbolic-ref --short HEAD OUTPUT_VARIABLE GIT_BRANCH ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
89execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE GIT_REV ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
90execute_process(COMMAND git describe --tag --exact-match OUTPUT_VARIABLE GIT_TAG ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
91
92if(GIT_REV STREQUAL "")
93 set(GIT_REV -1)
94endif()
95if(NOT GIT_TAG STREQUAL "")
96 set(VERSION_STRING ${GIT_TAG})
97elseif(GIT_BRANCH STREQUAL "")
98 set(VERSION_STRING ${LIB_VERSION_STRING})
99else()
100 if(GIT_BRANCH STREQUAL "master")
101 set(VERSION_STRING ${GIT_REV}-${GIT_COMMIT_SHORT})
102 else()
103 set(VERSION_STRING ${GIT_BRANCH}-${GIT_REV}-${GIT_COMMIT_SHORT})
104 endif()
105
106 if(NOT LIB_VERSION_ABI STREQUAL GIT_BRANCH)
107 set(VERSION_STRING ${LIB_VERSION_ABI}-${VERSION_STRING})
108 endif()
109endif()
110
111add_custom_target(version-info ALL ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
112 COMMAND ${CMAKE_COMMAND}
113 -DGIT_COMMIT=${GIT_COMMIT}
114 -DGIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
115 -DGIT_BRANCH=${GIT_BRANCH}
116 -DGIT_REV=${GIT_REV}
117 -DBINARY_NAME=${BINARY_NAME}
118 -DPROJECT_NAME=${PROJECT_NAME}
119 -DVERSION_STRING=${VERSION_STRING}
120 -D${BINARY_NAME}_SOURCE_DIR=${CMAKE_SOURCE_DIR}
121 -P ${CMAKE_SOURCE_DIR}/version.cmake
122 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
123
124include(${CMAKE_SOURCE_DIR}/version.cmake)
125list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
126source_group("Generated sources" FILES ${CMAKE_BINARY_DIR}/version.c)
127
128# Advanced settings
129set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
130set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
131set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
132set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
133mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
134set(PGO_PRE_FLAGS "-pg -fprofile-generate=${PGO_DIR} -fprofile-arcs")
135set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
136
137if(BUILD_PGO AND NOT PGO_STAGE_2)
138 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
139 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
140 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
141elseif(BUILD_PGO AND PGO_STAGE_2)
142 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
143 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
144 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
145endif()
146
147# Feature dependencies
148set(FEATURES)
149if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
150 set(LIBEDIT_LIBRARIES -ledit)
151 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
152 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
153 endif()
154else()
155 find_feature(USE_CLI_DEBUGGER "libedit")
156endif()
157if(BUILD_GL)
158 find_package(OpenGL QUIET)
159 if(NOT OPENGL_FOUND)
160 set(BUILD_GL OFF)
161 endif()
162endif()
163set(WANT_PNG ${USE_PNG})
164find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
165find_feature(USE_ZLIB "ZLIB")
166find_feature(USE_PNG "PNG")
167find_feature(USE_LIBZIP "libzip")
168find_feature(USE_MAGICK "MagickWand")
169
170# Platform support
171if(WIN32)
172 set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
173 add_definitions(-D_WIN32_WINNT=0x0600)
174 list(APPEND OS_LIB ws2_32 shlwapi)
175 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
176 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
177 source_group("Windows-specific code" FILES ${OS_SRC})
178elseif(UNIX)
179 add_definitions(-DUSE_PTHREADS)
180
181 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
182 add_definitions(-D_GNU_SOURCE)
183 endif()
184 if(NOT APPLE AND NOT HAIKU)
185 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
186 endif()
187
188 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
189 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
190 source_group("POSIX-specific code" FILES ${OS_SRC})
191endif()
192
193if(APPLE)
194 add_definitions(-D_DARWIN_C_SOURCE)
195 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
196endif()
197
198if(NOT HAIKU AND NOT MSVC)
199 list(APPEND OS_LIB m)
200endif()
201
202if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
203 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
204 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
205endif()
206
207if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
208 if(NOT BUILD_EGL)
209 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
210 endif()
211endif()
212
213if(BUILD_PANDORA)
214 add_definitions(-DBUILD_PANDORA)
215endif()
216
217if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
218 enable_language(ASM)
219endif()
220
221include(CheckFunctionExists)
222check_function_exists(strdup HAVE_STRDUP)
223check_function_exists(strndup HAVE_STRNDUP)
224check_function_exists(snprintf_l HAVE_SNPRINTF_L)
225if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
226 # The strtof_l on Linux not actually exposed nor actually strtof_l
227 set(HAVE_STRTOF_L OFF)
228else()
229 check_function_exists(strtof_l HAVE_STRTOF_L)
230endif()
231check_function_exists(newlocale HAVE_NEWLOCALE)
232check_function_exists(freelocale HAVE_FREELOCALE)
233check_function_exists(uselocale HAVE_USELOCALE)
234check_function_exists(setlocale HAVE_SETLOCALE)
235
236if(HAVE_STRDUP)
237 add_definitions(-DHAVE_STRDUP)
238endif()
239
240if(HAVE_STRNDUP)
241 add_definitions(-DHAVE_STRNDUP)
242endif()
243
244if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
245 add_definitions(-DHAVE_LOCALE)
246 if (HAVE_STRTOF_L)
247 add_definitions(-DHAVE_STRTOF_L)
248 endif()
249 if (HAVE_SNPRINTF_L)
250 add_definitions(-DHAVE_SNPRINTF_L)
251 endif()
252endif()
253
254if(HAVE_SETLOCALE)
255 add_definitions(-DHAVE_SETLOCALE)
256endif()
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_ZLIB)
328 list(APPEND FEATURES ZLIB)
329 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
330 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
331 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
332endif()
333
334if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
335 set(PNG_STATIC ON CACHE BOOL "" FORCE)
336 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
337 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
338 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/libpng libpng)
339 set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/libpng;${CMAKE_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
340 set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/libpng ${CMAKE_BINARY_DIR}/libpng)
341 list(APPEND DEPENDENCY_LIB png16_static)
342 set(USE_PNG ON)
343endif()
344
345if(USE_PNG)
346 list(APPEND FEATURES PNG)
347 include_directories(AFTER ${PNG_INCLUDE_DIRS})
348 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
349 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
350endif()
351
352if(USE_LIBZIP)
353 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
354 link_directories(${LIBZIP_LIBRARY_DIRS})
355 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
356 list(APPEND FEATURES LIBZIP)
357 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
358 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
359endif()
360
361if (USE_LZMA)
362 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
363 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
364 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
365 set(LZMA_SRC
366 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
367 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
368 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
369 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
370 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
371 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
372 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
373 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
374 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
375 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
376 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
377 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
378 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
379 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
380 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
381 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
382 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
383 list(APPEND FEATURE_SRC ${LZMA_SRC})
384 list(APPEND FEATURES LZMA)
385endif()
386
387set(FEATURE_DEFINES)
388foreach(FEATURE IN LISTS FEATURES)
389 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
390endforeach()
391
392source_group("Virtual files" FILES ${VFS_SRC})
393source_group("Extra features" FILES ${FEATURE_SRC})
394source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
395
396# Binaries
397set(CORE_SRC
398 ${ARM_SRC}
399 ${GBA_SRC}
400 ${GBA_CHEATS_SRC}
401 ${GBA_RR_SRC}
402 ${GBA_SV_SRC}
403 ${DEBUGGER_SRC}
404 ${RENDERER_SRC}
405 ${SIO_SRC}
406 ${UTIL_SRC}
407 ${VFS_SRC}
408 ${OS_SRC}
409 ${THIRD_PARTY_SRC})
410
411set(SRC
412 ${CORE_SRC}
413 ${FEATURE_SRC})
414
415if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
416 set(BUILD_SHARED ON)
417endif()
418
419if(BUILD_SHARED)
420 message(STATUS ${DEPENDENCY_TARGETS})
421 add_library(${BINARY_NAME} SHARED ${SRC} ${DEPENDENCY_TARGETS})
422 if(BUILD_STATIC)
423 add_library(${BINARY_NAME}-static STATIC ${SRC})
424 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
425 install(TARGETS ${BINARY_NAME}-static DESTINATION lib COMPONENT lib${BINARY_NAME})
426 add_dependencies(${BINARY_NAME}-static version-info)
427 endif()
428else()
429 add_library(${BINARY_NAME} STATIC ${SRC})
430endif()
431
432add_dependencies(${BINARY_NAME} version-info)
433
434target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
435install(TARGETS ${BINARY_NAME} DESTINATION lib COMPONENT lib${BINARY_NAME})
436if(UNIX AND NOT APPLE)
437 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
438 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
439 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
440 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
441 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
442 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
443 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
444 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
445 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
446endif()
447set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
448
449if(BUILD_GL)
450 add_definitions(-DBUILD_GL)
451endif()
452
453if(BUILD_LIBRETRO)
454 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
455 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
456 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5")
457 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
458endif()
459
460if(BUILD_SDL)
461 add_definitions(-DBUILD_SDL)
462 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
463endif()
464
465if(BUILD_QT)
466 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
467endif()
468
469if(BUILD_PERF)
470 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
471 if(UNIX AND NOT APPLE)
472 list(APPEND PERF_LIB rt)
473 endif()
474
475 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
476 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
477 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
478 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
479endif()
480
481# Packaging
482set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
483set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
484set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
485set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
486set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
487set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
488
489set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
490set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
491set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
492set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
493set(CPACK_DEBIAN_PACKAGE_SECTION "games")
494
495SET(CPACK_DEB_COMPONENT_INSTALL ON)
496
497set(CPACK_STRIP_FILES ${BINARY_NAME})
498
499install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
500
501include(CPack)
502
503# Summaries
504message(STATUS "Feature summary:")
505message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
506message(STATUS " GDB stub: ${USE_GDB_STUB}")
507message(STATUS " Video recording: ${USE_FFMPEG}")
508message(STATUS " GIF recording: ${USE_MAGICK}")
509message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
510message(STATUS " ZIP support: ${USE_LIBZIP}")
511message(STATUS " 7-Zip support: ${USE_LZMA}")
512message(STATUS " Better audio resampling: ${USE_BLIP}")
513message(STATUS "Frontend summary:")
514message(STATUS " Qt: ${BUILD_QT}")
515message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
516message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
517message(STATUS " Profiling: ${BUILD_PERF}")
518message(STATUS "Library summary:")
519message(STATUS " Static: ${BUILD_STATIC}")
520message(STATUS " Shared: ${BUILD_SHARED}")