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)
48list(APPEND GBA_SV_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},libavformat${LIBAVFORMAT_VERSION_MAJOR},libavresample${LIBAVRESAMPLE_VERSION_MAJOR},libavutil${LIBAVUTIL_VERSION_MAJOR},libswscale${LIBSWSCALE_VERSION_MAJOR}")
357 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
358 if(APPLE)
359 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
360 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
361 endif()
362endif()
363
364list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
365
366if(USE_MAGICK)
367 list(APPEND FEATURES MAGICK)
368 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
369 link_directories(${MAGICKWAND_LIBRARY_DIRS})
370 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
371 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
372 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
373 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
374 set(MAGICKWAND_DEB_VERSION "5")
375 else()
376 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
377 endif()
378 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
379endif()
380
381if(WANT_ZLIB AND NOT USE_ZLIB)
382 set(SKIP_INSTALL_ALL ON)
383 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/zlib zlib)
384 set_property(TARGET zlibstatic PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/zlib;${CMAKE_SOURCE_DIR}/src/third-party/zlib)
385 set_property(TARGET zlib PROPERTY EXCLUDE_FROM_ALL ON)
386 set_property(TARGET example PROPERTY EXCLUDE_FROM_ALL ON)
387 set_property(TARGET minigzip PROPERTY EXCLUDE_FROM_ALL ON)
388 set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
389 set(ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
390 set(ZLIB_LIBRARY zlibstatic)
391 list(APPEND DEPENDENCY_LIB zlibstatic)
392 set(USE_ZLIB ON)
393endif()
394
395if(USE_ZLIB)
396 list(APPEND FEATURES ZLIB)
397 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
398 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
399 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
400endif()
401
402if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
403 set(PNG_STATIC ON CACHE BOOL "" FORCE)
404 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
405 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
406 set(SKIP_INSTALL_ALL ON)
407 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/libpng libpng)
408 set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/libpng;${CMAKE_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
409 set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/libpng ${CMAKE_BINARY_DIR}/libpng)
410 list(APPEND DEPENDENCY_LIB png16_static)
411 set(USE_PNG ON)
412endif()
413
414if(USE_PNG)
415 list(APPEND FEATURES PNG)
416 include_directories(AFTER ${PNG_INCLUDE_DIRS})
417 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
418 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
419endif()
420
421if(USE_LIBZIP)
422 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
423 link_directories(${LIBZIP_LIBRARY_DIRS})
424 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
425 list(APPEND FEATURES LIBZIP)
426 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
427 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
428elseif(USE_ZLIB)
429 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c
430 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
431 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
432endif()
433
434if (USE_LZMA)
435 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
436 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
437 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
438 set(LZMA_SRC
439 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
440 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
441 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
442 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
443 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
444 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
445 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
446 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
447 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Delta.c
448 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
449 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
450 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
451 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
452 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/BraIA64.c
453 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
454 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
455 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
456 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
457 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
458 list(APPEND VFS_SRC ${LZMA_SRC})
459 list(APPEND FEATURES LZMA)
460endif()
461
462if(USE_EPOXY)
463 add_definitions(-DBUILD_GL -DBUILD_GLES2)
464 list(APPEND FEATURES EPOXY)
465 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
466 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
467 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
468endif()
469
470
471set(FEATURE_DEFINES)
472foreach(FEATURE IN LISTS FEATURES)
473 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
474endforeach()
475
476set(CORE_SRC)
477if(M_CORE_GB)
478 add_definitions(-DM_CORE_GB)
479 list(APPEND CORE_SRC
480 ${LR35902_SRC}
481 ${GB_SRC}
482 ${GB_RENDERER_SRC})
483endif()
484
485if(M_CORE_GBA)
486 add_definitions(-DM_CORE_GBA)
487 list(APPEND CORE_SRC
488 ${ARM_SRC}
489 ${GBA_SRC}
490 ${GBA_CHEATS_SRC}
491 ${GBA_CTX_SRC}
492 ${DEBUGGER_SRC}
493 ${GBA_RENDERER_SRC})
494 if(NOT M_CORE_GB)
495 list(APPEND CORE_SRC ${CMAKE_SOURCE_DIR}/src/gb/audio.c)
496 endif()
497endif()
498
499source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
500source_group("Extra features" FILES ${FEATURE_SRC})
501source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
502
503# Platform binaries
504if(3DS)
505 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR}/3ds)
506endif()
507
508if(WII)
509 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR}/wii)
510endif()
511
512if(PSP2)
513 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
514endif()
515
516# Binaries
517list(APPEND CORE_SRC
518 ${UTIL_SRC}
519 ${CORE_VFS_SRC}
520 ${OS_SRC}
521 ${THIRD_PARTY_SRC})
522
523set(SRC ${CORE_SRC} ${VFS_SRC})
524if(NOT MINIMAL_CORE)
525 if(M_CORE_GBA)
526 list(APPEND SRC
527 ${GBA_RR_SRC}
528 ${GBA_SV_SRC}
529 ${SIO_SRC})
530 endif()
531 list(APPEND SRC
532 ${FEATURE_SRC})
533endif()
534
535if(NOT SKIP_LIBRARY)
536 if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
537 set(BUILD_SHARED ON)
538 endif()
539
540 if(BUILD_SHARED)
541 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
542 if(BUILD_STATIC)
543 add_library(${BINARY_NAME}-static STATIC ${SRC})
544 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
545 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
546 add_dependencies(${BINARY_NAME}-static version-info)
547 endif()
548 else()
549 add_library(${BINARY_NAME} STATIC ${SRC})
550 endif()
551
552 add_dependencies(${BINARY_NAME} version-info)
553 set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
554
555 target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
556 install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
557 if(UNIX AND NOT APPLE)
558 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
559 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
560 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
561 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
562 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
563 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
564 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
565 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
566 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
567 endif()
568else()
569 set(BUILD_SHARED OFF)
570 set(BUILD_STATIC OFF)
571 find_library(${BINARY_NAME} ${BINARY_NAME})
572 if(NOT ${BINARY_NAME}_FOUND)
573 set(DISABLE_FRONTENDS ON)
574 set(BUILD_PERF OFF)
575 set(BUILD_TEST OFF)
576 endif()
577endif()
578
579if(BUILD_GL)
580 add_definitions(-DBUILD_GL)
581endif()
582
583if(BUILD_GLES2)
584 add_definitions(-DBUILD_GLES2)
585endif()
586
587if(DISABLE_FRONTENDS)
588 set(BUILD_SDL OFF)
589 set(BUILD_QT OFF)
590endif()
591
592if(BUILD_LIBRETRO)
593 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
594 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
595 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")
596 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
597 install(TARGETS ${BINARY_NAME}_libretro LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}_libretro NAMELINK_SKIP)
598endif()
599
600if(BUILD_OPENEMU)
601 find_library(FOUNDATION Foundation)
602 find_library(OPENEMUBASE OpenEmuBase)
603 file(GLOB OE_SRC ${CMAKE_SOURCE_DIR}/src/platform/openemu/*.m)
604 add_library(${BINARY_NAME}-openemu MODULE ${CORE_SRC} ${OE_SRC})
605 set_target_properties(${BINARY_NAME}-openemu PROPERTIES
606 MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/platform/openemu/Info.plist.in
607 BUNDLE TRUE
608 BUNDLE_EXTENSION oecoreplugin
609 OUTPUT_NAME ${PROJECT_NAME}
610 COMPILE_DEFINITIONS "DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES};MINIMAL_CORE=1")
611 target_link_libraries(${BINARY_NAME}-openemu ${OS_LIB} ${FOUNDATION} ${OPENEMUBASE})
612 install(TARGETS ${BINARY_NAME}-openemu LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}.oecoreplugin NAMELINK_SKIP)
613endif()
614
615if(BUILD_SDL)
616 add_definitions(-DBUILD_SDL)
617 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
618endif()
619
620if(BUILD_QT)
621 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
622endif()
623
624if(BUILD_PERF)
625 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c)
626 if(UNIX AND NOT APPLE)
627 list(APPEND PERF_LIB rt)
628 endif()
629
630 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
631 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
632 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
633 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
634 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
635endif()
636
637if(BUILD_TEST)
638 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
639 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
640 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
641 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
642endif()
643
644# Packaging
645set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
646set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
647set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
648set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
649set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
650set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
651
652set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
653set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
654set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
655set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
656set(CPACK_DEBIAN_PACKAGE_SECTION "games")
657
658SET(CPACK_DEB_COMPONENT_INSTALL ON)
659
660set(CPACK_STRIP_FILES ${BINARY_NAME})
661
662install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
663
664include(CPack)
665
666# Summaries
667set(SUMMARY_GL_LIST)
668if(USE_EPOXY)
669 set(SUMMARY_GL_LIST "libepoxy")
670else()
671 if(BUILD_GL)
672 list(APPEND SUMMARY_GL_LIST "OpenGL")
673 endif()
674 if(BUILD_GLES2)
675 list(APPEND SUMMARY_GL_LIST "OpenGL|ES 2")
676 endif()
677endif()
678if(NOT SUMMARY_GL_LIST)
679 set(SUMMARY_GL OFF)
680else()
681 string(REPLACE ";" ", " SUMMARY_GL "${SUMMARY_GL_LIST}")
682endif()
683if(USE_LIBZIP)
684 set(SUMMARY_ZIP libzip)
685elseif(USE_ZLIB)
686 set(SUMMARY_ZIP minizip)
687else()
688 set(SUMMARY_ZIP OFF)
689endif()
690
691message(STATUS "Platforms:")
692message(STATUS " Game Boy Advance: ${M_CORE_GBA}")
693message(STATUS " Game Boy: ${M_CORE_GB}")
694message(STATUS "Features:")
695message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
696message(STATUS " GDB stub: ${USE_GDB_STUB}")
697message(STATUS " Video recording: ${USE_FFMPEG}")
698message(STATUS " GIF recording: ${USE_MAGICK}")
699message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
700message(STATUS " ZIP support: ${SUMMARY_ZIP}")
701message(STATUS " 7-Zip support: ${USE_LZMA}")
702message(STATUS " OpenGL support: ${SUMMARY_GL}")
703message(STATUS "Frontends:")
704message(STATUS " Qt: ${BUILD_QT}")
705message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
706message(STATUS " Profiling: ${BUILD_PERF}")
707message(STATUS " Test harness: ${BUILD_TEST}")
708message(STATUS "Cores:")
709message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
710if(APPLE)
711 message(STATUS " OpenEmu core: ${BUILD_OPENEMU}")
712endif()
713message(STATUS "Libraries:")
714message(STATUS " Static: ${BUILD_STATIC}")
715message(STATUS " Shared: ${BUILD_SHARED}")