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