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