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