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