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 AND NOT PSP2)
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
187if(PSP2)
188 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
189endif()
190
191include(CheckFunctionExists)
192check_function_exists(strdup HAVE_STRDUP)
193check_function_exists(strndup HAVE_STRNDUP)
194check_function_exists(snprintf_l HAVE_SNPRINTF_L)
195if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
196 # The strtof_l on Linux not actually exposed nor actually strtof_l
197 set(HAVE_STRTOF_L OFF)
198else()
199 check_function_exists(strtof_l HAVE_STRTOF_L)
200endif()
201check_function_exists(newlocale HAVE_NEWLOCALE)
202check_function_exists(freelocale HAVE_FREELOCALE)
203check_function_exists(uselocale HAVE_USELOCALE)
204check_function_exists(setlocale HAVE_SETLOCALE)
205
206if(HAVE_STRDUP)
207 add_definitions(-DHAVE_STRDUP)
208endif()
209
210if(HAVE_STRNDUP)
211 add_definitions(-DHAVE_STRNDUP)
212endif()
213
214if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
215 add_definitions(-DHAVE_LOCALE)
216 if (HAVE_STRTOF_L)
217 add_definitions(-DHAVE_STRTOF_L)
218 endif()
219 if (HAVE_SNPRINTF_L)
220 add_definitions(-DHAVE_SNPRINTF_L)
221 endif()
222endif()
223
224if(HAVE_SETLOCALE)
225 add_definitions(-DHAVE_SETLOCALE)
226endif()
227
228# Features
229set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
230set(FEATURE_SRC)
231set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
232
233if(USE_CLI_DEBUGGER)
234 list(APPEND FEATURES CLI_DEBUGGER)
235 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
236 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
237 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
238 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
239 link_directories(${LIBEDIT_LIBRARY_DIRS})
240 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
241 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
242else()
243 set(DEBUGGER_LIB "")
244endif()
245
246if(USE_GDB_STUB)
247 list(APPEND FEATURES GDB_STUB)
248 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
249endif()
250source_group("ARM debugger" FILES ${DEBUGGER_SRC})
251
252if(USE_FFMPEG)
253 list(APPEND FEATURES FFMPEG)
254 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
255 if(NOT LIBSWRESAMPLE_FOUND)
256 list(APPEND FEATURES LIBAV)
257 endif()
258 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
259 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
260 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
261 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
262 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
263 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
264 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
265 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
266 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
267 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}")
268 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
269 if(APPLE)
270 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
271 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
272 endif()
273endif()
274
275if(USE_BLIP)
276 list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
277 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
278else()
279 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
280endif()
281
282if(USE_MAGICK)
283 list(APPEND FEATURES MAGICK)
284 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
285 link_directories(${MAGICKWAND_LIBRARY_DIRS})
286 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
287 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
288 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
289 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
290 set(MAGICKWAND_DEB_VERSION "5")
291 else()
292 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
293 endif()
294 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
295endif()
296
297if(USE_PNG)
298 list(APPEND FEATURES PNG)
299 include_directories(AFTER ${PNG_INCLUDE_DIRS})
300 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
301 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0,zlib1g")
302endif()
303
304if(USE_LIBZIP)
305 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
306 link_directories(${LIBZIP_LIBRARY_DIRS})
307 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
308 list(APPEND FEATURES LIBZIP)
309 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
310 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
311endif()
312
313if (USE_LZMA)
314 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
315 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
316 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
317 set(LZMA_SRC
318 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
319 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
320 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
321 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
322 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
323 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
324 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
325 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
326 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
327 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
328 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
329 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
330 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
331 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
332 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
333 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
334 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
335 list(APPEND FEATURE_SRC ${LZMA_SRC})
336 list(APPEND FEATURES LZMA)
337endif()
338
339set(FEATURE_DEFINES)
340foreach(FEATURE IN LISTS FEATURES)
341 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
342endforeach()
343
344source_group("Virtual files" FILES ${VFS_SRC})
345source_group("Extra features" FILES ${FEATURE_SRC})
346source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
347
348# Binaries
349set(CORE_SRC
350 ${ARM_SRC}
351 ${GBA_SRC}
352 ${GBA_CHEATS_SRC}
353 ${GBA_RR_SRC}
354 ${GBA_SV_SRC}
355 ${DEBUGGER_SRC}
356 ${RENDERER_SRC}
357 ${SIO_SRC}
358 ${UTIL_SRC}
359 ${VFS_SRC}
360 ${OS_SRC}
361 ${THIRD_PARTY_SRC})
362
363set(SRC
364 ${CORE_SRC}
365 ${FEATURE_SRC})
366
367if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
368 set(BUILD_SHARED ON)
369endif()
370
371if(BUILD_SHARED)
372 add_library(${BINARY_NAME} SHARED ${SRC})
373 if(BUILD_STATIC)
374 add_library(${BINARY_NAME}-static STATIC ${SRC})
375 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
376 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
377 add_dependencies(${BINARY_NAME}-static version-info)
378 endif()
379else()
380 add_library(${BINARY_NAME} STATIC ${SRC})
381endif()
382
383add_dependencies(${BINARY_NAME} version-info)
384
385target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
386install(TARGETS ${BINARY_NAME} DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
387if(UNIX AND NOT APPLE)
388 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
389 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
390 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
391 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
392 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
393 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
394 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
395 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
396 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
397endif()
398set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
399
400if(BUILD_GL)
401 add_definitions(-DBUILD_GL)
402endif()
403
404if(BUILD_LIBRETRO)
405 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
406 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
407 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5")
408 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
409endif()
410
411if(BUILD_SDL)
412 add_definitions(-DBUILD_SDL)
413 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
414endif()
415
416if(BUILD_QT)
417 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
418endif()
419
420if(BUILD_PERF)
421 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
422 if(UNIX AND NOT APPLE)
423 list(APPEND PERF_LIB rt)
424 endif()
425
426 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
427 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
428 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
429 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
430endif()
431
432if(PSP2)
433 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
434endif()
435
436# Packaging
437set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
438set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
439set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
440set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
441set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
442set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
443
444set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
445set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
446set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
447set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
448set(CPACK_DEBIAN_PACKAGE_SECTION "games")
449
450SET(CPACK_DEB_COMPONENT_INSTALL ON)
451
452set(CPACK_STRIP_FILES ${BINARY_NAME})
453
454install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
455
456include(CPack)
457
458# Summaries
459message(STATUS "Feature summary:")
460message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
461message(STATUS " GDB stub: ${USE_GDB_STUB}")
462message(STATUS " Video recording: ${USE_FFMPEG}")
463message(STATUS " GIF recording: ${USE_MAGICK}")
464message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
465message(STATUS " ZIP support: ${USE_LIBZIP}")
466message(STATUS " 7-Zip support: ${USE_LZMA}")
467message(STATUS " Better audio resampling: ${USE_BLIP}")
468message(STATUS "Frontend summary:")
469message(STATUS " Qt: ${BUILD_QT}")
470message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
471message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
472message(STATUS " Profiling: ${BUILD_PERF}")
473message(STATUS "Library summary:")
474message(STATUS " Static: ${BUILD_STATIC}")
475message(STATUS " Shared: ${BUILD_SHARED}")