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