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_ZLIB ON CACHE BOOL "Whether or not to enable zlib support")
13set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support")
14set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable LIBZIP support")
15set(USE_MAGICK ON CACHE BOOL "Whether or not to enable ImageMagick support")
16set(M_CORE_GBA ON CACHE BOOL "Build Game Boy Advance core")
17set(M_CORE_GB ON CACHE BOOL "Build Game Boy core")
18set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
19set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
20set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
21set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
22if(APPLE)
23 set(BUILD_OPENEMU OFF CACHE BOOL "Build OpenEmu core")
24endif()
25set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
26set(BUILD_TEST OFF CACHE BOOL "Build testing harness")
27set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
28set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
29set(SKIP_LIBRARY OFF CACHE BOOL "Skip building the library (useful for only building libretro or OpenEmu cores)")
30set(BUILD_GL ON CACHE STRING "Build with OpenGL")
31set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2")
32set(USE_EPOXY ON CACHE STRING "Build with libepoxy")
33set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies")
34file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
35file(GLOB LR35902_SRC ${CMAKE_SOURCE_DIR}/src/lr35902/*.c)
36file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
37file(GLOB GB_SRC ${CMAKE_SOURCE_DIR}/src/gb/*.c)
38file(GLOB GBA_CHEATS_SRC ${CMAKE_SOURCE_DIR}/src/gba/cheats/*.c)
39file(GLOB GBA_RR_SRC ${CMAKE_SOURCE_DIR}/src/gba/rr/*.c)
40file(GLOB GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/*.c)
41file(GLOB GBA_CTX_SRC ${CMAKE_SOURCE_DIR}/src/gba/context/*.c)
42file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs] ${CMAKE_SOURCE_DIR}/src/core/*.c)
43file(GLOB GUI_SRC ${CMAKE_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_SOURCE_DIR}/src/gba/gui/*.c)
44file(GLOB GBA_RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c)
45file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
46file(GLOB GB_RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gb/renderers/*.c)
47file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c)
48set(CLI_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
49set(CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c)
50set(VFS_SRC)
51source_group("ARM core" FILES ${ARM_SRC})
52source_group("LR35902 core" FILES ${LR35902_SRC})
53source_group("GBA board" FILES ${GBA_SRC} ${GBA_RENDERER_SRC} ${SIO_SRC})
54source_group("GBA extra" FILES ${GBA_CHEATS_SRC} ${GBA_CTX_SRC} ${GBA_SV_SRC} ${GBA_RR_SRC})
55source_group("GB board" FILES ${GB_SRC})
56source_group("Utilities" FILES ${UTIL_SRC})
57include_directories(${CMAKE_SOURCE_DIR}/src/arm)
58include_directories(${CMAKE_SOURCE_DIR}/src)
59
60if(NOT CMAKE_BUILD_TYPE)
61 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE)
62endif()
63
64set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
65
66include(GNUInstallDirs)
67
68if (NOT DEFINED LIBDIR)
69 set(LIBDIR "lib")
70endif()
71
72if (NOT DEFINED MANDIR)
73 set(MANDIR ${CMAKE_INSTALL_MANDIR})
74endif()
75
76# Function definitions
77include(FindPkgConfig)
78function(find_feature FEATURE_NAME FEATURE_REQUIRES)
79 if (NOT ${FEATURE_NAME})
80 return()
81 endif()
82 if (DISABLE_DEPS)
83 set(${FEATURE_NAME} OFF PARENT_SCOPE)
84 return()
85 endif()
86 foreach(REQUIRE ${FEATURE_REQUIRES})
87 if(NOT ${REQUIRE}_FOUND)
88 find_package(${REQUIRE} QUIET)
89 if(NOT ${REQUIRE}_FOUND)
90 pkg_search_module(${REQUIRE} ${REQUIRE})
91 if (NOT ${REQUIRE}_FOUND)
92 message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
93 set(${FEATURE_NAME} OFF PARENT_SCOPE)
94 return()
95 endif()
96 endif()
97 endif()
98 string(TOUPPER ${REQUIRE} UREQUIRE)
99 set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
100 set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
101 set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
102 set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
103 set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
104 set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
105 endforeach()
106endfunction()
107
108# Version information
109add_custom_target(version-info ALL ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
110 COMMAND ${CMAKE_COMMAND}
111 -DBINARY_NAME=${BINARY_NAME}
112 -DCONFIG_FILE=${CMAKE_SOURCE_DIR}/src/util/version.c.in
113 -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.c
114 -P ${CMAKE_SOURCE_DIR}/version.cmake
115 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
116
117include(${CMAKE_SOURCE_DIR}/version.cmake)
118configure_file(${CMAKE_SOURCE_DIR}/src/util/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
119list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
120source_group("Generated sources" FILES ${CMAKE_BINARY_DIR}/version.c)
121
122# Advanced settings
123set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
124set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
125set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
126set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
127mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
128set(PGO_PRE_FLAGS "-fprofile-generate=${PGO_DIR} -fprofile-arcs")
129set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
130
131if(BUILD_PGO AND NOT PGO_STAGE_2)
132 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
133 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
134 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
135elseif(BUILD_PGO AND PGO_STAGE_2)
136 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
137 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
138 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
139endif()
140
141# Platform support
142if(WIN32)
143 set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
144 add_definitions(-D_WIN32_WINNT=0x0600)
145 list(APPEND OS_LIB ws2_32 shlwapi)
146 list(APPEND CORE_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/windows/*.c)
148 source_group("Windows-specific code" FILES ${OS_SRC})
149elseif(UNIX)
150 add_definitions(-DUSE_PTHREADS)
151
152 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
153 add_definitions(-D_GNU_SOURCE)
154 endif()
155 if(NOT APPLE AND NOT HAIKU)
156 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
157 endif()
158
159 list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
160 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
161 source_group("POSIX-specific code" FILES ${OS_SRC})
162endif()
163
164if(APPLE)
165 add_definitions(-D_DARWIN_C_SOURCE)
166 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
167endif()
168
169if(NOT HAIKU AND NOT MSVC AND NOT PSP2)
170 set(M_LIBRARY m)
171endif()
172list(APPEND OS_LIB ${M_LIBRARY})
173
174if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
175 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
176 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
177 set_source_files_properties(${CMAKE_SOURCE_DIR}/src/arm/isa-arm.c ${CMAKE_SOURCE_DIR}/src/arm/isa-thumb.c PROPERTIES COMPILE_FLAGS -fno-lto)
178endif()
179
180if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
181 if(NOT BUILD_EGL)
182 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
183 endif()
184endif()
185
186if(BUILD_RASPI)
187 set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
188endif()
189
190if(BUILD_PANDORA)
191 add_definitions(-DBUILD_PANDORA)
192endif()
193
194if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
195 enable_language(ASM)
196endif()
197
198if(PSP2 OR WII)
199 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
200endif()
201
202if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII)
203 set(USE_GDB_STUB OFF)
204endif()
205
206if(WII)
207 add_definitions(-U__STRICT_ANSI__)
208endif()
209
210include(CheckFunctionExists)
211check_function_exists(strdup HAVE_STRDUP)
212check_function_exists(strndup HAVE_STRNDUP)
213check_function_exists(localtime_r HAVE_LOCALTIME_R)
214if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
215 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
216 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
217 # The strtof_l on Linux not actually exposed nor actually strtof_l
218 set(HAVE_STRTOF_L OFF)
219 else()
220 check_function_exists(strtof_l HAVE_STRTOF_L)
221 endif()
222 check_function_exists(newlocale HAVE_NEWLOCALE)
223 check_function_exists(freelocale HAVE_FREELOCALE)
224 check_function_exists(uselocale HAVE_USELOCALE)
225 check_function_exists(setlocale HAVE_SETLOCALE)
226else()
227 if(NOT DEFINED 3DS AND NOT DEFINED PSP2 AND NOT DEFINED WII)
228 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
229 endif()
230 set(DISABLE_FRONTENDS ON)
231 set(MINIMAL_CORE ON)
232endif()
233
234check_function_exists(chmod HAVE_CHMOD)
235check_function_exists(umask HAVE_UMASK)
236
237set(FUNCTION_DEFINES)
238
239if(HAVE_STRDUP)
240 list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
241endif()
242
243if(HAVE_STRNDUP)
244 list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
245endif()
246
247if(HAVE_LOCALTIME_R)
248 list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
249endif()
250
251if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
252 list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
253 if (HAVE_STRTOF_L)
254 list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
255 endif()
256 if (HAVE_SNPRINTF_L)
257 list(APPEND FUNCTION_DEFINES HAVE_SNPRINTF_L)
258 endif()
259endif()
260
261if(HAVE_SETLOCALE)
262 list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
263endif()
264
265if(HAVE_CHMOD)
266 list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
267endif()
268
269if(HAVE_UMASK)
270 list(APPEND FUNCTION_DEFINES HAVE_UMASK)
271endif()
272
273# Feature dependencies
274set(FEATURES)
275if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
276 set(LIBEDIT_LIBRARIES -ledit)
277 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
278 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
279 endif()
280else()
281 find_feature(USE_CLI_DEBUGGER "libedit")
282endif()
283if(BUILD_GL)
284 find_package(OpenGL QUIET)
285 if(NOT OPENGL_FOUND)
286 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
287 endif()
288endif()
289if(NOT BUILD_GL)
290 set(OPENGLE_LIBRARY "" CACHE PATH "" FORCE)
291endif()
292if(BUILD_GLES2 AND NOT BUILD_RASPI)
293 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
294 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
295 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
296 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
297 endif()
298endif()
299if(NOT BUILD_GLES2)
300 set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
301endif()
302set(WANT_ZLIB ${USE_ZLIB})
303set(WANT_PNG ${USE_PNG})
304set(WANT_LIBZIP ${USE_LIBZIP})
305
306find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
307find_feature(USE_ZLIB "ZLIB")
308find_feature(USE_PNG "PNG")
309find_feature(USE_LIBZIP "libzip")
310find_feature(USE_MAGICK "MagickWand")
311find_feature(USE_EPOXY "epoxy")
312
313# Features
314set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
315set(FEATURE_SRC)
316set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
317
318if(DISABLE_DEPS)
319 set(USE_GDB_STUB OFF)
320endif()
321
322if(USE_CLI_DEBUGGER)
323 list(APPEND FEATURES CLI_DEBUGGER)
324 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
325 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
326 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
327 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
328 link_directories(${LIBEDIT_LIBRARY_DIRS})
329 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
330 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
331else()
332 set(DEBUGGER_LIB "")
333endif()
334
335if(USE_GDB_STUB)
336 list(APPEND FEATURES GDB_STUB)
337 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
338endif()
339source_group("ARM debugger" FILES ${DEBUGGER_SRC})
340
341if(USE_FFMPEG)
342 list(APPEND FEATURES FFMPEG)
343 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
344 if(NOT LIBSWRESAMPLE_FOUND)
345 list(APPEND FEATURES LIBAV)
346 endif()
347 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
348 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
349 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
350 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
351 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
352 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
353 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
354 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
355 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
356 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
357 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
358 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
359 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
360 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
361 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
362 if(APPLE)
363 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
364 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
365 endif()
366endif()
367
368list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
369
370if(USE_MAGICK)
371 list(APPEND FEATURES MAGICK)
372 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
373 link_directories(${MAGICKWAND_LIBRARY_DIRS})
374 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
375 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
376 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
377 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
378 set(MAGICKWAND_DEB_VERSION "5")
379 else()
380 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
381 endif()
382 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
383endif()
384
385if(WANT_ZLIB AND NOT USE_ZLIB)
386 set(SKIP_INSTALL_ALL ON)
387 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/zlib zlib)
388 set_property(TARGET zlibstatic PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/zlib;${CMAKE_SOURCE_DIR}/src/third-party/zlib)
389 set_property(TARGET zlib PROPERTY EXCLUDE_FROM_ALL ON)
390 set_property(TARGET example PROPERTY EXCLUDE_FROM_ALL ON)
391 set_property(TARGET minigzip PROPERTY EXCLUDE_FROM_ALL ON)
392 set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
393 set(ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
394 set(ZLIB_LIBRARY zlibstatic)
395 list(APPEND DEPENDENCY_LIB zlibstatic)
396 set(USE_ZLIB ON)
397endif()
398
399if(USE_ZLIB)
400 list(APPEND FEATURES ZLIB)
401 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
402 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
403 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
404endif()
405
406if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
407 set(PNG_STATIC ON CACHE BOOL "" FORCE)
408 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
409 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
410 set(SKIP_INSTALL_ALL ON)
411 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/libpng libpng)
412 set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/libpng;${CMAKE_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
413 set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/libpng ${CMAKE_BINARY_DIR}/libpng)
414 list(APPEND DEPENDENCY_LIB png16_static)
415 set(USE_PNG ON)
416endif()
417
418if(USE_PNG)
419 list(APPEND FEATURES PNG)
420 include_directories(AFTER ${PNG_INCLUDE_DIRS})
421 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
422 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
423endif()
424
425if(USE_LIBZIP)
426 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
427 link_directories(${LIBZIP_LIBRARY_DIRS})
428 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
429 list(APPEND FEATURES LIBZIP)
430 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
431 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
432elseif(USE_ZLIB)
433 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c
434 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
435 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
436endif()
437
438if (USE_LZMA)
439 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
440 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
441 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
442 set(LZMA_SRC
443 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
444 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
445 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
446 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
447 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
448 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
449 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
450 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
451 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Delta.c
452 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
453 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
454 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
455 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
456 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
457 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
458 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
459 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
460 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
461 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
462 list(APPEND VFS_SRC ${LZMA_SRC})
463 list(APPEND FEATURES LZMA)
464endif()
465
466if(USE_EPOXY)
467 add_definitions(-DBUILD_GL -DBUILD_GLES2)
468 list(APPEND FEATURES EPOXY)
469 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
470 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
471 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
472endif()
473
474
475set(FEATURE_DEFINES)
476foreach(FEATURE IN LISTS FEATURES)
477 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
478endforeach()
479
480set(CORE_SRC)
481if(M_CORE_GB)
482 add_definitions(-DM_CORE_GB)
483 list(APPEND CORE_SRC
484 ${LR35902_SRC}
485 ${GB_SRC}
486 ${GB_RENDERER_SRC})
487endif()
488
489if(M_CORE_GBA)
490 add_definitions(-DM_CORE_GBA)
491 list(APPEND CORE_SRC
492 ${ARM_SRC}
493 ${GBA_SRC}
494 ${GBA_CHEATS_SRC}
495 ${GBA_CTX_SRC}
496 ${DEBUGGER_SRC}
497 ${GBA_RENDERER_SRC})
498 if(NOT M_CORE_GB)
499 list(APPEND CORE_SRC ${CMAKE_SOURCE_DIR}/src/gb/audio.c)
500 endif()
501endif()
502
503source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
504source_group("Extra features" FILES ${FEATURE_SRC})
505source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
506
507# Platform binaries
508if(3DS)
509 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR}/3ds)
510endif()
511
512if(WII)
513 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR}/wii)
514endif()
515
516if(PSP2)
517 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
518endif()
519
520# Binaries
521list(APPEND CORE_SRC
522 ${UTIL_SRC}
523 ${CORE_VFS_SRC}
524 ${OS_SRC}
525 ${THIRD_PARTY_SRC})
526
527set(SRC ${CORE_SRC} ${VFS_SRC})
528if(NOT MINIMAL_CORE)
529 if(M_CORE_GBA)
530 list(APPEND SRC
531 ${GBA_RR_SRC}
532 ${GBA_SV_SRC}
533 ${SIO_SRC})
534 endif()
535 list(APPEND SRC
536 ${FEATURE_SRC}
537 ${CLI_SRC})
538endif()
539
540if(NOT SKIP_LIBRARY)
541 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
542 set(BUILD_SHARED ON)
543 endif()
544
545 if(BUILD_SHARED)
546 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
547 if(BUILD_STATIC)
548 add_library(${BINARY_NAME}-static STATIC ${SRC})
549 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
550 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
551 add_dependencies(${BINARY_NAME}-static version-info)
552 endif()
553 else()
554 add_library(${BINARY_NAME} STATIC ${SRC})
555 endif()
556
557 add_dependencies(${BINARY_NAME} version-info)
558 set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
559
560 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
561 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
562 if(UNIX AND NOT APPLE)
563 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
564 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
565 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
566 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
567 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
568 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
569 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
570 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
571 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
572 endif()
573else()
574 set(BUILD_SHARED OFF)
575 set(BUILD_STATIC OFF)
576 find_library(${BINARY_NAME} ${BINARY_NAME})
577 if(NOT ${BINARY_NAME}_FOUND)
578 set(DISABLE_FRONTENDS ON)
579 set(BUILD_PERF OFF)
580 set(BUILD_TEST OFF)
581 endif()
582endif()
583
584if(BUILD_GL)
585 add_definitions(-DBUILD_GL)
586endif()
587
588if(BUILD_GLES2)
589 add_definitions(-DBUILD_GLES2)
590endif()
591
592if(DISABLE_FRONTENDS)
593 set(BUILD_SDL OFF)
594 set(BUILD_QT OFF)
595endif()
596
597if(BUILD_LIBRETRO)
598 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
599 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
600 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=2")
601 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
602 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
603endif()
604
605if(BUILD_OPENEMU)
606 find_library(FOUNDATION Foundation)
607 find_library(OPENEMUBASE OpenEmuBase)
608 file(GLOB OE_SRC ${CMAKE_SOURCE_DIR}/src/platform/openemu/*.m)
609 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OE_SRC})
610 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
611 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/platform/openemu/Info.plist.in
612 BUNDLE TRUE
613 BUNDLE_EXTENSION oecoreplugin
614 OUTPUT_NAME ${PROJECT_NAME}
615 COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
616 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
617 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
618endif()
619
620if(BUILD_SDL)
621 add_definitions(-DBUILD_SDL)
622 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
623endif()
624
625if(BUILD_QT)
626 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
627endif()
628
629if(BUILD_PERF)
630 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c ${CLI_SRC})
631 if(UNIX AND NOT APPLE)
632 list(APPEND PERF_LIB rt)
633 endif()
634
635 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
636 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB} ${OS_LIB})
637 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
638 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
639 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
640endif()
641
642if(BUILD_TEST)
643 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
644 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
645 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
646 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
647endif()
648
649# Packaging
650set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
651set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
652set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
653set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
654set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
655set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
656
657set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
658set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
659set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
660set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
661set(CPACK_DEBIAN_PACKAGE_SECTION "games")
662
663SET(CPACK_DEB_COMPONENT_INSTALL ON)
664
665set(CPACK_STRIP_FILES ${BINARY_NAME})
666
667install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
668
669include(CPack)
670
671# Summaries
672set(SUMMARY_GL_LIST)
673if(USE_EPOXY)
674 set(SUMMARY_GL_LIST "libepoxy")
675else()
676 if(BUILD_GL)
677 list(APPEND SUMMARY_GL_LIST "OpenGL")
678 endif()
679 if(BUILD_GLES2)
680 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
681 endif()
682endif()
683if(NOT SUMMARY_GL_LIST)
684 set(SUMMARY_GL OFF)
685else()
686 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
687endif()
688if(USE_LIBZIP)
689 set(SUMMARY_ZIP libzip)
690elseif(USE_ZLIB)
691 set(SUMMARY_ZIP minizip)
692else()
693 set(SUMMARY_ZIP OFF)
694endif()
695
696message(STATUS "Platforms:")
697message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
698message(STATUS " Game Boy: ${M_CORE_GB}")
699message(STATUS "Features:")
700message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
701message(STATUS " GDB stub: ${USE_GDB_STUB}")
702message(STATUS " Video recording: ${USE_FFMPEG}")
703message(STATUS " GIF recording: ${USE_MAGICK}")
704message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
705message(STATUS " ZIP support: ${SUMMARY_ZIP}")
706message(STATUS " 7-Zip support: ${USE_LZMA}")
707message(STATUS " OpenGL support: ${SUMMARY_GL}")
708message(STATUS "Frontends:")
709message(STATUS " Qt: ${BUILD_QT}")
710message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
711message(STATUS " Profiling: ${BUILD_PERF}")
712message(STATUS " Test harness: ${BUILD_TEST}")
713message(STATUS "Cores:")
714message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
715if(APPLE)
716 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
717endif()
718message(STATUS "Libraries:")
719message(STATUS " Static: ${BUILD_STATIC}")
720message(STATUS " Shared: ${BUILD_SHARED}")