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