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