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