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