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 -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_PNG ON CACHE BOOL "Whether or not to enable PNG support")
14set(USE_LIBZIP ON CACHE BOOL "Whether or not to enable LIBZIP support")
15set(USE_MAGICK ON CACHE BOOL "Whether or not to enable ImageMagick support")
16set(USE_BLIP ON CACHE BOOL "Whether or not to enable blip_buf support")
17set(USE_LZMA ON CACHE BOOL "Whether or not to enable 7-Zip support")
18set(BUILD_QT ON CACHE BOOL "Build Qt frontend")
19set(BUILD_SDL ON CACHE BOOL "Build SDL frontend")
20set(BUILD_LIBRETRO OFF CACHE BOOL "Build libretro core")
21set(BUILD_PERF OFF CACHE BOOL "Build performance profiling tool")
22set(BUILD_TEST OFF CACHE BOOL "Build testing harness")
23set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
24set(BUILD_SHARED ON CACHE BOOL "Build a shared library")
25set(BUILD_GL ON CACHE STRING "Build with OpenGL")
26set(BUILD_GLES2 OFF CACHE STRING "Build with OpenGL|ES 2")
27set(USE_EPOXY ON CACHE STRING "Build with libepoxy")
28set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies")
29file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
30file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
31file(GLOB GBA_CHEATS_SRC ${CMAKE_SOURCE_DIR}/src/gba/cheats/*.c)
32file(GLOB GBA_RR_SRC ${CMAKE_SOURCE_DIR}/src/gba/rr/*.c)
33file(GLOB GBA_SV_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/*.c)
34file(GLOB GBA_CTX_SRC ${CMAKE_SOURCE_DIR}/src/gba/context/*.c)
35file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.[cSs])
36file(GLOB GUI_SRC ${CMAKE_SOURCE_DIR}/src/util/gui/*.c ${CMAKE_SOURCE_DIR}/src/gba/gui/*.c)
37file(GLOB RENDERER_SRC ${CMAKE_SOURCE_DIR}/src/gba/renderers/*.c)
38file(GLOB SIO_SRC ${CMAKE_SOURCE_DIR}/src/gba/sio/lockstep.c)
39file(GLOB THIRD_PARTY_SRC ${CMAKE_SOURCE_DIR}/src/third-party/inih/*.c)
40list(APPEND UTIL_SRC ${CMAKE_SOURCE_DIR}/src/platform/commandline.c)
41set(CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-mem.c)
42set(VFS_SRC)
43source_group("ARM core" FILES ${ARM_SRC})
44source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC} ${SIO_SRC})
45source_group("GBA extra" FILES ${GBA_CHEATS_SRC} ${GBA_CTX_SRC} ${GBA_SV_SRC} ${GBA_RR_SRC})
46source_group("Utilities" FILES ${UTIL_SRC})
47include_directories(${CMAKE_SOURCE_DIR}/src/arm)
48include_directories(${CMAKE_SOURCE_DIR}/src)
49
50if(NOT CMAKE_BUILD_TYPE)
51 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (e.g. Release or Debug)" FORCE)
52endif()
53
54set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
55
56include(GNUInstallDirs)
57
58if (NOT DEFINED LIBDIR)
59 set(LIBDIR "lib")
60endif()
61
62if (NOT DEFINED MANDIR)
63 set(MANDIR ${CMAKE_INSTALL_MANDIR})
64endif()
65
66# Function definitions
67include(FindPkgConfig)
68function(find_feature FEATURE_NAME FEATURE_REQUIRES)
69 if (NOT ${FEATURE_NAME})
70 return()
71 endif()
72 if (DISABLE_DEPS)
73 set(${FEATURE_NAME} OFF PARENT_SCOPE)
74 return()
75 endif()
76 foreach(REQUIRE ${FEATURE_REQUIRES})
77 if(NOT ${REQUIRE}_FOUND)
78 find_package(${REQUIRE} QUIET)
79 if(NOT ${REQUIRE}_FOUND)
80 pkg_search_module(${REQUIRE} ${REQUIRE})
81 if (NOT ${REQUIRE}_FOUND)
82 message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
83 set(${FEATURE_NAME} OFF PARENT_SCOPE)
84 return()
85 endif()
86 endif()
87 endif()
88 string(TOUPPER ${REQUIRE} UREQUIRE)
89 set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
90 set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
91 set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
92 set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
93 set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
94 set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
95 endforeach()
96endfunction()
97
98# Version information
99add_custom_target(version-info ALL ${CMAKE_COMMAND} -E touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
100 COMMAND ${CMAKE_COMMAND}
101 -DBINARY_NAME=${BINARY_NAME}
102 -DCONFIG_FILE=${CMAKE_SOURCE_DIR}/src/util/version.c.in
103 -DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.c
104 -P ${CMAKE_SOURCE_DIR}/version.cmake
105 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
106
107include(${CMAKE_SOURCE_DIR}/version.cmake)
108configure_file(${CMAKE_SOURCE_DIR}/src/util/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
109list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
110source_group("Generated sources" FILES ${CMAKE_BINARY_DIR}/version.c)
111
112# Advanced settings
113set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
114set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
115set(PGO_STAGE_2 CACHE BOOL "Rebuild for profiling-guided optimization after profiles have been generated")
116set(PGO_DIR "/tmp/gba-pgo/" CACHE PATH "Profiling-guided optimization profiles path")
117mark_as_advanced(BUILD_LTO BUILD_PGO PGO_STAGE_2 PGO_DIR)
118set(PGO_PRE_FLAGS "-fprofile-generate=${PGO_DIR} -fprofile-arcs")
119set(PGO_POST_FLAGS "-fprofile-use=${PGO_DIR} -fbranch-probabilities")
120
121if(BUILD_PGO AND NOT PGO_STAGE_2)
122 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_PRE_FLAGS}")
123 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
124 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_PRE_FLAGS}")
125elseif(BUILD_PGO AND PGO_STAGE_2)
126 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
127 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}")
128 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
129endif()
130
131# Platform support
132if(WIN32)
133 set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}")
134 add_definitions(-D_WIN32_WINNT=0x0600)
135 list(APPEND OS_LIB ws2_32 shlwapi)
136 list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
137 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c)
138 source_group("Windows-specific code" FILES ${OS_SRC})
139elseif(UNIX)
140 add_definitions(-DUSE_PTHREADS)
141
142 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
143 add_definitions(-D_GNU_SOURCE)
144 endif()
145 if(NOT APPLE AND NOT HAIKU)
146 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
147 endif()
148
149 list(APPEND CORE_VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
150 file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/posix/*.c)
151 source_group("POSIX-specific code" FILES ${OS_SRC})
152endif()
153
154if(APPLE)
155 add_definitions(-D_DARWIN_C_SOURCE)
156 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6")
157endif()
158
159if(NOT HAIKU AND NOT MSVC AND NOT PSP2)
160 set(M_LIBRARY m)
161endif()
162list(APPEND OS_LIB ${M_LIBRARY})
163
164if(APPLE OR CMAKE_C_COMPILER_ID STREQUAL "GNU" AND BUILD_LTO)
165 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
166 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
167 set_source_files_properties(${CMAKE_SOURCE_DIR}/src/arm/isa-arm.c ${CMAKE_SOURCE_DIR}/src/arm/isa-thumb.c PROPERTIES COMPILE_FLAGS -fno-lto)
168endif()
169
170if(BUILD_BBB OR BUILD_RASPI OR BUILD_PANDORA)
171 if(NOT BUILD_EGL)
172 add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5)
173 endif()
174endif()
175
176if(BUILD_RASPI)
177 set(BUILD_GL OFF CACHE BOOL "OpenGL not supported" FORCE)
178endif()
179
180if(BUILD_PANDORA)
181 add_definitions(-DBUILD_PANDORA)
182endif()
183
184if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*")
185 enable_language(ASM)
186endif()
187
188if(PSP2 OR WII)
189 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format")
190endif()
191
192if(DEFINED 3DS OR DEFINED PSP2 OR DEFINED WII)
193 set(USE_LZMA OFF)
194 set(USE_GDB_STUB OFF)
195endif()
196
197if(WII)
198 add_definitions(-U__STRICT_ANSI__)
199endif()
200
201include(CheckFunctionExists)
202check_function_exists(strdup HAVE_STRDUP)
203check_function_exists(strndup HAVE_STRNDUP)
204check_function_exists(localtime_r HAVE_LOCALTIME_R)
205if(NOT CMAKE_SYSTEM_NAME STREQUAL "Generic")
206 check_function_exists(snprintf_l HAVE_SNPRINTF_L)
207 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
208 # The strtof_l on Linux not actually exposed nor actually strtof_l
209 set(HAVE_STRTOF_L OFF)
210 else()
211 check_function_exists(strtof_l HAVE_STRTOF_L)
212 endif()
213 check_function_exists(newlocale HAVE_NEWLOCALE)
214 check_function_exists(freelocale HAVE_FREELOCALE)
215 check_function_exists(uselocale HAVE_USELOCALE)
216 check_function_exists(setlocale HAVE_SETLOCALE)
217else()
218 if(NOT DEFINED 3DS AND NOT DEFINED PSP2 AND NOT DEFINED WII)
219 set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
220 endif()
221 set(DISABLE_FRONTENDS ON)
222 set(MINIMAL_CORE ON)
223endif()
224
225check_function_exists(chmod HAVE_CHMOD)
226check_function_exists(umask HAVE_UMASK)
227
228set(FUNCTION_DEFINES)
229
230if(HAVE_STRDUP)
231 list(APPEND FUNCTION_DEFINES HAVE_STRDUP)
232endif()
233
234if(HAVE_STRNDUP)
235 list(APPEND FUNCTION_DEFINES HAVE_STRNDUP)
236endif()
237
238if(HAVE_LOCALTIME_R)
239 list(APPEND FUNCTION_DEFINES HAVE_LOCALTIME_R)
240endif()
241
242if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
243 list(APPEND FUNCTION_DEFINES HAVE_LOCALE)
244 if (HAVE_STRTOF_L)
245 list(APPEND FUNCTION_DEFINES HAVE_STRTOF_L)
246 endif()
247 if (HAVE_SNPRINTF_L)
248 list(APPEND FUNCTION_DEFINES HAVE_SNPRINTF_L)
249 endif()
250endif()
251
252if(HAVE_SETLOCALE)
253 list(APPEND FUNCTION_DEFINES HAVE_SETLOCALE)
254endif()
255
256if(HAVE_CHMOD)
257 list(APPEND FUNCTION_DEFINES HAVE_CHMOD)
258endif()
259
260if(HAVE_UMASK)
261 list(APPEND FUNCTION_DEFINES HAVE_UMASK)
262endif()
263
264# Feature dependencies
265set(FEATURES)
266if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
267 set(LIBEDIT_LIBRARIES -ledit)
268 if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
269 list(APPEND LIBEDIT_LIBRARIES -ltermcap)
270 endif()
271else()
272 find_feature(USE_CLI_DEBUGGER "libedit")
273endif()
274if(BUILD_GL)
275 find_package(OpenGL QUIET)
276 if(NOT OPENGL_FOUND)
277 set(BUILD_GL OFF CACHE BOOL "OpenGL not found" FORCE)
278 endif()
279endif()
280if(BUILD_GLES2 AND NOT BUILD_RASPI)
281 find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
282 find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
283 if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
284 set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
285 endif()
286endif()
287set(WANT_ZLIB ${USE_ZLIB})
288set(WANT_PNG ${USE_PNG})
289set(WANT_LIBZIP ${USE_LIBZIP})
290
291find_feature(USE_FFMPEG "libavcodec;libavformat;libavresample;libavutil;libswscale")
292find_feature(USE_ZLIB "ZLIB")
293find_feature(USE_PNG "PNG")
294find_feature(USE_LIBZIP "libzip")
295find_feature(USE_MAGICK "MagickWand")
296find_feature(USE_EPOXY "epoxy")
297
298# Features
299set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)
300set(FEATURE_SRC)
301set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
302
303if(DISABLE_DEPS)
304 set(USE_LZMA OFF)
305 set(USE_GDB_STUB OFF)
306endif()
307
308if(USE_CLI_DEBUGGER)
309 list(APPEND FEATURES CLI_DEBUGGER)
310 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c)
311 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c)
312 list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c)
313 include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS})
314 link_directories(${LIBEDIT_LIBRARY_DIRS})
315 set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})
316 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libedit2")
317else()
318 set(DEBUGGER_LIB "")
319endif()
320
321if(USE_GDB_STUB)
322 list(APPEND FEATURES GDB_STUB)
323 list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c)
324endif()
325source_group("ARM debugger" FILES ${DEBUGGER_SRC})
326
327if(USE_FFMPEG)
328 list(APPEND FEATURES FFMPEG)
329 pkg_search_module(LIBSWRESAMPLE QUIET libswresample)
330 if(NOT LIBSWRESAMPLE_FOUND)
331 list(APPEND FEATURES LIBAV)
332 endif()
333 include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
334 link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS})
335 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")
336 string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION})
337 string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION})
338 string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})
339 string(REGEX MATCH "^[0-9]+" LIBAVUTIL_VERSION_MAJOR ${libavutil_VERSION})
340 string(REGEX MATCH "^[0-9]+" LIBSWSCALE_VERSION_MAJOR ${libswscale_VERSION})
341 list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVRESAMPLE_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
342 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR},libavformat${LIBAVFORMAT_VERSION_MAJOR},libavresample${LIBAVRESAMPLE_VERSION_MAJOR},libavutil${LIBAVUTIL_VERSION_MAJOR},libswscale${LIBSWSCALE_VERSION_MAJOR}")
343 set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
344 if(APPLE)
345 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
346 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework VideoDecodeAcceleration -framework CoreVideo")
347 endif()
348endif()
349
350if(USE_BLIP)
351 list(APPEND THIRD_PARTY_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c")
352 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF)
353else()
354 add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN)
355endif()
356
357if(USE_MAGICK)
358 list(APPEND FEATURES MAGICK)
359 include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS})
360 link_directories(${MAGICKWAND_LIBRARY_DIRS})
361 list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c")
362 list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES})
363 string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION})
364 if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")
365 set(MAGICKWAND_DEB_VERSION "5")
366 else()
367 set(MAGICKWAND_DEB_VERSION "-6.q16-2")
368 endif()
369 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
370endif()
371
372if(WANT_ZLIB AND NOT USE_ZLIB)
373 set(SKIP_INSTALL_ALL ON)
374 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/zlib zlib)
375 set_property(TARGET zlibstatic PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/zlib;${CMAKE_SOURCE_DIR}/src/third-party/zlib)
376 set_property(TARGET zlib PROPERTY EXCLUDE_FROM_ALL ON)
377 set_property(TARGET example PROPERTY EXCLUDE_FROM_ALL ON)
378 set_property(TARGET minigzip PROPERTY EXCLUDE_FROM_ALL ON)
379 set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
380 set(ZLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/third-party/zlib ${CMAKE_BINARY_DIR}/zlib)
381 set(ZLIB_LIBRARY zlibstatic)
382 list(APPEND DEPENDENCY_LIB zlibstatic)
383 set(USE_ZLIB ON)
384endif()
385
386if(USE_ZLIB)
387 list(APPEND FEATURES ZLIB)
388 include_directories(AFTER ${ZLIB_INCLUDE_DIRS})
389 list(APPEND DEPENDENCY_LIB ${ZLIB_LIBRARIES})
390 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},zlib1g")
391endif()
392
393if(WANT_PNG AND USE_ZLIB AND NOT USE_PNG)
394 set(PNG_STATIC ON CACHE BOOL "" FORCE)
395 set(PNG_SHARED OFF CACHE BOOL "" FORCE)
396 set(PNG_TESTS OFF CACHE BOOL "" FORCE)
397 set(SKIP_INSTALL_ALL ON)
398 add_subdirectory(${CMAKE_SOURCE_DIR}/src/third-party/libpng libpng)
399 set_property(TARGET png16_static PROPERTY INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/libpng;${CMAKE_SOURCE_DIR}/src/third-party/libpng;${ZLIB_INCLUDE_DIRS})
400 set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/third-party/libpng ${CMAKE_BINARY_DIR}/libpng)
401 list(APPEND DEPENDENCY_LIB png16_static)
402 set(USE_PNG ON)
403endif()
404
405if(USE_PNG)
406 list(APPEND FEATURES PNG)
407 include_directories(AFTER ${PNG_INCLUDE_DIRS})
408 list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
409 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0")
410endif()
411
412if(USE_LIBZIP)
413 include_directories(AFTER ${LIBZIP_INCLUDE_DIRS})
414 link_directories(${LIBZIP_LIBRARY_DIRS})
415 list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES})
416 list(APPEND FEATURES LIBZIP)
417 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c)
418 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2")
419elseif(USE_ZLIB)
420 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-zip.c
421 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/ioapi.c
422 ${CMAKE_SOURCE_DIR}/src/third-party/zlib/contrib/minizip/unzip.c)
423endif()
424
425if (USE_LZMA)
426 include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma)
427 add_definitions(-D_7ZIP_PPMD_SUPPPORT)
428 list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c)
429 set(LZMA_SRC
430 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c
431 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c
432 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c
433 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf2.c
434 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrc.c
435 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zCrcOpt.c
436 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zDec.c
437 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/CpuArch.c
438 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/LzmaDec.c
439 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Lzma2Dec.c
440 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra.c
441 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bra86.c
442 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Bcj2.c
443 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
444 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c
445 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c
446 ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c)
447 list(APPEND FEATURE_SRC ${LZMA_SRC})
448 list(APPEND FEATURES LZMA)
449endif()
450
451if(USE_EPOXY)
452 add_definitions(-DBUILD_GL -DBUILD_GLES2)
453 list(APPEND FEATURES EPOXY)
454 include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
455 set(OPENGLES2_LIBRARY ${EPOXY_LIBRARIES})
456 set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libepoxy0")
457endif()
458
459
460set(FEATURE_DEFINES)
461foreach(FEATURE IN LISTS FEATURES)
462 list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
463endforeach()
464
465source_group("Virtual files" FILES ${CORE_VFS_SRC} ${VFS_SRC})
466source_group("Extra features" FILES ${FEATURE_SRC})
467source_group("Third-party code" FILES ${THIRD_PARTY_SRC})
468
469# Platform binaries
470if(3DS)
471 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/3ds ${CMAKE_BINARY_DIR}/3ds)
472endif()
473
474if(WII)
475 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/wii ${CMAKE_BINARY_DIR}/wii)
476endif()
477
478if(PSP2)
479 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/psp2 ${CMAKE_BINARY_DIR}/psp2)
480endif()
481
482# Binaries
483set(CORE_SRC
484 ${ARM_SRC}
485 ${GBA_SRC}
486 ${GBA_CHEATS_SRC}
487 ${GBA_CTX_SRC}
488 ${DEBUGGER_SRC}
489 ${RENDERER_SRC}
490 ${UTIL_SRC}
491 ${CORE_VFS_SRC}
492 ${OS_SRC}
493 ${THIRD_PARTY_SRC})
494
495if(NOT MINIMAL_CORE)
496 set(SRC
497 ${CORE_SRC}
498 ${GBA_RR_SRC}
499 ${GBA_SV_SRC}
500 ${SIO_SRC}
501 ${FEATURE_SRC}
502 ${VFS_SRC})
503else()
504 set(SRC ${CORE_SRC} ${VFS_SRC})
505endif()
506
507if(NOT BUILD_STATIC AND NOT BUILD_SHARED)
508 set(BUILD_SHARED ON)
509endif()
510
511if(BUILD_SHARED)
512 add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
513 if(BUILD_STATIC)
514 add_library(${BINARY_NAME}-static STATIC ${SRC})
515 set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
516 install(TARGETS ${BINARY_NAME}-static DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
517 add_dependencies(${BINARY_NAME}-static version-info)
518 endif()
519else()
520 add_library(${BINARY_NAME} STATIC ${SRC})
521endif()
522
523add_dependencies(${BINARY_NAME} version-info)
524set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
525
526target_link_libraries(${BINARY_NAME} ${DEBUGGER_LIB} ${DEPENDENCY_LIB} ${OS_LIB})
527install(TARGETS ${BINARY_NAME} LIBRARY DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME} NAMELINK_SKIP ARCHIVE DESTINATION ${LIBDIR} RUNTIME DESTINATION ${LIBDIR} COMPONENT lib${BINARY_NAME})
528if(UNIX AND NOT APPLE)
529 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-16.png DESTINATION share/icons/hicolor/16x16/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
530 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-24.png DESTINATION share/icons/hicolor/24x24/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
531 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-32.png DESTINATION share/icons/hicolor/32x32/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
532 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-48.png DESTINATION share/icons/hicolor/48x48/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
533 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-64.png DESTINATION share/icons/hicolor/64x64/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
534 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-96.png DESTINATION share/icons/hicolor/96x96/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
535 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-128.png DESTINATION share/icons/hicolor/128x128/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
536 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-256.png DESTINATION share/icons/hicolor/256x256/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
537 install(FILES ${CMAKE_SOURCE_DIR}/res/mgba-512.png DESTINATION share/icons/hicolor/512x512/apps RENAME mgba.png COMPONENT lib${BINARY_NAME})
538endif()
539
540if(BUILD_GL)
541 add_definitions(-DBUILD_GL)
542endif()
543
544if(BUILD_GLES2)
545 add_definitions(-DBUILD_GLES2)
546endif()
547
548if(DISABLE_FRONTENDS)
549 set(BUILD_SDL OFF)
550 set(BUILD_QT OFF)
551endif()
552
553if(BUILD_LIBRETRO)
554 file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c)
555 add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC})
556 set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;${OS_DEFINES};${FUNCTION_DEFINES}")
557 target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})
558endif()
559
560if(BUILD_SDL)
561 add_definitions(-DBUILD_SDL)
562 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/sdl ${CMAKE_BINARY_DIR}/sdl)
563endif()
564
565if(BUILD_QT)
566 add_subdirectory(${CMAKE_SOURCE_DIR}/src/platform/qt ${CMAKE_BINARY_DIR}/qt)
567endif()
568
569if(BUILD_PERF)
570 set(PERF_SRC ${CMAKE_SOURCE_DIR}/src/platform/test/perf-main.c)
571 if(UNIX AND NOT APPLE)
572 list(APPEND PERF_LIB rt)
573 endif()
574
575 add_executable(${BINARY_NAME}-perf ${PERF_SRC})
576 target_link_libraries(${BINARY_NAME}-perf ${BINARY_NAME} ${PERF_LIB})
577 set_target_properties(${BINARY_NAME}-perf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
578 install(TARGETS ${BINARY_NAME}-perf DESTINATION bin COMPONENT ${BINARY_NAME}-perf)
579 install(FILES ${CMAKE_SOURCE_DIR}/tools/perf.py DESTINATION "${CMAKE_INSTALL_LIBDIR}/${BINARY_NAME}" COMPONENT ${BINARY_NAME}-perf)
580endif()
581
582if(BUILD_TEST)
583 add_executable(${BINARY_NAME}-fuzz ${CMAKE_SOURCE_DIR}/src/platform/test/fuzz-main.c)
584 target_link_libraries(${BINARY_NAME}-fuzz ${BINARY_NAME})
585 set_target_properties(${BINARY_NAME}-fuzz PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
586 install(TARGETS ${BINARY_NAME}-fuzz DESTINATION bin COMPONENT ${BINARY_NAME}-test)
587endif()
588
589# Packaging
590set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
591set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_VERSION_MAJOR})
592set(CPACK_PACKAGE_VERSION_MINOR ${LIB_VERSION_MINOR})
593set(CPACK_PACKAGE_VERSION_PATCH ${LIB_VERSION_PATCH})
594set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
595set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
596
597set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "mGBA Game Boy Advance Emulator")
598set(CPACK_PACKAGE_VENDOR "Jeffrey Pfau")
599set(CPACK_PACKAGE_CONTACT "Jeffrey Pfau <jeffrey@endrift.com>")
600set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
601set(CPACK_DEBIAN_PACKAGE_SECTION "games")
602
603SET(CPACK_DEB_COMPONENT_INSTALL ON)
604
605set(CPACK_STRIP_FILES ${BINARY_NAME})
606
607install(FILES ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/CHANGES DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT lib${BINARY_NAME})
608
609include(CPack)
610
611# Summaries
612message(STATUS "Feature summary:")
613message(STATUS " CLI debugger: ${USE_CLI_DEBUGGER}")
614message(STATUS " GDB stub: ${USE_GDB_STUB}")
615message(STATUS " Video recording: ${USE_FFMPEG}")
616message(STATUS " GIF recording: ${USE_MAGICK}")
617message(STATUS " Screenshot/advanced savestate support: ${USE_PNG}")
618message(STATUS " 7-Zip support: ${USE_LZMA}")
619message(STATUS " Better audio resampling: ${USE_BLIP}")
620message(STATUS "Frontend summary:")
621message(STATUS " Qt: ${BUILD_QT}")
622message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
623message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
624message(STATUS " Profiling: ${BUILD_PERF}")
625message(STATUS " Test harness: ${BUILD_TEST}")
626message(STATUS "Library summary:")
627message(STATUS " Static: ${BUILD_STATIC}")
628message(STATUS " Shared: ${BUILD_SHARED}")