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