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 if (${CMAKE_SOURCE_DIR}/src/platform/3ds/font.raw IS_NEWER_THAN ${CMAKE_BINARY_DIR}/font.c)
161 execute_process(COMMAND ${RAW2C} ${CMAKE_SOURCE_DIR}/src/platform/3ds/font.raw)
162 endif()
163 include_directories(${CMAKE_BINARY_DIR})
164 list(APPEND OS_LIB sf2d ctru)
165 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/3ds/*.c ${CMAKE_BINARY_DIR}/font.c)
166 set(USE_VFS_3DS ON)
167 if(USE_VFS_3DS)
168 add_definitions(-DUSE_VFS_3DS)
169 else()
170 add_definitions(-DUSE_VFS_FILE)
171 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-file.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
172 endif()
173 source_group("3DS-specific code" FILES ${OS_SRC})
174endif()
175
176if(APPLE)
177 add_definitions(-D_DARWIN_C_SOURCE)
178 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
179endif()
180
181if(NOT HAIKU AND NOT MSVC AND NOT PSP2)
182 list(APPEND OS_LIB m)
183endif()
184
185if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
186 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
187 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
188endif()
189
190if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
191 if(NOT BUILD_EGL)
192 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
193 endif()
194endif()
195
196if(WII)
197 add_definitions(-U__STRICT_ANSI__)
198 if (${CMAKE_SOURCE_DIR}/src/platform/wii/font.tpl IS_NEWER_THAN ${CMAKE_BINARY_DIR}/font.c)
199 execute_process(COMMAND ${RAW2C} ${CMAKE_SOURCE_DIR}/src/platform/wii/font.tpl OUTPUT_QUIET ERROR_QUIET)
200 endif()
201endif()
202
203if(BUILD_RASPI)
204 set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
205endif()
206
207if(BUILD_PANDORA)
208 add_definitions(-DBUILD_PANDORA)
209endif()
210
211if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
212 enable_language(ASM)
213endif()
214
215if(PSP2)
216 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
217endif()
218
219include(CheckFunctionExists)
220check_function_exists(strdup HAVE_STRDUP)
221check_function_exists(strndup HAVE_STRNDUP)
222if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
223 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
224 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
225 # The strtof_l on Linux not actually exposed nor actually strtof_l
226 set(HAVE_STRTOF_L OFF)
227 else()
228 check_function_exists(strtof_l HAVE_STRTOF_L)
229 endif()
230 check_function_exists(newlocale HAVE_NEWLOCALE)
231 check_function_exists(freelocale HAVE_FREELOCALE)
232 check_function_exists(uselocale HAVE_USELOCALE)
233 check_function_exists(setlocale HAVE_SETLOCALE)
234else()
235 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
236 set(DISABLE_FRONTENDS ON)
237 set(MINIMAL_CORE ON)
238endif()
239
240if(HAVE_STRDUP)
241 add_definitions(-DHAVE_STRDUP)
242endif()
243
244if(HAVE_STRNDUP)
245 add_definitions(-DHAVE_STRNDUP)
246endif()
247
248if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
249 add_definitions(-DHAVE_LOCALE)
250 if (HAVE_STRTOF_L)
251 add_definitions(-DHAVE_STRTOF_L)
252 endif()
253 if (HAVE_SNPRINTF_L)
254 add_definitions(-DHAVE_SNPRINTF_L)
255 endif()
256endif()
257
258if(HAVE_SETLOCALE)
259 add_definitions(-DHAVE_SETLOCALE)
260endif()
261
262if(DISABLE_DEPS)
263endif()
264
265# Feature dependencies
266set(FEATURES)
267if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
268 set(LIBEDIT_LIBRARIES -ledit)
269 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
270 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
271 endif()
272else()
273 find_feature(USE_CLI_DEBUGGER "libedit")
274endif()
275if(BUILD_GL)
276 find_package(OpenGL QUIET)
277 if(NOT OPENGL_FOUND)
278 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
279 endif()
280endif()
281if(BUILD_GLES2 AND NOT BUILD_RASPI)
282 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
283 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
284 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
285 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
286 endif()
287endif()
288find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
289find_feature(USE_PNG "ZLIB;PNG")
290find_feature(USE_LIBZIP "libzip")
291find_feature(USE_MAGICK "MagickWand")
292
293# Features
294set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
295set(FEATURE_SRC)
296set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
297
298if(DISABLE_DEPS)
299 set(USE_LZMA OFF)
300 set(USE_GDB_STUB OFF)
301endif()
302
303if(USE_CLI_DEBUGGER)
304 list(APPEND FEATURES CLI_DEBUGGER)
305 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
306 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
307 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
308 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
309 link_directories(${LIBEDIT_LIBRARY_DIRS})
310 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
311 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
312else()
313 set(DEBUGGER_LIB "")
314endif()
315
316if(USE_GDB_STUB)
317 list(APPEND FEATURES GDB_STUB)
318 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
319endif()
320source_group("ARM debugger" FILES ${DEBUGGER_SRC})
321
322if(USE_FFMPEG)
323 list(APPEND FEATURES FFMPEG)
324 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
325 if(NOT LIBSWRESAMPLE_FOUND)
326 list(APPEND FEATURES LIBAV)
327 endif()
328 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
329 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
330 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
331 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
332 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
333 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
334 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
335 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
336 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
337 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}")
338 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
339 if(APPLE)
340 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
341 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
342 endif()
343endif()
344
345if(USE_BLIP)
346 list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
347 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
348else()
349 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
350endif()
351
352if(USE_MAGICK)
353 list(APPEND FEATURES MAGICK)
354 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
355 link_directories(${MAGICKWAND_LIBRARY_DIRS})
356 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
357 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
358 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
359 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
360 set(MAGICKWAND_DEB_VERSION "5")
361 else()
362 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
363 endif()
364 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
365endif()
366
367if(USE_PNG)
368 list(APPEND FEATURES PNG)
369 include_directories(AFTER ${PNG_INCLUDE_DIRS})
370 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
371 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0,zlib1g")
372endif()
373
374if(USE_LIBZIP)
375 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
376 link_directories(${LIBZIP_LIBRARY_DIRS})
377 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
378 list(APPEND FEATURES LIBZIP)
379 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
380 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
381endif()
382
383if (USE_LZMA)
384 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
385 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
386 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
387 set(LZMA_SRC
388 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
389 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
390 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
391 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
392 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
393 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
394 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
395 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
396 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
397 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
398 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
399 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
400 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
401 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
402 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
403 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
404 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
405 list(APPEND FEATURE_SRC ${LZMA_SRC})
406 list(APPEND FEATURES LZMA)
407endif()
408
409set(FEATURE_DEFINES)
410foreach(FEATURE IN LISTS FEATURES)
411 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
412endforeach()
413
414source_group("Virtual files" FILES ${VFS_SRC})
415source_group("Extra features" FILES ${FEATURE_SRC})
416source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
417
418# Binaries
419set(CORE_SRC
420 ${ARM_SRC}
421 ${GBA_SRC}
422 ${GBA_CHEATS_SRC}
423 ${GBA_CTX_SRC}
424 ${DEBUGGER_SRC}
425 ${RENDERER_SRC}
426 ${UTIL_SRC}
427 ${VFS_SRC}
428 ${OS_SRC}
429 ${THIRD_PARTY_SRC})
430
431if(NOT MINIMAL_CORE)
432 set(SRC
433 ${CORE_SRC}
434 ${GBA_RR_SRC}
435 ${GBA_SV_SRC}
436 ${SIO_SRC}
437 ${FEATURE_SRC})
438else()
439 set(SRC ${CORE_SRC})
440endif()
441
442if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
443 set(BUILD_SHARED ON)
444endif()
445
446if(BUILD_SHARED)
447 add_library(${BINARY_NAME} SHARED ${SRC})
448 set_target_properties(${BINARY_NAME} PROPERTIES SOVERSION ${LIB_VERSION_ABI})
449 if(BUILD_STATIC)
450 add_library(${BINARY_NAME}-static STATIC ${SRC})
451 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
452 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
453 add_dependencies(${BINARY_NAME}-static version-info)
454 endif()
455else()
456 add_library(${BINARY_NAME} STATIC ${SRC})
457endif()
458
459add_dependencies(${BINARY_NAME} version-info)
460
461target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
462install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
463if(UNIX AND NOT APPLE)
464 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
465 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
466 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
467 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
468 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
469 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
470 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
471 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
472 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
473endif()
474set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
475
476if(BUILD_GL)
477 add_definitions(-DBUILD_GL)
478endif()
479
480if(BUILD_GLES2)
481 add_definitions(-DBUILD_GLES2)
482endif()
483
484if(DISABLE_FRONTENDS)
485 set(BUILD_SDL OFF)
486 set(BUILD_QT OFF)
487endif()
488
489if(BUILD_LIBRETRO)
490 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
491 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
492 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING")
493 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
494endif()
495
496if(BUILD_SDL)
497 add_definitions(-DBUILD_SDL)
498 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
499endif()
500
501if(BUILD_QT)
502 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
503endif()
504
505if(WII)
506 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR})
507endif()
508
509if(PSP2)
510 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR})
511endif()
512
513if(3DS)
514 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR})
515endif()
516
517if(BUILD_PERF)
518 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c)
519 if(UNIX AND NOT APPLE)
520 list(APPEND PERF_LIB rt)
521 endif()
522
523 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
524 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
525 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
526 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
527endif()
528
529if(BUILD_TEST)
530 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
531 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
532 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
533endif()
534
535# Packaging
536set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
537set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
538set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
539set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
540set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
541set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
542
543set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
544set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
545set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
546set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
547set(CPACK_DEBIAN_PACKAGE_SECTION "games")
548
549SET(CPACK_DEB_COMPONENT_INSTALL ON)
550
551set(CPACK_STRIP_FILES ${BINARY_NAME})
552
553install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
554
555include(CPack)
556
557# Summaries
558message(STATUS "Feature summary:")
559message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
560message(STATUS " GDB stub: ${USE_GDB_STUB}")
561message(STATUS " Video recording: ${USE_FFMPEG}")
562message(STATUS " GIF recording: ${USE_MAGICK}")
563message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
564message(STATUS " ZIP support: ${USE_LIBZIP}")
565message(STATUS " 7-Zip support: ${USE_LZMA}")
566message(STATUS " Better audio resampling: ${USE_BLIP}")
567message(STATUS "Frontend summary:")
568message(STATUS " Qt: ${BUILD_QT}")
569message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
570message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
571message(STATUS " Profiling: ${BUILD_PERF}")
572message(STATUS " Test harness: ${BUILD_TEST}")
573message(STATUS "Library summary:")
574message(STATUS " Static: ${BUILD_STATIC}")
575message(STATUS " Shared: ${BUILD_SHARED}")