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})
150 if(MSVC)
151 add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
152 endif()
153elseif(UNIX)
154 add_definitions(-DUSE_PTHREADS)
155
156 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
157 add_definitions(-D_GNU_SOURCE)
158 endif()
159 if(NOT APPLE AND NOT HAIKU)
160 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
161 endif()
162
163 list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
164 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
165 source_group("POSIX-specific code" FILES ${OS_SRC})
166endif()
167
168if(APPLE)
169 add_definitions(-D_DARWIN_C_SOURCE)
170 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
171endif()
172
173if(NOT HAIKU AND NOT MSVC AND NOT PSP2)
174 set(M_LIBRARY m)
175endif()
176list(APPEND OS_LIB ${M_LIBRARY})
177
178if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
179 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
180 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
181 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)
182endif()
183
184if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
185 if(NOT BUILD_EGL)
186 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
187 endif()
188endif()
189
190if(BUILD_RASPI)
191 set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
192endif()
193
194if(BUILD_PANDORA)
195 add_definitions(-DBUILD_PANDORA)
196endif()
197
198if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
199 enable_language(ASM)
200endif()
201
202if(PSP2 OR WII)
203 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
204endif()
205
206if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII)
207 set(USE_GDB_STUB OFF)
208endif()
209
210if(WII)
211 add_definitions(-U__STRICT_ANSI__)
212endif()
213
214include(CheckFunctionExists)
215check_function_exists(strdup HAVE_STRDUP)
216check_function_exists(strndup HAVE_STRNDUP)
217check_function_exists(localtime_r HAVE_LOCALTIME_R)
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 if(NOT DEFINED 3DS AND NOT DEFINED PSP2 AND NOT DEFINED WII)
232 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
233 endif()
234 set(DISABLE_FRONTENDS ON)
235 set(MINIMAL_CORE ON)
236endif()
237
238check_function_exists(chmod HAVE_CHMOD)
239check_function_exists(umask HAVE_UMASK)
240
241set(FUNCTION_DEFINES)
242
243if(HAVE_STRDUP)
244 list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
245endif()
246
247if(HAVE_STRNDUP)
248 list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
249endif()
250
251if(HAVE_LOCALTIME_R)
252 list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
253endif()
254
255if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
256 list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
257 if (HAVE_STRTOF_L)
258 list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
259 endif()
260 if (HAVE_SNPRINTF_L)
261 list(APPEND FUNCTION_DEFINES HAVE_SNPRINTF_L)
262 endif()
263endif()
264
265if(HAVE_SETLOCALE)
266 list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
267endif()
268
269if(HAVE_CHMOD)
270 list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
271endif()
272
273if(HAVE_UMASK)
274 list(APPEND FUNCTION_DEFINES HAVE_UMASK)
275endif()
276
277# Feature dependencies
278set(FEATURES)
279if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
280 set(LIBEDIT_LIBRARIES -ledit)
281 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
282 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
283 endif()
284else()
285 find_feature(USE_CLI_DEBUGGER "libedit")
286endif()
287if(BUILD_GL)
288 find_package(OpenGL QUIET)
289 if(NOT OPENGL_FOUND)
290 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
291 endif()
292endif()
293if(NOT BUILD_GL)
294 set(OPENGLE_LIBRARY "" CACHE PATH "" FORCE)
295endif()
296if(BUILD_GLES2 AND NOT BUILD_RASPI)
297 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
298 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
299 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
300 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
301 endif()
302endif()
303if(NOT BUILD_GLES2)
304 set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
305endif()
306set(WANT_ZLIB ${USE_ZLIB})
307set(WANT_PNG ${USE_PNG})
308set(WANT_LIBZIP ${USE_LIBZIP})
309
310find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
311find_feature(USE_ZLIB "ZLIB")
312find_feature(USE_MINIZIP "minizip")
313find_feature(USE_PNG "PNG")
314find_feature(USE_LIBZIP "libzip")
315find_feature(USE_MAGICK "MagickWand")
316find_feature(USE_EPOXY "epoxy")
317
318# Features
319set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
320set(FEATURE_SRC)
321set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
322
323if(DISABLE_DEPS)
324 set(USE_GDB_STUB OFF)
325endif()
326
327if(USE_CLI_DEBUGGER)
328 list(APPEND FEATURES CLI_DEBUGGER)
329 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
330 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
331 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
332 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
333 link_directories(${LIBEDIT_LIBRARY_DIRS})
334 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
335 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
336else()
337 set(DEBUGGER_LIB "")
338endif()
339
340if(USE_GDB_STUB)
341 list(APPEND FEATURES GDB_STUB)
342 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
343endif()
344source_group("ARM debugger" FILES ${DEBUGGER_SRC})
345
346if(USE_FFMPEG)
347 list(APPEND FEATURES FFMPEG)
348 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
349 if(NOT LIBSWRESAMPLE_FOUND)
350 list(APPEND FEATURES LIBAV)
351 endif()
352 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
353 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
354 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
355 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
356 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
357 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
358 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
359 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
360 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
361 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}")
362 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
363 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavresample${LIBAVRESAMPLE_VERSION_MAJOR}|libavresample-ffmpeg${LIBAVRESAMPLE_VERSION_MAJOR}")
364 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavutil${LIBAVUTIL_VERSION_MAJOR}|libavutil-ffmpeg${LIBAVUTIL_VERSION_MAJOR}")
365 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswscale${LIBSWSCALE_VERSION_MAJOR}|libswscale-ffmpeg${LIBSWSCALE_VERSION_MAJOR}")
366 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
367 if(APPLE)
368 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
369 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
370 endif()
371endif()
372
373list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
374
375if(USE_MAGICK)
376 list(APPEND FEATURES MAGICK)
377 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
378 link_directories(${MAGICKWAND_LIBRARY_DIRS})
379 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
380 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
381 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
382 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
383 set(MAGICKWAND_DEB_VERSION "5")
384 else()
385 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
386 endif()
387 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
388endif()
389
390if(WANT_ZLIB AND NOT USE_ZLIB)
391 set(SKIP_INSTALL_ALL ON)
392 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/zlib zlib)
393 set_property(TARGET zlibstatic PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/zlib;${CMAKE_SOURCE_DIR}/src/third-party/zlib)
394 set_property(TARGET zlib PROPERTY EXCLUDE_FROM_ALL ON)
395 set_property(TARGET example PROPERTY EXCLUDE_FROM_ALL ON)
396 set_property(TARGET minigzip PROPERTY EXCLUDE_FROM_ALL ON)
397 set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
398 set(ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
399 set(ZLIB_LIBRARY zlibstatic)
400 list(APPEND DEPENDENCY_LIB zlibstatic)
401 set(USE_ZLIB ON)
402endif()
403
404if(USE_ZLIB)
405 list(APPEND FEATURES ZLIB)
406 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
407 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
408 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
409endif()
410
411if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
412 set(PNG_STATIC ON CACHE BOOL "" FORCE)
413 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
414 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
415 set(SKIP_INSTALL_ALL ON)
416 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/libpng libpng)
417 set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/libpng;${CMAKE_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
418 set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/libpng ${CMAKE_BINARY_DIR}/libpng)
419 list(APPEND DEPENDENCY_LIB png16_static)
420 set(USE_PNG ON)
421endif()
422
423if(USE_PNG)
424 list(APPEND FEATURES PNG)
425 include_directories(AFTER ${PNG_INCLUDE_DIRS})
426 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
427 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
428endif()
429
430if(USE_LIBZIP)
431 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
432 link_directories(${LIBZIP_LIBRARY_DIRS})
433 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
434 list(APPEND FEATURES LIBZIP)
435 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
436 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
437elseif(USE_MINIZIP)
438 include_directories(AFTER ${MINIZIP_INCLUDE_DIRS})
439 link_directories(${MINIZIP_LIBRARY_DIRS})
440 list(APPEND DEPENDENCY_LIB ${MINIZIP_LIBRARIES})
441 list(APPEND FEATURES MINIZIP)
442 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
443 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libminizip1")
444elseif(USE_ZLIB)
445 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c
446 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
447 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
448endif()
449
450if (USE_LZMA)
451 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
452 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
453 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
454 set(LZMA_SRC
455 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
456 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
457 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
458 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
459 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
460 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
461 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
462 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
463 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Delta.c
464 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
465 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
466 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
467 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
468 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
469 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
470 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
471 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
472 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
473 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
474 list(APPEND VFS_SRC ${LZMA_SRC})
475 list(APPEND FEATURES LZMA)
476endif()
477
478if(USE_EPOXY)
479 add_definitions(-DBUILD_GL -DBUILD_GLES2)
480 list(APPEND FEATURES EPOXY)
481 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
482 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
483 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
484endif()
485
486
487set(FEATURE_DEFINES)
488foreach(FEATURE IN LISTS FEATURES)
489 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
490endforeach()
491
492set(CORE_SRC)
493if(M_CORE_GB)
494 add_definitions(-DM_CORE_GB)
495 list(APPEND CORE_SRC
496 ${LR35902_SRC}
497 ${GB_SRC}
498 ${GB_RENDERER_SRC})
499endif()
500
501if(M_CORE_GBA)
502 add_definitions(-DM_CORE_GBA)
503 list(APPEND CORE_SRC
504 ${ARM_SRC}
505 ${GBA_SRC}
506 ${GBA_CHEATS_SRC}
507 ${GBA_CTX_SRC}
508 ${DEBUGGER_SRC}
509 ${GBA_RENDERER_SRC})
510 if(NOT M_CORE_GB)
511 list(APPEND CORE_SRC ${CMAKE_SOURCE_DIR}/src/gb/audio.c)
512 endif()
513endif()
514
515source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
516source_group("Extra features" FILES ${FEATURE_SRC})
517source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
518
519# Platform binaries
520if(3DS)
521 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR}/3ds)
522endif()
523
524if(WII)
525 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR}/wii)
526endif()
527
528if(PSP2)
529 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
530endif()
531
532# Binaries
533list(APPEND CORE_SRC
534 ${UTIL_SRC}
535 ${CORE_VFS_SRC}
536 ${OS_SRC}
537 ${THIRD_PARTY_SRC})
538
539set(SRC ${CORE_SRC} ${VFS_SRC})
540if(NOT MINIMAL_CORE)
541 if(M_CORE_GBA)
542 list(APPEND SRC
543 ${GBA_RR_SRC}
544 ${GBA_SV_SRC}
545 ${SIO_SRC})
546 endif()
547 list(APPEND SRC
548 ${FEATURE_SRC}
549 ${CLI_SRC})
550endif()
551
552if(NOT SKIP_LIBRARY)
553 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
554 set(BUILD_SHARED ON)
555 endif()
556
557 if(BUILD_SHARED)
558 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
559 if(BUILD_STATIC)
560 add_library(${BINARY_NAME}-static STATIC ${SRC})
561 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
562 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
563 add_dependencies(${BINARY_NAME}-static version-info)
564 endif()
565 else()
566 add_library(${BINARY_NAME} STATIC ${SRC})
567 endif()
568
569 add_dependencies(${BINARY_NAME} version-info)
570 set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
571
572 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
573 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
574 if(UNIX AND NOT APPLE)
575 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
576 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
577 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
578 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
579 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
580 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
581 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
582 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
583 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
584 endif()
585else()
586 set(BUILD_SHARED OFF)
587 set(BUILD_STATIC OFF)
588 find_library(${BINARY_NAME} ${BINARY_NAME})
589 if(NOT ${BINARY_NAME}_FOUND)
590 set(DISABLE_FRONTENDS ON)
591 set(BUILD_PERF OFF)
592 set(BUILD_TEST OFF)
593 endif()
594endif()
595
596if(BUILD_GL)
597 add_definitions(-DBUILD_GL)
598endif()
599
600if(BUILD_GLES2)
601 add_definitions(-DBUILD_GLES2)
602endif()
603
604if(DISABLE_FRONTENDS)
605 set(BUILD_SDL OFF)
606 set(BUILD_QT OFF)
607endif()
608
609if(BUILD_LIBRETRO)
610 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
611 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
612 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")
613 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
614 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
615endif()
616
617if(BUILD_OPENEMU)
618 find_library(FOUNDATION Foundation)
619 find_library(OPENEMUBASE OpenEmuBase)
620 file(GLOB OE_SRC ${CMAKE_SOURCE_DIR}/src/platform/openemu/*.m)
621 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OE_SRC})
622 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
623 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/platform/openemu/Info.plist.in
624 BUNDLE TRUE
625 BUNDLE_EXTENSION oecoreplugin
626 OUTPUT_NAME ${PROJECT_NAME}
627 COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
628 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
629 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
630endif()
631
632if(BUILD_SDL)
633 add_definitions(-DBUILD_SDL)
634 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
635endif()
636
637if(BUILD_QT)
638 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
639endif()
640
641if(BUILD_PERF)
642 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c ${CLI_SRC})
643 if(UNIX AND NOT APPLE)
644 list(APPEND PERF_LIB rt)
645 endif()
646
647 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
648 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB} ${OS_LIB})
649 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
650 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
651 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
652endif()
653
654if(BUILD_TEST)
655 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
656 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
657 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
658 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
659endif()
660
661# Packaging
662set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
663set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
664set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
665set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
666set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
667set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
668
669set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
670set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
671set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
672set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
673set(CPACK_DEBIAN_PACKAGE_SECTION "games")
674
675SET(CPACK_DEB_COMPONENT_INSTALL ON)
676
677set(CPACK_STRIP_FILES ${BINARY_NAME})
678
679install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
680
681include(CPack)
682
683# Summaries
684set(SUMMARY_GL_LIST)
685if(USE_EPOXY)
686 set(SUMMARY_GL_LIST "libepoxy")
687else()
688 if(BUILD_GL)
689 list(APPEND SUMMARY_GL_LIST "OpenGL")
690 endif()
691 if(BUILD_GLES2)
692 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
693 endif()
694endif()
695if(NOT SUMMARY_GL_LIST)
696 set(SUMMARY_GL OFF)
697else()
698 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
699endif()
700if(USE_LIBZIP)
701 set(SUMMARY_ZIP libzip)
702elseif(USE_MINIZIP)
703 set(SUMMARY_ZIP "minizip (external)")
704elseif(USE_ZLIB)
705 set(SUMMARY_ZIP "minizip (included)")
706else()
707 set(SUMMARY_ZIP OFF)
708endif()
709
710message(STATUS "Platforms:")
711message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
712message(STATUS " Game Boy: ${M_CORE_GB}")
713message(STATUS "Features:")
714message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
715message(STATUS " GDB stub: ${USE_GDB_STUB}")
716message(STATUS " Video recording: ${USE_FFMPEG}")
717message(STATUS " GIF recording: ${USE_MAGICK}")
718message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
719message(STATUS " ZIP support: ${SUMMARY_ZIP}")
720message(STATUS " 7-Zip support: ${USE_LZMA}")
721message(STATUS " OpenGL support: ${SUMMARY_GL}")
722message(STATUS "Frontends:")
723message(STATUS " Qt: ${BUILD_QT}")
724message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
725message(STATUS " Profiling: ${BUILD_PERF}")
726message(STATUS " Test harness: ${BUILD_TEST}")
727message(STATUS "Cores:")
728message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
729if(APPLE)
730 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
731endif()
732message(STATUS "Libraries:")
733message(STATUS " Static: ${BUILD_STATIC}")
734message(STATUS " Shared: ${BUILD_SHARED}")