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