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