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_BLIP ON CACHE BOOL "Whether or not to enable blip_buf support")
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)
49list(APPEND GBA_SV_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/util/vfs/vfs-dirent.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_PNG "PNG")
310find_feature(USE_LIBZIP "libzip")
311find_feature(USE_MAGICK "MagickWand")
312find_feature(USE_EPOXY "epoxy")
313
314# Features
315set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
316set(FEATURE_SRC)
317set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
318
319if(DISABLE_DEPS)
320 set(USE_GDB_STUB OFF)
321endif()
322
323if(USE_CLI_DEBUGGER)
324 list(APPEND FEATURES CLI_DEBUGGER)
325 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
326 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
327 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
328 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
329 link_directories(${LIBEDIT_LIBRARY_DIRS})
330 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
331 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
332else()
333 set(DEBUGGER_LIB "")
334endif()
335
336if(USE_GDB_STUB)
337 list(APPEND FEATURES GDB_STUB)
338 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
339endif()
340source_group("ARM debugger" FILES ${DEBUGGER_SRC})
341
342if(USE_FFMPEG)
343 list(APPEND FEATURES FFMPEG)
344 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
345 if(NOT LIBSWRESAMPLE_FOUND)
346 list(APPEND FEATURES LIBAV)
347 endif()
348 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
349 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
350 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
351 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
352 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
353 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
354 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
355 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
356 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
357 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}")
358 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
359 if(APPLE)
360 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
361 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
362 endif()
363endif()
364
365if(USE_BLIP)
366 list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
367 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
368else()
369 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
370endif()
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_ZLIB)
435 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c
436 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
437 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
438endif()
439
440if (USE_LZMA)
441 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
442 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
443 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
444 set(LZMA_SRC
445 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
446 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
447 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
448 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
449 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
450 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
451 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
452 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
453 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Delta.c
454 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
455 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
456 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
457 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
458 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
459 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
460 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
461 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
462 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
463 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
464 list(APPEND VFS_SRC ${LZMA_SRC})
465 list(APPEND FEATURES LZMA)
466endif()
467
468if(USE_EPOXY)
469 add_definitions(-DBUILD_GL -DBUILD_GLES2)
470 list(APPEND FEATURES EPOXY)
471 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
472 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
473 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
474endif()
475
476
477set(FEATURE_DEFINES)
478foreach(FEATURE IN LISTS FEATURES)
479 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
480endforeach()
481
482source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
483source_group("Extra features" FILES ${FEATURE_SRC})
484source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
485
486# Platform binaries
487if(3DS)
488 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR}/3ds)
489endif()
490
491if(WII)
492 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR}/wii)
493endif()
494
495if(PSP2)
496 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
497endif()
498
499# Binaries
500set(CORE_SRC)
501if(M_CORE_GB)
502 add_definitions(-DM_CORE_GB)
503 list(APPEND CORE_SRC
504 ${LR35902_SRC}
505 ${GB_SRC}
506 ${GB_RENDERER_SRC})
507endif()
508
509if(M_CORE_GBA)
510 add_definitions(-DM_CORE_GBA)
511 list(APPEND CORE_SRC
512 ${ARM_SRC}
513 ${GBA_SRC}
514 ${GBA_CHEATS_SRC}
515 ${GBA_CTX_SRC}
516 ${DEBUGGER_SRC}
517 ${GBA_RENDERER_SRC})
518endif()
519
520list(APPEND CORE_SRC
521 ${UTIL_SRC}
522 ${CORE_VFS_SRC}
523 ${OS_SRC}
524 ${THIRD_PARTY_SRC})
525
526set(SRC ${CORE_SRC} ${VFS_SRC})
527if(NOT MINIMAL_CORE)
528 if(M_CORE_GBA)
529 list(APPEND SRC
530 ${GBA_RR_SRC}
531 ${GBA_SV_SRC}
532 ${SIO_SRC})
533 endif()
534 list(APPEND SRC
535 ${FEATURE_SRC})
536endif()
537
538if(NOT SKIP_LIBRARY)
539 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
540 set(BUILD_SHARED ON)
541 endif()
542
543 if(BUILD_SHARED)
544 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
545 if(BUILD_STATIC)
546 add_library(${BINARY_NAME}-static STATIC ${SRC})
547 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
548 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
549 add_dependencies(${BINARY_NAME}-static version-info)
550 endif()
551 else()
552 add_library(${BINARY_NAME} STATIC ${SRC})
553 endif()
554
555 add_dependencies(${BINARY_NAME} version-info)
556 set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
557
558 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
559 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
560 if(UNIX AND NOT APPLE)
561 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
562 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
563 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
564 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
565 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
566 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
567 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
568 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
569 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
570 endif()
571else()
572 set(BUILD_SHARED OFF)
573 set(BUILD_STATIC OFF)
574 find_library(${BINARY_NAME} ${BINARY_NAME})
575 if(NOT ${BINARY_NAME}_FOUND)
576 set(DISABLE_FRONTENDS ON)
577 set(BUILD_PERF OFF)
578 set(BUILD_TEST OFF)
579 endif()
580endif()
581
582if(BUILD_GL)
583 add_definitions(-DBUILD_GL)
584endif()
585
586if(BUILD_GLES2)
587 add_definitions(-DBUILD_GLES2)
588endif()
589
590if(DISABLE_FRONTENDS)
591 set(BUILD_SDL OFF)
592 set(BUILD_QT OFF)
593endif()
594
595if(BUILD_LIBRETRO)
596 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
597 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
598 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")
599 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
600 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
601endif()
602
603if(BUILD_OPENEMU)
604 find_library(FOUNDATION Foundation)
605 find_library(OPENEMUBASE OpenEmuBase)
606 file(GLOB OE_SRC ${CMAKE_SOURCE_DIR}/src/platform/openemu/*.m)
607 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OE_SRC})
608 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
609 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/platform/openemu/Info.plist.in
610 BUNDLE TRUE
611 BUNDLE_EXTENSION oecoreplugin
612 OUTPUT_NAME ${PROJECT_NAME}
613 COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
614 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
615 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
616endif()
617
618if(BUILD_SDL)
619 add_definitions(-DBUILD_SDL)
620 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
621endif()
622
623if(BUILD_QT)
624 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
625endif()
626
627if(BUILD_PERF)
628 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c)
629 if(UNIX AND NOT APPLE)
630 list(APPEND PERF_LIB rt)
631 endif()
632
633 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
634 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
635 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
636 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
637 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
638endif()
639
640if(BUILD_TEST)
641 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
642 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
643 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
644 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
645endif()
646
647# Packaging
648set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
649set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
650set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
651set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
652set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
653set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
654
655set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
656set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
657set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
658set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
659set(CPACK_DEBIAN_PACKAGE_SECTION "games")
660
661SET(CPACK_DEB_COMPONENT_INSTALL ON)
662
663set(CPACK_STRIP_FILES ${BINARY_NAME})
664
665install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
666
667include(CPack)
668
669# Summaries
670set(SUMMARY_GL_LIST)
671if(USE_EPOXY)
672 set(SUMMARY_GL_LIST "libepoxy")
673else()
674 if(BUILD_GL)
675 list(APPEND SUMMARY_GL_LIST "OpenGL")
676 endif()
677 if(BUILD_GLES2)
678 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
679 endif()
680endif()
681if(NOT SUMMARY_GL_LIST)
682 set(SUMMARY_GL OFF)
683else()
684 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
685endif()
686if(USE_LIBZIP)
687 set(SUMMARY_ZIP libzip)
688elseif(USE_ZLIB)
689 set(SUMMARY_ZIP minizip)
690else()
691 set(SUMMARY_ZIP OFF)
692endif()
693
694message(STATUS "Platforms:")
695message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
696message(STATUS " Game Boy: ${M_CORE_GB}")
697message(STATUS "Features:")
698message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
699message(STATUS " GDB stub: ${USE_GDB_STUB}")
700message(STATUS " Video recording: ${USE_FFMPEG}")
701message(STATUS " GIF recording: ${USE_MAGICK}")
702message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
703message(STATUS " ZIP support: ${SUMMARY_ZIP}")
704message(STATUS " 7-Zip support: ${USE_LZMA}")
705message(STATUS " Better audio resampling: ${USE_BLIP}")
706message(STATUS " OpenGL support: ${SUMMARY_GL}")
707message(STATUS "Frontends:")
708message(STATUS " Qt: ${BUILD_QT}")
709message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
710message(STATUS " Profiling: ${BUILD_PERF}")
711message(STATUS " Test harness: ${BUILD_TEST}")
712message(STATUS "Cores:")
713message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
714if(APPLE)
715 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
716endif()
717message(STATUS "Libraries:")
718message(STATUS " Static: ${BUILD_STATIC}")
719message(STATUS " Shared: ${BUILD_SHARED}")