summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-2.30.2/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-2.30.2/CMakeLists.txt')
-rw-r--r--src/contrib/SDL-2.30.2/CMakeLists.txt3735
1 files changed, 3735 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/CMakeLists.txt b/src/contrib/SDL-2.30.2/CMakeLists.txt
new file mode 100644
index 0000000..8f9ab39
--- /dev/null
+++ b/src/contrib/SDL-2.30.2/CMakeLists.txt
@@ -0,0 +1,3735 @@
1if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
2 message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there")
3endif()
4
5# MSVC runtime library flags are selected by an abstraction.
6set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
7
8cmake_minimum_required(VERSION 3.0.0...3.5)
9project(SDL2 C CXX)
10
11if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
12 set(SDL2_SUBPROJECT OFF)
13else()
14 set(SDL2_SUBPROJECT ON)
15endif()
16
17if (HAIKU)
18 set(LINKER_LANGUAGE CXX)
19endif()
20
21set(EXTRA_LIBS)
22set(EXTRA_LDFLAGS)
23
24set(CMAKE_DEPENDS)
25set(PKGCONFIG_DEPENDS)
26
27# This is a virtual "library" that just exists to collect up compiler and
28# linker options that used to be global to this CMake project. When you
29# specify it as part of a real library's target_link_libraries(), that
30# library will also gain all those build options too. This is meant to
31# modularize old calls to the global add_definitions and include_directories,
32# etc. See https://github.com/libsdl-org/SDL/issues/4150
33add_library(sdl-build-options INTERFACE)
34
35if(WINDOWS_STORE)
36 target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BUILDING_WINRT=1")
37 target_compile_options(sdl-build-options INTERFACE "-ZW")
38endif()
39
40# CMake 3.0 expands the "if(${A})" in "set(OFF 1);set(A OFF);if(${A})" to "if(1)"
41# CMake 3.24+ emits a warning when not set.
42unset(OFF)
43unset(ON)
44if(POLICY CMP0054)
45 cmake_policy(SET CMP0054 NEW)
46endif()
47
48# !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
49# !!! FIXME: for the SDL2 shared library (so you get an
50# !!! FIXME: install_name ("soname") of "@rpath/libSDL-whatever.dylib"
51# !!! FIXME: instead of "/usr/local/lib/libSDL-whatever.dylib"), but I'm
52# !!! FIXME: punting for now and leaving the existing behavior. Until this
53# !!! FIXME: properly resolved, this line silences a warning in CMake 3.0+.
54# !!! FIXME: remove it and this comment entirely once the problem is
55# !!! FIXME: properly resolved.
56#cmake_policy(SET CMP0042 OLD)
57
58include(CheckLibraryExists)
59include(CheckIncludeFiles)
60include(CheckIncludeFile)
61include(CheckLanguage)
62include(CheckSymbolExists)
63include(CheckCSourceCompiles)
64include(CheckCSourceRuns)
65include(CheckCCompilerFlag)
66include(CheckCXXCompilerFlag)
67include(CheckStructHasMember)
68include(CMakeDependentOption)
69include(CMakePushCheckState)
70include(GNUInstallDirs)
71
72find_package(PkgConfig)
73
74list(APPEND CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
75include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
76include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
77include(${SDL2_SOURCE_DIR}/cmake/sdlplatform.cmake)
78include(${SDL2_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake)
79
80# Enable large file support on 32-bit glibc, so that we can access files
81# with large inode numbers
82check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
83if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4)
84 add_definitions(-D_FILE_OFFSET_BITS=64)
85endif()
86
87# See docs/release_checklist.md
88set(SDL_MAJOR_VERSION 2)
89set(SDL_MINOR_VERSION 30)
90set(SDL_MICRO_VERSION 2)
91set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
92
93# Set defaults preventing destination file conflicts
94set(SDL_CMAKE_DEBUG_POSTFIX "d"
95 CACHE STRING "Name suffix for debug builds")
96
97mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX SDL_CMAKE_DEBUG_POSTFIX)
98
99# Calculate a libtool-like version number
100math(EXPR SDL_BINARY_AGE "${SDL_MINOR_VERSION} * 100 + ${SDL_MICRO_VERSION}")
101if(SDL_MINOR_VERSION MATCHES "[02468]$")
102 # Stable branch, 2.24.1 -> libSDL2-2.0.so.0.2400.1
103 set(SDL_INTERFACE_AGE ${SDL_MICRO_VERSION})
104else()
105 # Development branch, 2.23.1 -> libSDL2-2.0.so.0.2301.0
106 set(SDL_INTERFACE_AGE 0)
107endif()
108
109# Increment this if there is an incompatible change - but if that happens,
110# we should rename the library from SDL2 to SDL3, at which point this would
111# reset to 0 anyway.
112set(LT_MAJOR "0")
113
114math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
115math(EXPR LT_CURRENT "${LT_MAJOR} + ${LT_AGE}")
116set(LT_REVISION "${SDL_INTERFACE_AGE}")
117# For historical reasons, the library name redundantly includes the major
118# version twice: libSDL2-2.0.so.0.
119# TODO: in SDL 3, set the OUTPUT_NAME to plain SDL3, which will simplify
120# it to libSDL3.so.0
121set(LT_RELEASE "2.0")
122set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
123
124# The following should match the versions in the Xcode project file.
125# Each version is 1 higher than you might expect, for compatibility
126# with libtool: macOS ABI versioning is 1-based, unlike other platforms
127# which are normally 0-based.
128math(EXPR DYLIB_CURRENT_VERSION_MAJOR "${LT_MAJOR} + ${LT_AGE} + 1")
129math(EXPR DYLIB_CURRENT_VERSION_MINOR "${LT_REVISION}")
130set(DYLIB_CURRENT_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.${DYLIB_CURRENT_VERSION_MINOR}.0")
131set(DYLIB_COMPATIBILITY_VERSION "${DYLIB_CURRENT_VERSION_MAJOR}.0.0")
132
133# This list holds all generated headers.
134# To avoid generating them twice, these are added to a dummy target on which all sdl targets depend.
135set(SDL_GENERATED_HEADERS)
136
137#message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
138
139check_cpu_architecture(x86 SDL_CPU_X86)
140check_cpu_architecture(x64 SDL_CPU_X64)
141check_cpu_architecture(arm32 SDL_CPU_ARM32)
142check_cpu_architecture(arm64 SDL_CPU_ARM64)
143check_cpu_architecture(loongarch64 SDL_CPU_LOONGARCH64)
144
145# Check for 64 or 32 bit
146set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
147if(CMAKE_SIZEOF_VOID_P EQUAL 8)
148 set(ARCH_64 TRUE)
149 set(PROCESSOR_ARCH "x64")
150else()
151 set(ARCH_64 FALSE)
152 set(PROCESSOR_ARCH "x86")
153endif()
154set(LIBNAME SDL2)
155if(NOT LIBTYPE)
156 set(LIBTYPE SHARED)
157endif()
158
159# Get the platform
160SDL_DetectCMakePlatform()
161
162# Don't mistake osx for unix
163if(UNIX AND NOT ANDROID AND NOT APPLE AND NOT RISCOS)
164 set(UNIX_SYS ON)
165else()
166 set(UNIX_SYS OFF)
167endif()
168
169if(UNIX OR APPLE)
170 set(UNIX_OR_MAC_SYS ON)
171else()
172 set(UNIX_OR_MAC_SYS OFF)
173endif()
174
175# Emscripten pthreads work, but you need to have a non-pthread fallback build
176# for systems without support. It's not currently enough to not use
177# pthread functions in a pthread-build; it won't start up on unsupported
178# browsers. As such, you have to explicitly enable it on Emscripten builds
179# for the time being. This default with change to ON once this becomes
180# commonly supported in browsers or the Emscripten teams makes a single
181# binary work everywhere.
182if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN)
183 set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
184else()
185 set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
186endif()
187
188if(UNIX_SYS OR ANDROID)
189 set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT ON)
190else()
191 set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT OFF)
192endif()
193
194# The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
195# so we'll just use libusb when it's available. libusb does not support iOS,
196# so we default to yes on iOS.
197# TODO: Windows can support libusb, the hid.c file just depends on Unix APIs
198if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR ANDROID)
199 set(HIDAPI_SKIP_LIBUSB TRUE)
200else()
201 set(HIDAPI_SKIP_LIBUSB FALSE)
202endif()
203
204# On the other hand, *BSD specifically uses libusb only, so we make a special
205# case just for them.
206if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
207 set(HIDAPI_ONLY_LIBUSB TRUE)
208else()
209 set(HIDAPI_ONLY_LIBUSB FALSE)
210endif()
211
212# Compiler info
213if(CMAKE_C_COMPILER_ID MATCHES "Clang|IntelLLVM")
214 set(USE_CLANG TRUE)
215 set(OPT_DEF_ASM TRUE)
216 # Visual Studio 2019 v16.2 added support for Clang/LLVM.
217 # Check if a Visual Studio project is being generated with the Clang toolset.
218 if(MSVC)
219 set(MSVC_CLANG TRUE)
220 endif()
221elseif(CMAKE_COMPILER_IS_GNUCC)
222 set(USE_GCC TRUE)
223 set(OPT_DEF_ASM TRUE)
224elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
225 set(OPT_DEF_ASM TRUE)
226 #set(CMAKE_C_FLAGS "/ZI /WX- /
227elseif(CMAKE_C_COMPILER_ID MATCHES "^Intel$")
228 set(OPT_DEF_ASM TRUE)
229 set(USE_INTELCC TRUE)
230elseif(CMAKE_C_COMPILER_ID MATCHES "QCC")
231 set(USE_QCC TRUE)
232else()
233 set(OPT_DEF_ASM FALSE)
234endif()
235
236if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC)
237 set(OPT_DEF_GCC_ATOMICS ON)
238endif()
239
240# Default option knobs
241if(UNIX OR MINGW OR MSYS OR (USE_CLANG AND NOT WINDOWS) OR VITA OR PSP OR PS2 OR N3DS)
242 set(OPT_DEF_LIBC ON)
243endif()
244if(WINDOWS OR IOS OR TVOS)
245 set(SDL_SYSTEM_ICONV_DEFAULT OFF)
246else()
247 set(SDL_SYSTEM_ICONV_DEFAULT ON)
248endif()
249
250if(NOT ("$ENV{CFLAGS}" STREQUAL ""))
251 if(CMAKE_VERSION VERSION_LESS 3.11.0)
252 message(WARNING "SDL's CMakeLists.txt no longer checks the CFLAGS environment.")
253 message(WARNING "Please use CMake's CMAKE_C_FLAGS and CMAKE_BUILD_TYPE variables directly.")
254 message(WARNING "Or upgrade to CMake >= 3.11.0, which respects the CFLAGS environment var.")
255 endif()
256endif()
257
258# Build in parallel under Visual Studio. Not enabled by default.
259if(MSVC AND NOT USE_CLANG)
260 target_compile_options(sdl-build-options INTERFACE "/MP")
261endif()
262
263if(MSVC)
264 option(SDL_FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
265 if(SDL_FORCE_STATIC_VCRT)
266 if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
267 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
268 endif()
269 foreach(flag_var
270 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
271 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
272 if(${flag_var} MATCHES "/MD")
273 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
274 endif()
275 endforeach()
276 endif()
277
278 if(NOT SDL_LIBC)
279 # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
280 foreach(flag_var
281 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
282 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
283 string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
284 endforeach(flag_var)
285 endif()
286
287 if(MSVC_CLANG)
288 # clang-cl treats /W4 as '-Wall -Wextra' -- we don't need -Wextra
289 foreach(flag_var
290 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
291 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
292 string(REGEX REPLACE "/W4" "/W3" ${flag_var} "${${flag_var}}")
293 endforeach(flag_var)
294 endif()
295endif()
296
297# Those are used for pkg-config and friends, so that the sdl2.pc, sdl2-config,
298# etc. are created correctly.
299set(SDL_LIBS "-lSDL2")
300set(SDL_CFLAGS )
301
302# When building shared lib for Windows with MinGW,
303# avoid the DLL having a "lib" prefix
304if(WINDOWS)
305 set(CMAKE_SHARED_LIBRARY_PREFIX "")
306endif()
307
308set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE=1")
309
310# Emscripten toolchain has a nonempty default value for this, and the checks
311# in this file need to change that, so remember the original value, and
312# restore back to that afterwards. For check_function_exists() to work in
313# Emscripten, this value must be at its default value.
314set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
315
316if(CYGWIN)
317 # We build SDL on cygwin without the UNIX emulation layer
318 target_include_directories(sdl-build-options INTERFACE "/usr/include/mingw")
319 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
320 check_c_source_compiles("int main(int argc, char **argv) { return 0; }"
321 HAVE_GCC_NO_CYGWIN)
322 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
323 if(HAVE_GCC_NO_CYGWIN)
324 list(APPEND EXTRA_LDFLAGS_BUILD "-mno-cygwin")
325 list(APPEND SDL_LIBS "-mno-cygwin")
326 endif()
327 list(APPEND SDL_CFLAGS "-I/usr/include/mingw")
328endif()
329
330# General includes
331target_compile_definitions(sdl-build-options INTERFACE "-DUSING_GENERATED_CONFIG_H")
332target_include_directories(sdl-build-options BEFORE INTERFACE "${SDL2_BINARY_DIR}/include" "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>")
333# Note: The clang toolset for Visual Studio does not support the '-idirafter' option.
334if(USE_GCC OR (USE_CLANG AND NOT MSVC_CLANG))
335 # !!! FIXME: do we _need_ to mess with CMAKE_C_FLAGS here?
336 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter \"${SDL2_SOURCE_DIR}/src/video/khronos\"")
337else()
338 target_include_directories(sdl-build-options INTERFACE "${SDL2_SOURCE_DIR}/src/video/khronos")
339endif()
340
341# All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
342# you only need to have a platform override them if they are disabling.
343if(EMSCRIPTEN)
344 # Set up default values for the currently supported set of subsystems:
345 # Emscripten/Javascript does not have assembly support, a dynamic library
346 # loading architecture, or low-level CPU inspection.
347
348 # SDL_THREADS_ENABLED_BY_DEFAULT now defaults to ON, but pthread support might be disabled by default.
349 # !!! FIXME: most of these subsystems should default to ON if there are dummy implementations to be used.
350
351 set(OPT_DEF_ASM FALSE)
352 set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
353 set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
354 set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
355 set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
356endif()
357
358if(VITA OR PSP OR PS2 OR N3DS)
359 set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
360 set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
361endif()
362
363# When defined, respect CMake's BUILD_SHARED_LIBS setting:
364set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
365if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
366 # ...unless decided already (as for EMSCRIPTEN)
367
368 set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
369
370 if (NOT DEFINED BUILD_SHARED_LIBS)
371 # No preference? Build both, just like the AC/AM configure
372 set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
373
374 elseif (BUILD_SHARED_LIBS)
375 # In this case, we assume the user wants a shared lib and don't build
376 # the static one
377 set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
378 set(SDL_STATIC_ENABLED_BY_DEFAULT OFF)
379 endif()
380endif()
381
382if (NOT DEFINED SDL_TEST_ENABLED_BY_DEFAULT)
383 set(SDL_TEST_ENABLED_BY_DEFAULT ON)
384endif()
385
386set(LONGESTOPTIONNAME 0) # set_option and friends will change this.
387
388set(SDL_SUBSYSTEMS
389 Atomic Audio Video Render Events Joystick Haptic Hidapi Power Threads Timers
390 File Loadso CPUinfo Filesystem Sensor Locale Misc)
391foreach(_SUB ${SDL_SUBSYSTEMS})
392 string(TOUPPER ${_SUB} _OPT)
393 if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
394 set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
395 endif()
396 option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
397endforeach()
398
399# Allow some projects to be built conditionally.
400set_option(SDL2_DISABLE_SDL2MAIN "Disable building/installation of SDL2main" OFF)
401set_option(SDL2_DISABLE_INSTALL "Disable installation of SDL2" ${SDL2_SUBPROJECT})
402set_option(SDL2_DISABLE_UNINSTALL "Disable uninstallation of SDL2" OFF)
403
404option_string(SDL_ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
405#set_option(SDL_DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
406set_option(SDL_ASSEMBLY "Enable assembly routines" ${OPT_DEF_ASM})
407dep_option(SDL_SSEMATH "Allow GCC to use SSE floating point math" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
408dep_option(SDL_SSE "Use SSE assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
409dep_option(SDL_SSE2 "Use SSE2 assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
410dep_option(SDL_SSE3 "Use SSE3 assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
411dep_option(SDL_MMX "Use MMX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
412dep_option(SDL_3DNOW "Use 3Dnow! MMX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF)
413dep_option(SDL_ALTIVEC "Use Altivec assembly routines" ON "SDL_ASSEMBLY" OFF)
414dep_option(SDL_ARMSIMD "Use SIMD assembly blitters on ARM" OFF "SDL_ASSEMBLY;SDL_CPU_ARM32" OFF)
415dep_option(SDL_ARMNEON "Use NEON assembly blitters on ARM" OFF "SDL_ASSEMBLY;SDL_CPU_ARM32" OFF)
416dep_option(SDL_LSX "Use LSX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
417dep_option(SDL_LASX "Use LASX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
418
419set_option(SDL_LIBC "Use the system C library" ${OPT_DEF_LIBC})
420set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS})
421dep_option(SDL_DBUS "Enable D-Bus support" ON ${UNIX_SYS} OFF)
422set_option(SDL_DISKAUDIO "Support the disk writer audio driver" ON)
423set_option(SDL_DUMMYAUDIO "Support the dummy audio driver" ON)
424set_option(SDL_DIRECTFB "Use DirectFB video driver" OFF)
425dep_option(SDL_DIRECTFB_SHARED "Dynamically load directfb support" ON "SDL_DIRECTFB" OFF)
426set_option(SDL_DUMMYVIDEO "Use dummy video driver" ON)
427dep_option(SDL_IBUS "Enable IBus support" ON ${UNIX_SYS} OFF)
428set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ${SDL_SYSTEM_ICONV_DEFAULT})
429set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" OFF)
430set_option(SDL_OPENGL "Include OpenGL support" ON)
431set_option(SDL_OPENGLES "Include OpenGL ES support" ON)
432set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
433dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" ON "SDL_PTHREADS" OFF)
434dep_option(SDL_OSS "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF)
435set_option(SDL_ALSA "Support the ALSA audio API" ${UNIX_SYS})
436dep_option(SDL_ALSA_SHARED "Dynamically load ALSA audio support" ON "SDL_ALSA" OFF)
437set_option(SDL_JACK "Support the JACK audio API" ${UNIX_SYS})
438dep_option(SDL_JACK_SHARED "Dynamically load JACK audio support" ON "SDL_JACK" OFF)
439set_option(SDL_ESD "Support the Enlightened Sound Daemon" ${UNIX_SYS})
440dep_option(SDL_ESD_SHARED "Dynamically load ESD audio support" ON "SDL_ESD" OFF)
441set_option(SDL_PIPEWIRE "Use Pipewire audio" ${UNIX_SYS})
442dep_option(SDL_PIPEWIRE_SHARED "Dynamically load Pipewire support" ON "SDL_PIPEWIRE" OFF)
443set_option(SDL_PULSEAUDIO "Use PulseAudio" ${UNIX_SYS})
444dep_option(SDL_PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "SDL_PULSEAUDIO" OFF)
445set_option(SDL_ARTS "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
446dep_option(SDL_ARTS_SHARED "Dynamically load aRts audio support" ON "SDL_ARTS" OFF)
447set_option(SDL_NAS "Support the NAS audio API" ${UNIX_SYS})
448dep_option(SDL_NAS_SHARED "Dynamically load NAS audio support" ON "SDL_NAS" OFF)
449set_option(SDL_SNDIO "Support the sndio audio API" ${UNIX_SYS})
450dep_option(SDL_SNDIO_SHARED "Dynamically load the sndio audio API" ON "SDL_SNDIO" OFF)
451set_option(SDL_FUSIONSOUND "Use FusionSound audio driver" OFF)
452dep_option(SDL_FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "SDL_FUSIONSOUND" OFF)
453set_option(SDL_LIBSAMPLERATE "Use libsamplerate for audio rate conversion" ${UNIX_SYS})
454dep_option(SDL_LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON "SDL_LIBSAMPLERATE" OFF)
455set_option(SDL_RPATH "Use an rpath when linking SDL" ${UNIX_SYS})
456set_option(SDL_CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ${SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT})
457set_option(SDL_X11 "Use X11 video driver" ${UNIX_SYS})
458dep_option(SDL_X11_SHARED "Dynamically load X11 support" ON "SDL_X11" OFF)
459set(SDL_X11_OPTIONS Xcursor Xdbe XInput Xfixes Xrandr Xscrnsaver XShape)
460foreach(_SUB ${SDL_X11_OPTIONS})
461 string(TOUPPER "SDL_X11_${_SUB}" _OPT)
462 dep_option(${_OPT} "Enable ${_SUB} support" ON "SDL_X11" OFF)
463endforeach()
464set_option(SDL_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
465dep_option(SDL_WAYLAND_SHARED "Dynamically load Wayland support" ON "SDL_WAYLAND" OFF)
466dep_option(SDL_WAYLAND_LIBDECOR "Use client-side window decorations on Wayland" ON "SDL_WAYLAND" OFF)
467dep_option(SDL_WAYLAND_LIBDECOR_SHARED "Dynamically load libdecor support" ON "SDL_WAYLAND_LIBDECOR;SDL_WAYLAND_SHARED" OFF)
468dep_option(SDL_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" ON "SDL_WAYLAND" OFF)
469set_option(SDL_RPI "Use Raspberry Pi video driver" ${UNIX_SYS})
470set_option(SDL_COCOA "Use Cocoa video driver" ${APPLE})
471set_option(SDL_DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS})
472set_option(SDL_XINPUT "Use Xinput for Windows" ${WINDOWS})
473set_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ${WINDOWS})
474set_option(SDL_RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS})
475set_option(SDL_RENDER_METAL "Enable the Metal render driver" ${APPLE})
476set_option(SDL_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
477dep_option(SDL_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
478set_option(SDL_METAL "Enable Metal support" ${APPLE})
479set_option(SDL_KMSDRM "Use KMS DRM video driver" ${UNIX_SYS})
480dep_option(SDL_KMSDRM_SHARED "Dynamically load KMS DRM support" ON "SDL_KMSDRM" OFF)
481set_option(SDL_OFFSCREEN "Use offscreen video driver" ON)
482option_string(SDL_BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" OFF)
483option_string(SDL_FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" OFF)
484set_option(SDL_HIDAPI "Enable the HIDAPI subsystem" ON)
485dep_option(SDL_HIDAPI_LIBUSB "Use libusb for low level joystick drivers" OFF SDL_HIDAPI OFF)
486dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON SDL_HIDAPI OFF)
487dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF)
488set_option(SDL_LIBUDEV "Enable libudev support" ON)
489set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
490option_string(SDL_VENDOR_INFO "Vendor name and/or version to add to SDL_REVISION" "")
491set_option(SDL_CCACHE "Use Ccache to speed up build" ON)
492
493option(SDL_WERROR "Enable -Werror" OFF)
494
495option(SDL_SHARED "Build a shared version of the library" ${SDL_SHARED_ENABLED_BY_DEFAULT})
496option(SDL_STATIC "Build a static version of the library" ${SDL_STATIC_ENABLED_BY_DEFAULT})
497option(SDL_TEST "Build the SDL2_test library" ${SDL_TEST_ENABLED_BY_DEFAULT})
498
499dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" "${CMAKE_POSITION_INDEPENDENT_CODE}" "SDL_STATIC" OFF)
500dep_option(SDL_TESTS "Build the test directory" OFF SDL_TEST OFF)
501set_option(SDL_INSTALL_TESTS "Install test-cases" OFF)
502
503set(HAVE_STATIC_PIC "${SDL_STATIC_PIC}")
504
505if(SDL_HIDAPI)
506 if(HIDAPI_ONLY_LIBUSB)
507 set(SDL_HIDAPI_LIBUSB ON CACHE BOOL "" FORCE)
508 elseif(HIDAPI_SKIP_LIBUSB)
509 set(SDL_HIDAPI_LIBUSB OFF CACHE BOOL "" FORCE)
510 endif()
511endif()
512
513if(VITA)
514 set_option(VIDEO_VITA_PIB "Build with PSVita piglet gles2 support" OFF)
515 set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF)
516endif()
517
518# General source files
519file(GLOB SOURCE_FILES
520 ${SDL2_SOURCE_DIR}/src/*.c
521 ${SDL2_SOURCE_DIR}/src/atomic/*.c
522 ${SDL2_SOURCE_DIR}/src/audio/*.c
523 ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
524 ${SDL2_SOURCE_DIR}/src/dynapi/*.c
525 ${SDL2_SOURCE_DIR}/src/events/*.c
526 ${SDL2_SOURCE_DIR}/src/file/*.c
527 ${SDL2_SOURCE_DIR}/src/joystick/*.c
528 ${SDL2_SOURCE_DIR}/src/haptic/*.c
529 ${SDL2_SOURCE_DIR}/src/hidapi/*.c
530 ${SDL2_SOURCE_DIR}/src/libm/*.c
531 ${SDL2_SOURCE_DIR}/src/locale/*.c
532 ${SDL2_SOURCE_DIR}/src/misc/*.c
533 ${SDL2_SOURCE_DIR}/src/power/*.c
534 ${SDL2_SOURCE_DIR}/src/render/*.c
535 ${SDL2_SOURCE_DIR}/src/render/*/*.c
536 ${SDL2_SOURCE_DIR}/src/sensor/*.c
537 ${SDL2_SOURCE_DIR}/src/stdlib/*.c
538 ${SDL2_SOURCE_DIR}/src/thread/*.c
539 ${SDL2_SOURCE_DIR}/src/timer/*.c
540 ${SDL2_SOURCE_DIR}/src/video/*.c
541 ${SDL2_SOURCE_DIR}/src/video/yuv2rgb/*.c)
542
543if(USE_INTELCC)
544 # warning #39: division by zero
545 # warning #239: floating point underflow
546 # warning #264: floating-point value does not fit in required floating-point type
547 set_property(SOURCE "${SDL2_SOURCE_DIR}/src/libm/e_exp.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -wd239 -wd264")
548 set_property(SOURCE "${SDL2_SOURCE_DIR}/src/libm/e_log.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -wd39")
549 set_property(SOURCE "${SDL2_SOURCE_DIR}/src/libm/e_log10.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -wd39")
550endif()
551
552
553set(SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 1)
554if(SDL_ASSERTIONS MATCHES "^(auto|)$")
555 # Do nada - use optimization settings to determine the assertion level
556 set(SDL_DEFAULT_ASSERT_LEVEL )
557 set(SDL_DEFAULT_ASSERT_LEVEL_CONFIGURED 0)
558elseif(SDL_ASSERTIONS MATCHES "^(disabled|0)$")
559 set(SDL_DEFAULT_ASSERT_LEVEL 0)
560elseif(SDL_ASSERTIONS MATCHES "^(release|1)$")
561 set(SDL_DEFAULT_ASSERT_LEVEL 1)
562elseif(SDL_ASSERTIONS MATCHES "^(enabled|2)$")
563 set(SDL_DEFAULT_ASSERT_LEVEL 2)
564elseif(SDL_ASSERTIONS MATCHES "^(paranoid|3)$")
565 set(SDL_DEFAULT_ASSERT_LEVEL 3)
566else()
567 message_error("unknown assertion level")
568endif()
569set(HAVE_ASSERTIONS ${SDL_ASSERTIONS})
570
571if(NOT SDL_BACKGROUNDING_SIGNAL STREQUAL "OFF")
572 target_compile_definitions(sdl-build-options INTERFACE "-DSDL_BACKGROUNDING_SIGNAL=${SDL_BACKGROUNDING_SIGNAL}")
573endif()
574
575if(NOT SDL_FOREGROUNDING_SIGNAL STREQUAL "OFF")
576 target_compile_definitions(sdl-build-options INTERFACE "-DSDL_FOREGROUNDING_SIGNAL=${SDL_FOREGROUNDING_SIGNAL}")
577endif()
578
579# Compiler option evaluation
580if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC)
581 # Check for -Wall first, so later things can override pieces of it.
582 # Note: clang-cl treats -Wall as -Weverything (which is very loud),
583 # /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough.
584 check_c_compiler_flag(-Wall HAVE_GCC_WALL)
585 if(MSVC_CLANG)
586 list(APPEND EXTRA_CFLAGS "/W3")
587 elseif(HAVE_GCC_WALL)
588 list(APPEND EXTRA_CFLAGS "-Wall")
589 if(HAIKU)
590 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
591 endif()
592 endif()
593
594 check_c_compiler_flag(-Wundef HAVE_GCC_WUNDEF)
595 if(HAVE_GCC_WUNDEF)
596 list(APPEND EXTRA_CFLAGS "-Wundef")
597 endif()
598
599 check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
600 if(HAVE_GCC_NO_STRICT_ALIASING)
601 list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
602 endif()
603
604 check_c_compiler_flag(-Wdocumentation HAVE_GCC_WDOCUMENTATION)
605 if(HAVE_GCC_WDOCUMENTATION)
606 if(SDL_WERROR)
607 check_c_compiler_flag(-Werror=documentation HAVE_GCC_WERROR_DOCUMENTATION)
608 if(HAVE_GCC_WERROR_DOCUMENTATION)
609 list(APPEND EXTRA_CFLAGS "-Werror=documentation")
610 endif()
611 endif()
612 list(APPEND EXTRA_CFLAGS "-Wdocumentation")
613 endif()
614
615 check_c_compiler_flag(-Wdocumentation-unknown-command HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
616 if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
617 if(SDL_WERROR)
618 check_c_compiler_flag(-Werror=documentation-unknown-command HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
619 if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
620 list(APPEND EXTRA_CFLAGS "-Werror=documentation-unknown-command")
621 endif()
622 endif()
623 list(APPEND EXTRA_CFLAGS "-Wdocumentation-unknown-command")
624 endif()
625
626 check_c_compiler_flag(-fcomment-block-commands=threadsafety HAVE_GCC_COMMENT_BLOCK_COMMANDS)
627 if(HAVE_GCC_COMMENT_BLOCK_COMMANDS)
628 list(APPEND EXTRA_CFLAGS "-fcomment-block-commands=threadsafety")
629 list(APPEND EXTRA_CFLAGS "-fcomment-block-commands=deprecated")
630 else()
631 check_c_compiler_flag(/clang:-fcomment-block-commands=threadsafety HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
632 if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
633 list(APPEND EXTRA_CFLAGS "/clang:-fcomment-block-commands=threadsafety")
634 list(APPEND EXTRA_CFLAGS "/clang:-fcomment-block-commands=deprecated")
635 endif()
636 endif()
637
638 check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
639 if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
640 if(SDL_WERROR)
641 check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
642 if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
643 list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
644 endif()
645 endif()
646 list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
647 endif()
648
649 if(DEPENDENCY_TRACKING)
650 check_c_source_compiles("
651 #if !defined(__GNUC__) || __GNUC__ < 3
652 #error Dependency tracking requires GCC 3.0 or newer
653 #endif
654 int main(int argc, char **argv) { return 0; }" HAVE_DEPENDENCY_TRACKING)
655 endif()
656
657 if(SDL_GCC_ATOMICS)
658 check_c_source_compiles("int main(int argc, char **argv) {
659 int a;
660 void *x, *y, *z;
661 __sync_lock_test_and_set(&a, 4);
662 __sync_lock_test_and_set(&x, y);
663 __sync_fetch_and_add(&a, 1);
664 __sync_bool_compare_and_swap(&a, 5, 10);
665 __sync_bool_compare_and_swap(&x, y, z);
666 return 0; }" HAVE_GCC_ATOMICS)
667 if(NOT HAVE_GCC_ATOMICS)
668 check_c_source_compiles("int main(int argc, char **argv) {
669 int a;
670 __sync_lock_test_and_set(&a, 1);
671 __sync_lock_release(&a);
672 return 0; }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
673 endif()
674 endif()
675
676 set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
677 check_c_source_compiles("
678 #if !defined(__GNUC__) || __GNUC__ < 4
679 #error SDL only uses visibility attributes in GCC 4 or newer
680 #endif
681 int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY)
682 if(HAVE_GCC_FVISIBILITY)
683 list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
684 endif()
685 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
686
687 check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
688 if(HAVE_GCC_WSHADOW)
689 list(APPEND EXTRA_CFLAGS "-Wshadow")
690 endif()
691
692 check_c_compiler_flag(-Wunused-local-typedefs HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS)
693 if(HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS)
694 list(APPEND EXTRA_CFLAGS "-Wno-unused-local-typedefs")
695 endif()
696
697 if(APPLE)
698 cmake_push_check_state(RESET)
699 # FIXME: don't use deprecated declarations
700 check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
701 if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
702 target_compile_options(sdl-build-options INTERFACE "-Wno-error=deprecated-declarations")
703 endif()
704 cmake_pop_check_state()
705
706 # FIXME: use generator expression instead of appending to EXTRA_LDFLAGS_BUILD
707 list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-compatibility_version,${DYLIB_COMPATIBILITY_VERSION}")
708 list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,-current_version,${DYLIB_CURRENT_VERSION}")
709 elseif(NOT OPENBSD)
710 set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
711 check_c_compiler_flag("" HAVE_NO_UNDEFINED)
712 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
713 if(HAVE_NO_UNDEFINED AND NOT (USE_CLANG AND WINDOWS))
714 list(APPEND EXTRA_LDFLAGS_BUILD "-Wl,--no-undefined")
715 endif()
716 endif()
717
718 if(MINGW)
719 # See if GCC's -gdwarf-4 is supported
720 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows
721 cmake_push_check_state(RESET)
722 check_c_compiler_flag("-gdwarf-4" HAVE_GDWARF_4)
723 if(HAVE_GDWARF_4)
724 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gdwarf-4")
725 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-4")
726 endif()
727 cmake_pop_check_state()
728 endif()
729
730 # Force color diagnostics when one of these conditions are met
731 if(DEFINED ENV{CI} OR DEFINED ENV{USE_CCACHE} OR CMAKE_GENERATOR MATCHES Ninja)
732 if(EMSCRIPTEN OR (USE_GCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9))
733 list(APPEND EXTRA_CFLAGS -fdiagnostics-color=always)
734 elseif(USE_CLANG AND NOT CMAKE_C_COMPILER_ID MATCHES AppleClang)
735 list(APPEND EXTRA_CFLAGS -fcolor-diagnostics)
736 endif()
737 endif()
738endif()
739if(MSVC)
740 target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_SECURE_NO_DEPRECATE")
741 target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_NONSTDC_NO_DEPRECATE")
742 target_compile_definitions(sdl-build-options INTERFACE "-D_CRT_SECURE_NO_WARNINGS")
743
744 # CET support was added in VS 16.7
745 if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
746 list(APPEND EXTRA_LDFLAGS_BUILD "-CETCOMPAT")
747 endif()
748endif()
749
750if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
751 # Due to a limitation of Microsoft's LTO implementation, LTO must be disabled for memcpy and memset.
752 # The same applies to various functions normally belonging in the C library (for x86 architecture).
753 set_property(SOURCE src/stdlib/SDL_mslibc.c APPEND_STRING PROPERTY COMPILE_FLAGS " /GL-")
754endif()
755
756if(SDL_ASSEMBLY)
757 if(USE_GCC OR USE_CLANG OR USE_INTELCC)
758 # TODO: Those all seem to be quite GCC specific - needs to be
759 # reworked for better compiler support
760 set(HAVE_ASSEMBLY TRUE)
761 if(SDL_MMX)
762 set(CMAKE_REQUIRED_FLAGS "-mmmx")
763 check_c_source_compiles("
764 #ifdef __MINGW32__
765 #include <_mingw.h>
766 #ifdef __MINGW64_VERSION_MAJOR
767 #include <intrin.h>
768 #else
769 #include <mmintrin.h>
770 #endif
771 #else
772 #include <mmintrin.h>
773 #endif
774 #ifndef __MMX__
775 #error Assembler CPP flag not enabled
776 #endif
777 int main(int argc, char **argv) { return 0; }" HAVE_MMX)
778 if(HAVE_MMX)
779 list(APPEND EXTRA_CFLAGS "-mmmx")
780 endif()
781 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
782 endif()
783
784 if(SDL_3DNOW)
785 set(CMAKE_REQUIRED_FLAGS "-m3dnow")
786 check_c_source_compiles("
787 #include <mm3dnow.h>
788 #ifndef __3dNOW__
789 #error Assembler CPP flag not enabled
790 #endif
791 int main(int argc, char **argv) {
792 void *p = 0;
793 _m_prefetch(p);
794 return 0;
795 }" HAVE_3DNOW)
796 if(HAVE_3DNOW)
797 list(APPEND EXTRA_CFLAGS "-m3dnow")
798 endif()
799 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
800 endif()
801
802 if(SDL_SSE)
803 set(CMAKE_REQUIRED_FLAGS "-msse")
804 check_c_source_compiles("
805 #ifdef __MINGW32__
806 #include <_mingw.h>
807 #ifdef __MINGW64_VERSION_MAJOR
808 #include <intrin.h>
809 #else
810 #include <xmmintrin.h>
811 #endif
812 #else
813 #include <xmmintrin.h>
814 #endif
815 #ifndef __SSE__
816 #error Assembler CPP flag not enabled
817 #endif
818 int main(int argc, char **argv) { return 0; }" HAVE_SSE)
819 if(HAVE_SSE)
820 list(APPEND EXTRA_CFLAGS "-msse")
821 endif()
822 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
823 endif()
824
825 if(SDL_SSE2)
826 set(CMAKE_REQUIRED_FLAGS "-msse2")
827 check_c_source_compiles("
828 #ifdef __MINGW32__
829 #include <_mingw.h>
830 #ifdef __MINGW64_VERSION_MAJOR
831 #include <intrin.h>
832 #else
833 #include <emmintrin.h>
834 #endif
835 #else
836 #include <emmintrin.h>
837 #endif
838 #ifndef __SSE2__
839 #error Assembler CPP flag not enabled
840 #endif
841 int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE2)
842 if(CPU_SUPPORTS_SSE2)
843 set(HAVE_SSE2 TRUE)
844 list(APPEND EXTRA_CFLAGS "-msse2")
845 endif()
846 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
847 endif()
848
849 if(SDL_SSE3)
850 set(CMAKE_REQUIRED_FLAGS "-msse3")
851 check_c_source_compiles("
852 #ifdef __MINGW32__
853 #include <_mingw.h>
854 #ifdef __MINGW64_VERSION_MAJOR
855 #include <intrin.h>
856 #else
857 #include <pmmintrin.h>
858 #endif
859 #else
860 #include <pmmintrin.h>
861 #endif
862 #ifndef __SSE3__
863 #error Assembler CPP flag not enabled
864 #endif
865 int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_SSE3)
866 if(CPU_SUPPORTS_SSE3)
867 set(HAVE_SSE3 TRUE)
868 list(APPEND EXTRA_CFLAGS "-msse3")
869 endif()
870 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
871 endif()
872
873 if(NOT SDL_SSEMATH)
874 if(SDL_SSE OR SDL_SSE2 OR SDL_SSE3)
875 if(USE_GCC)
876 check_c_compiler_flag(-mfpmath=387 HAVE_FP_387)
877 if(HAVE_FP_387)
878 list(APPEND EXTRA_CFLAGS "-mfpmath=387")
879 endif()
880 endif()
881 endif()
882 else()
883 set(HAVE_SSEMATH TRUE)
884 endif()
885
886 check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
887
888 if(SDL_ALTIVEC)
889 set(CMAKE_REQUIRED_FLAGS "-maltivec")
890 check_c_source_compiles("
891 #include <altivec.h>
892 vector unsigned int vzero() {
893 return vec_splat_u32(0);
894 }
895 int main(int argc, char **argv) { return 0; }" HAVE_ALTIVEC_H_HDR)
896 check_c_source_compiles("
897 vector unsigned int vzero() {
898 return vec_splat_u32(0);
899 }
900 int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_ALTIVEC)
901 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
902 if(CPU_SUPPORTS_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
903 set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
904 list(APPEND EXTRA_CFLAGS "-maltivec")
905 set(SDL_ALTIVEC_BLITTERS 1)
906 if(HAVE_ALTIVEC_H_HDR)
907 set(HAVE_ALTIVEC_H 1)
908 endif()
909 endif()
910 endif()
911
912 if(SDL_LSX)
913 cmake_push_check_state()
914 set(CMAKE_REQUIRED_FLAGS "-mlsx")
915 check_c_source_compiles("
916 #ifndef __loongarch_sx
917 #error Assembler CPP flag not enabled
918 #endif
919 int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_LSX)
920 check_include_file("lsxintrin.h" HAVE_LSXINTRIN_H)
921 cmake_pop_check_state()
922
923 if(CPU_SUPPORTS_LSX AND HAVE_LSXINTRIN_H)
924 list(APPEND EXTRA_CFLAGS "-mlsx")
925 set(HAVE_LSX TRUE)
926 endif()
927 endif()
928
929 if(SDL_LASX)
930 cmake_push_check_state()
931 set(CMAKE_REQUIRED_FLAGS "-mlasx")
932 check_c_source_compiles("
933 #ifndef __loongarch_asx
934 #error Assembler CPP flag not enabled
935 #endif
936 int main(int argc, char **argv) { return 0; }" CPU_SUPPORTS_LASX)
937 check_include_file("lasxintrin.h" HAVE_LASXINTRIN_H)
938 cmake_pop_check_state()
939 if(CPU_SUPPORTS_LASX AND HAVE_LASXINTRIN_H)
940 list(APPEND EXTRA_CFLAGS "-mlasx")
941 set(HAVE_LASX TRUE)
942 endif()
943 endif()
944
945 if(SDL_ARMSIMD)
946 set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
947 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
948 check_c_source_compiles("
949 .text
950 .arch armv6
951 .object_arch armv4
952 .arm
953 .altmacro
954 #ifndef __ARM_EABI__
955 #error EABI is required (to be sure that calling conventions are compatible)
956 #endif
957 pld [r0]
958 uqadd8 r0, r0, r0
959 " ARMSIMD_FOUND)
960 set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
961
962 if(ARMSIMD_FOUND)
963 set(HAVE_ARMSIMD TRUE)
964 set(SDL_ARM_SIMD_BLITTERS 1)
965 file(GLOB ARMSIMD_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S)
966 list(APPEND SOURCE_FILES ${ARMSIMD_SOURCES})
967 set(WARN_ABOUT_ARM_SIMD_ASM_MIT TRUE)
968 endif()
969 endif()
970
971 if(SDL_ARMNEON)
972 set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
973 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
974 check_c_source_compiles("
975 .text
976 .fpu neon
977 .arch armv7a
978 .object_arch armv4
979 .eabi_attribute 10, 0
980 .arm
981 .altmacro
982 #ifndef __ARM_EABI__
983 #error EABI is required (to be sure that calling conventions are compatible)
984 #endif
985 pld [r0]
986 vmovn.u16 d0, q0
987 " ARMNEON_FOUND)
988 set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
989
990 if(ARMNEON_FOUND)
991 set(HAVE_ARMNEON TRUE)
992 set(SDL_ARM_NEON_BLITTERS 1)
993 file(GLOB ARMNEON_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S)
994 list(APPEND SOURCE_FILES ${ARMNEON_SOURCES})
995 set(WARN_ABOUT_ARM_NEON_ASM_MIT TRUE)
996 endif()
997 endif()
998
999 elseif(MSVC_VERSION GREATER 1500)
1000 # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
1001 # for MSVC - right now it is always activated
1002 if(NOT ARCH_64)
1003 if(SDL_MMX)
1004 set(HAVE_MMX TRUE)
1005 endif()
1006 if(SDL_3DNOW)
1007 set(HAVE_3DNOW TRUE)
1008 endif()
1009 endif()
1010 if(SDL_SSE)
1011 set(HAVE_SSE TRUE)
1012 endif()
1013 if(SDL_SSE2)
1014 set(HAVE_SSE2 TRUE)
1015 endif()
1016 if(SDL_SSE3)
1017 set(HAVE_SSE3 TRUE)
1018 endif()
1019 check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
1020 endif()
1021endif()
1022
1023# TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
1024# anything.
1025if(SDL_LIBC)
1026 if(WINDOWS AND NOT MINGW)
1027 set(HAVE_LIBC TRUE)
1028 check_include_file(stdint.h HAVE_STDINT_H)
1029 foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h)
1030 string(TOUPPER "HAVE_${_HEADER}" _UPPER)
1031 string(REPLACE "." "_" _HAVE_H ${_UPPER})
1032 set(${_HAVE_H} 1)
1033 endforeach()
1034 set(HAVE_SIGNAL_H 1)
1035 foreach(_FN
1036 malloc calloc realloc free bsearch qsort abs memset memcpy memmove memcmp
1037 wcslen _wcsdup wcsdup wcsstr wcscmp wcsncmp _wcsicmp _wcsnicmp
1038 strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
1039 _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
1040 _stricmp _strnicmp sscanf
1041 acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
1042 copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
1043 log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf
1044 sin sinf sqrt sqrtf tan tanf trunc truncf)
1045 string(TOUPPER ${_FN} _UPPER)
1046 set(HAVE_${_UPPER} 1)
1047 endforeach()
1048 set(HAVE_ALLOCA 1)
1049 check_symbol_exists(M_PI math.h HAVE_M_PI)
1050 target_compile_definitions(sdl-build-options INTERFACE "-D_USE_MATH_DEFINES") # needed for M_PI
1051 set(STDC_HEADERS 1)
1052 else()
1053 set(HAVE_LIBC TRUE)
1054 set(headers_to_check
1055 ctype.h
1056 float.h
1057 iconv.h
1058 inttypes.h
1059 limits.h
1060 malloc.h
1061 math.h
1062 memory.h
1063 signal.h
1064 stdarg.h
1065 stddef.h
1066 stdint.h
1067 stdio.h
1068 stdlib.h
1069 string.h
1070 strings.h
1071 sys/types.h
1072 wchar.h
1073 )
1074 foreach(_HEADER ${headers_to_check})
1075 string(TOUPPER "HAVE_${_HEADER}" _UPPER)
1076 string(REGEX REPLACE "[./]" "_" _HAVE_H ${_UPPER})
1077 check_include_file("${_HEADER}" ${_HAVE_H})
1078 endforeach()
1079
1080 set(STDC_HEADER_NAMES "stddef.h;stdarg.h;stdlib.h;string.h;stdio.h;wchar.h;float.h")
1081 check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
1082 check_symbol_exists(M_PI math.h HAVE_M_PI)
1083 # TODO: refine the mprotect check
1084 check_c_source_compiles("#include <sys/types.h>
1085 #include <sys/mman.h>
1086 int main(void) { return 0; }" HAVE_MPROTECT)
1087 foreach(_FN
1088 strtod malloc calloc realloc free getenv setenv putenv unsetenv
1089 bsearch qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
1090 _strrev _strupr _strlwr index rindex strchr strrchr strstr strtok_r
1091 itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
1092 atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp strcasestr
1093 wcscmp _wcsdup wcsdup wcslcat wcslcpy wcslen wcsncmp wcsstr
1094 wcscasecmp _wcsicmp wcsncasecmp _wcsnicmp
1095 sscanf vsscanf vsnprintf fopen64 fseeko fseeko64 _Exit
1096 )
1097 string(TOUPPER ${_FN} _UPPER)
1098 set(_HAVEVAR "HAVE_${_UPPER}")
1099 check_symbol_exists("${_FN}" "${STDC_HEADER_NAMES}" ${_HAVEVAR})
1100 endforeach()
1101
1102 check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
1103 check_symbol_exists(setjmp "setjmp.h" HAVE_SETJMP)
1104 check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP)
1105 check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF)
1106 check_symbol_exists(sysctlbyname "sys/types.h;sys/sysctl.h" HAVE_SYSCTLBYNAME)
1107 check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL)
1108 check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO)
1109 check_symbol_exists(poll "poll.h" HAVE_POLL)
1110 check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE)
1111 check_symbol_exists(posix_fallocate "fcntl.h" HAVE_POSIX_FALLOCATE)
1112
1113 check_library_exists(m pow "" HAVE_LIBM)
1114 if(HAVE_LIBM)
1115 set(CMAKE_REQUIRED_LIBRARIES m)
1116 endif()
1117 foreach(_FN
1118 atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf
1119 exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f
1120 lround lroundf pow powf round roundf scalbn scalbnf sin sinf sqrt
1121 sqrtf tan tanf acos acosf asin asinf trunc truncf)
1122 string(TOUPPER ${_FN} _UPPER)
1123 set(_HAVEVAR "HAVE_${_UPPER}")
1124 check_symbol_exists("${_FN}" "math.h" ${_HAVEVAR})
1125 endforeach()
1126 if(HAVE_LIBM)
1127 set(CMAKE_REQUIRED_LIBRARIES)
1128 if(NOT VITA)
1129 list(APPEND EXTRA_LIBS m)
1130 endif()
1131 endif()
1132
1133 if(SDL_SYSTEM_ICONV)
1134 check_c_source_compiles("
1135 #define LIBICONV_PLUG 1 /* in case libiconv header is in include path */
1136 #include <stddef.h>
1137 #include <iconv.h>
1138 int main(int argc, char **argv) {
1139 return !iconv_open(NULL,NULL);
1140 }" ICONV_IN_LIBC)
1141
1142 cmake_push_check_state()
1143 list(APPEND CMAKE_REQUIRED_LIBRARIES iconv)
1144 check_c_source_compiles("
1145 #include <stddef.h>
1146 #include <iconv.h>
1147 int main(int argc, char **argv) {
1148 return !iconv_open(NULL,NULL);
1149 }" ICONV_IN_LIBICONV)
1150 cmake_pop_check_state()
1151
1152 if(ICONV_IN_LIBC OR ICONV_IN_LIBICONV)
1153 set(HAVE_ICONV 1)
1154 set(HAVE_SYSTEM_ICONV TRUE)
1155 if(ICONV_IN_LIBICONV AND (SDL_LIBICONV OR (NOT ICONV_IN_LIBC)))
1156 set(SDL_USE_LIBICONV 1)
1157 set(HAVE_LIBICONV TRUE)
1158 list(APPEND EXTRA_LIBS iconv)
1159 endif()
1160 endif()
1161 endif()
1162
1163 if(NOT APPLE)
1164 check_include_file(alloca.h HAVE_ALLOCA_H)
1165 check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA1)
1166 check_symbol_exists(alloca "stdlib.h" HAVE_ALLOCA2)
1167 check_symbol_exists(alloca "malloc.h" HAVE_ALLOCA3)
1168 if(HAVE_ALLOCA1 OR HAVE_ALLOCA2 OR HAVE_ALLOCA3)
1169 set(HAVE_ALLOCA 1)
1170 endif()
1171 else()
1172 set(HAVE_ALLOCA_H 1)
1173 set(HAVE_ALLOCA 1)
1174 endif()
1175
1176 check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
1177 endif()
1178else()
1179 if(WINDOWS)
1180 set(HAVE_STDARG_H 1)
1181 set(HAVE_STDDEF_H 1)
1182 check_include_file(stdint.h HAVE_STDINT_H)
1183
1184 if(MSVC AND USE_CLANG)
1185 check_c_compiler_flag("/Q_no-use-libirc" HAS_Q_NO_USE_LIBIRC )
1186 endif()
1187 endif()
1188endif()
1189
1190
1191# Enable/disable various subsystems of the SDL library
1192foreach(_SUB ${SDL_SUBSYSTEMS})
1193 string(TOUPPER ${_SUB} _OPT)
1194 if(NOT SDL_${_OPT})
1195 set(SDL_${_OPT}_DISABLED 1)
1196 endif()
1197endforeach()
1198if(SDL_HAPTIC)
1199 if(NOT SDL_JOYSTICK)
1200 # Haptic requires some private functions from the joystick subsystem.
1201 message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
1202 endif()
1203endif()
1204
1205
1206# General SDL subsystem options, valid for all platforms
1207if(SDL_AUDIO)
1208 # CheckDummyAudio/CheckDiskAudio - valid for all platforms
1209 if(SDL_DUMMYAUDIO)
1210 set(SDL_AUDIO_DRIVER_DUMMY 1)
1211 file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
1212 list(APPEND SOURCE_FILES ${DUMMYAUDIO_SOURCES})
1213 set(HAVE_DUMMYAUDIO TRUE)
1214 set(HAVE_SDL_AUDIO TRUE)
1215 endif()
1216 if(SDL_DISKAUDIO)
1217 set(SDL_AUDIO_DRIVER_DISK 1)
1218 file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
1219 list(APPEND SOURCE_FILES ${DISKAUDIO_SOURCES})
1220 set(HAVE_DISKAUDIO TRUE)
1221 set(HAVE_SDL_AUDIO TRUE)
1222 endif()
1223endif()
1224
1225if(UNIX OR APPLE)
1226 # Relevant for Unix/Darwin only
1227 set(DYNAPI_NEEDS_DLOPEN 1)
1228 CheckDLOPEN()
1229 if(SDL_LOADSO AND HAVE_DLOPEN)
1230 set(SDL_LOADSO_DLOPEN 1)
1231 file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
1232 list(APPEND SOURCE_FILES ${DLOPEN_SOURCES})
1233 set(HAVE_SDL_LOADSO TRUE)
1234 endif()
1235endif()
1236
1237if(UNIX OR APPLE OR HAIKU OR RISCOS)
1238 CheckO_CLOEXEC()
1239endif()
1240
1241if(SDL_JOYSTICK)
1242 if(SDL_VIRTUAL_JOYSTICK)
1243 set(HAVE_VIRTUAL_JOYSTICK TRUE)
1244 set(SDL_JOYSTICK_VIRTUAL 1)
1245 file(GLOB JOYSTICK_VIRTUAL_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/virtual/*.c)
1246 list(APPEND SOURCE_FILES ${JOYSTICK_VIRTUAL_SOURCES})
1247 endif()
1248endif()
1249
1250if(SDL_VIDEO)
1251 if(SDL_DUMMYVIDEO)
1252 set(SDL_VIDEO_DRIVER_DUMMY 1)
1253 file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
1254 list(APPEND SOURCE_FILES ${VIDEO_DUMMY_SOURCES})
1255 set(HAVE_DUMMYVIDEO TRUE)
1256 set(HAVE_SDL_VIDEO TRUE)
1257 endif()
1258 if(SDL_OFFSCREEN)
1259 set(SDL_VIDEO_DRIVER_OFFSCREEN 1)
1260 file(GLOB VIDEO_OFFSCREEN_SOURCES ${SDL2_SOURCE_DIR}/src/video/offscreen/*.c)
1261 list(APPEND SOURCE_FILES ${VIDEO_OFFSCREEN_SOURCES})
1262 set(HAVE_OFFSCREEN TRUE)
1263 set(HAVE_SDL_VIDEO TRUE)
1264 endif()
1265endif()
1266
1267# Platform-specific options and settings
1268if(ANDROID)
1269 file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
1270 list(APPEND SOURCE_FILES ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
1271 set_property(SOURCE "${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-declaration-after-statement")
1272
1273 if(SDL_MISC)
1274 file(GLOB ANDROID_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/android/*.c)
1275 list(APPEND SOURCE_FILES ${ANDROID_MISC_SOURCES})
1276 set(HAVE_SDL_MISC TRUE)
1277 endif()
1278
1279 # SDL_spinlock.c Needs to be compiled in ARM mode.
1280 # There seems to be no better way currently to set the ARM mode.
1281 # see: https://issuetracker.google.com/issues/62264618
1282 # Another option would be to set ARM mode to all compiled files
1283 cmake_push_check_state(RESET)
1284 set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument")
1285 check_c_compiler_flag(-marm HAVE_ARM_MODE)
1286 if(HAVE_ARM_MODE)
1287 set_property(SOURCE "${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
1288 endif()
1289 cmake_pop_check_state()
1290
1291 file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
1292 list(APPEND SDLMAIN_SOURCES ${ANDROID_MAIN_SOURCES})
1293
1294 if(SDL_AUDIO)
1295 set(SDL_AUDIO_DRIVER_ANDROID 1)
1296 file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
1297 list(APPEND SOURCE_FILES ${ANDROID_AUDIO_SOURCES})
1298
1299 set(SDL_AUDIO_DRIVER_OPENSLES 1)
1300 file(GLOB OPENSLES_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/openslES/*.c)
1301 list(APPEND SOURCE_FILES ${OPENSLES_AUDIO_SOURCES})
1302
1303 list(APPEND EXTRA_LIBS ${ANDROID_DL_LIBRARY} OpenSLES)
1304
1305 set(SDL_AUDIO_DRIVER_AAUDIO 1)
1306 file(GLOB AAUDIO_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/aaudio/*.c)
1307 list(APPEND SOURCE_FILES ${AAUDIO_AUDIO_SOURCES})
1308
1309 set(HAVE_SDL_AUDIO TRUE)
1310 endif()
1311 if(SDL_FILESYSTEM)
1312 set(SDL_FILESYSTEM_ANDROID 1)
1313 file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
1314 list(APPEND SOURCE_FILES ${ANDROID_FILESYSTEM_SOURCES})
1315 set(HAVE_SDL_FILESYSTEM TRUE)
1316 endif()
1317 if(SDL_HAPTIC)
1318 set(SDL_HAPTIC_ANDROID 1)
1319 file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
1320 list(APPEND SOURCE_FILES ${ANDROID_HAPTIC_SOURCES})
1321 set(HAVE_SDL_HAPTIC TRUE)
1322 endif()
1323 if(SDL_HIDAPI)
1324 CheckHIDAPI()
1325 endif()
1326 if(SDL_JOYSTICK)
1327 set(SDL_JOYSTICK_ANDROID 1)
1328 file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
1329 list(APPEND SOURCE_FILES ${ANDROID_JOYSTICK_SOURCES})
1330 set(HAVE_SDL_JOYSTICK TRUE)
1331 endif()
1332 if(SDL_LOADSO)
1333 set(SDL_LOADSO_DLOPEN 1)
1334 file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
1335 list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
1336 set(HAVE_SDL_LOADSO TRUE)
1337 endif()
1338 if(SDL_POWER)
1339 set(SDL_POWER_ANDROID 1)
1340 file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
1341 list(APPEND SOURCE_FILES ${ANDROID_POWER_SOURCES})
1342 set(HAVE_SDL_POWER TRUE)
1343 endif()
1344 if(SDL_LOCALE)
1345 file(GLOB ANDROID_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/android/*.c)
1346 list(APPEND SOURCE_FILES ${ANDROID_LOCALE_SOURCES})
1347 set(HAVE_SDL_LOCALE TRUE)
1348 endif()
1349 if(SDL_TIMERS)
1350 set(SDL_TIMER_UNIX 1)
1351 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1352 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
1353 set(HAVE_SDL_TIMERS TRUE)
1354 endif()
1355 if(SDL_SENSOR)
1356 set(SDL_SENSOR_ANDROID 1)
1357 set(HAVE_SDL_SENSORS TRUE)
1358 file(GLOB ANDROID_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/android/*.c)
1359 list(APPEND SOURCE_FILES ${ANDROID_SENSOR_SOURCES})
1360 endif()
1361 if(SDL_VIDEO)
1362 set(SDL_VIDEO_DRIVER_ANDROID 1)
1363 file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
1364 list(APPEND SOURCE_FILES ${ANDROID_VIDEO_SOURCES})
1365 set(HAVE_SDL_VIDEO TRUE)
1366
1367 # Core stuff
1368 # find_library(ANDROID_DL_LIBRARY dl)
1369 # FIXME failing dlopen https://github.com/android-ndk/ndk/issues/929
1370 list(APPEND EXTRA_LIBS dl log android)
1371 target_compile_definitions(sdl-build-options INTERFACE "-DGL_GLEXT_PROTOTYPES")
1372
1373 #enable gles
1374 if(SDL_OPENGLES)
1375 set(SDL_VIDEO_OPENGL_EGL 1)
1376 set(HAVE_OPENGLES TRUE)
1377 set(SDL_VIDEO_OPENGL_ES 1)
1378 set(SDL_VIDEO_RENDER_OGL_ES 1)
1379 set(SDL_VIDEO_OPENGL_ES2 1)
1380 set(SDL_VIDEO_RENDER_OGL_ES2 1)
1381
1382 list(APPEND EXTRA_LIBS GLESv1_CM GLESv2)
1383 endif()
1384
1385 if(SDL_VULKAN)
1386 CHECK_C_SOURCE_COMPILES("
1387 #if defined(__ARM_ARCH) && __ARM_ARCH < 7
1388 #error Vulkan doesn't work on this configuration
1389 #endif
1390 int main(int argc, char **argv) { return 0; }
1391 " VULKAN_PASSED_ANDROID_CHECKS)
1392 if(VULKAN_PASSED_ANDROID_CHECKS)
1393 set(SDL_VIDEO_VULKAN 1)
1394 set(HAVE_VULKAN TRUE)
1395 endif()
1396 endif()
1397 endif()
1398
1399 CheckPTHREAD()
1400 if(SDL_CLOCK_GETTIME)
1401 set(HAVE_CLOCK_GETTIME 1)
1402 endif()
1403
1404elseif(EMSCRIPTEN)
1405 # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
1406 # project. Uncomment at will for verbose cross-compiling -I/../ path info.
1407 target_compile_options(sdl-build-options INTERFACE "-Wno-warn-absolute-paths")
1408
1409 if(SDL_MISC)
1410 file(GLOB EMSRIPTEN_MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/emscripten/*.c)
1411 list(APPEND SOURCE_FILES ${EMSRIPTEN_MISC_SOURCES})
1412 set(HAVE_SDL_MISC TRUE)
1413 endif()
1414 if(SDL_AUDIO)
1415 set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
1416 file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
1417 list(APPEND SOURCE_FILES ${EM_AUDIO_SOURCES})
1418 set(HAVE_SDL_AUDIO TRUE)
1419 endif()
1420 if(SDL_FILESYSTEM)
1421 set(SDL_FILESYSTEM_EMSCRIPTEN 1)
1422 file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
1423 list(APPEND SOURCE_FILES ${EM_FILESYSTEM_SOURCES})
1424 set(HAVE_SDL_FILESYSTEM TRUE)
1425 endif()
1426 if(SDL_JOYSTICK)
1427 set(SDL_JOYSTICK_EMSCRIPTEN 1)
1428 file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
1429 list(APPEND SOURCE_FILES ${EM_JOYSTICK_SOURCES})
1430 set(HAVE_SDL_JOYSTICK TRUE)
1431 endif()
1432 if(SDL_POWER)
1433 set(SDL_POWER_EMSCRIPTEN 1)
1434 file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
1435 list(APPEND SOURCE_FILES ${EM_POWER_SOURCES})
1436 set(HAVE_SDL_POWER TRUE)
1437 endif()
1438 if(SDL_LOCALE)
1439 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/emscripten/*.c)
1440 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
1441 set(HAVE_SDL_LOCALE TRUE)
1442 endif()
1443 if(SDL_TIMERS)
1444 set(SDL_TIMER_UNIX 1)
1445 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1446 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
1447 set(HAVE_SDL_TIMERS TRUE)
1448
1449 if(SDL_CLOCK_GETTIME)
1450 set(HAVE_CLOCK_GETTIME 1)
1451 endif()
1452 endif()
1453 if(SDL_VIDEO)
1454 set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
1455 file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
1456 list(APPEND SOURCE_FILES ${EM_VIDEO_SOURCES})
1457 set(HAVE_SDL_VIDEO TRUE)
1458
1459 #enable gles
1460 if(SDL_OPENGLES)
1461 set(SDL_VIDEO_OPENGL_EGL 1)
1462 set(HAVE_OPENGLES TRUE)
1463 set(SDL_VIDEO_OPENGL_ES2 1)
1464 set(SDL_VIDEO_RENDER_OGL_ES2 1)
1465 endif()
1466 endif()
1467
1468 CheckPTHREAD()
1469 CheckLibUnwind()
1470
1471elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
1472 if(SDL_AUDIO)
1473 if(SYSV5 OR SOLARIS OR HPUX)
1474 set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
1475 file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
1476 list(APPEND SOURCE_FILES ${SUN_AUDIO_SOURCES})
1477 set(HAVE_SDL_AUDIO TRUE)
1478 elseif(NETBSD)
1479 set(SDL_AUDIO_DRIVER_NETBSD 1)
1480 file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
1481 list(APPEND SOURCE_FILES ${NETBSD_AUDIO_SOURCES})
1482 set(HAVE_SDL_AUDIO TRUE)
1483 elseif(AIX)
1484 set(SDL_AUDIO_DRIVER_PAUDIO 1)
1485 file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
1486 list(APPEND SOURCE_FILES ${AIX_AUDIO_SOURCES})
1487 set(HAVE_SDL_AUDIO TRUE)
1488 elseif(QNX)
1489 set(SDL_AUDIO_DRIVER_QSA 1)
1490 file(GLOB QSA_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/qsa/*.c)
1491 list(APPEND SOURCE_FILES ${QSA_AUDIO_SOURCES})
1492 list(APPEND EXTRA_LIBS asound)
1493 set(HAVE_SDL_AUDIO TRUE)
1494 endif()
1495 CheckOSS()
1496 CheckALSA()
1497 CheckJACK()
1498 CheckPipewire()
1499 CheckPulseAudio()
1500 CheckESD()
1501 CheckARTS()
1502 CheckNAS()
1503 CheckSNDIO()
1504 CheckFusionSound()
1505 endif()
1506
1507 if(SDL_VIDEO)
1508 # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
1509 CheckRPI()
1510 CheckX11()
1511 CheckDirectFB()
1512 # Need to check for EGL first because KMSDRM and Wayland depends on it.
1513 CheckEGL()
1514 CheckKMSDRM()
1515 CheckGLX()
1516 CheckOpenGL()
1517 CheckOpenGLES()
1518 CheckWayland()
1519 CheckVivante()
1520 # FIXME: implement CheckVulkan()
1521 if(SDL_VULKAN)
1522 set(SDL_VIDEO_VULKAN 1)
1523 set(HAVE_VULKAN TRUE)
1524 endif()
1525 CheckQNXScreen()
1526 endif()
1527
1528 if(UNIX)
1529 file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
1530 list(APPEND SOURCE_FILES ${CORE_UNIX_SOURCES})
1531
1532 check_c_source_compiles("
1533 #include <linux/input.h>
1534 #ifndef EVIOCGNAME
1535 #error EVIOCGNAME() ioctl not available
1536 #endif
1537 int main(int argc, char** argv) { return 0; }" HAVE_LINUX_INPUT_H)
1538
1539 if(LINUX)
1540 check_c_source_compiles("
1541 #include <linux/kd.h>
1542 #include <linux/keyboard.h>
1543 #include <sys/ioctl.h>
1544 int main(int argc, char **argv) {
1545 struct kbentry kbe;
1546 kbe.kb_table = KG_CTRL;
1547 ioctl(0, KDGKBENT, &kbe);
1548 return 0;
1549 }" HAVE_INPUT_KD)
1550 elseif(FREEBSD)
1551 check_c_source_compiles("
1552 #include <sys/kbio.h>
1553 #include <sys/ioctl.h>
1554 int main(int argc, char **argv) {
1555 accentmap_t accTable;
1556 ioctl(0, KDENABIO, 1);
1557 return 0;
1558 }" HAVE_INPUT_KBIO)
1559 elseif(OPENBSD OR NETBSD)
1560 check_c_source_compiles("
1561 #include <sys/time.h>
1562 #include <dev/wscons/wsconsio.h>
1563 #include <dev/wscons/wsksymdef.h>
1564 #include <dev/wscons/wsksymvar.h>
1565 #include <sys/ioctl.h>
1566 int main(int argc, char **argv) {
1567 struct wskbd_map_data data;
1568 ioctl(0, WSKBDIO_GETMAP, &data);
1569 return 0;
1570 }" HAVE_INPUT_WSCONS)
1571 endif()
1572
1573 if(HAVE_LINUX_INPUT_H)
1574 set(SDL_INPUT_LINUXEV 1)
1575 endif()
1576
1577 if(SDL_HAPTIC AND HAVE_LINUX_INPUT_H)
1578 set(SDL_HAPTIC_LINUX 1)
1579 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
1580 list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
1581 set(HAVE_SDL_HAPTIC TRUE)
1582 endif()
1583
1584 if(HAVE_INPUT_KD)
1585 set(SDL_INPUT_LINUXKD 1)
1586 endif()
1587
1588 if(HAVE_INPUT_KBIO)
1589 set(SDL_INPUT_FBSDKBIO 1)
1590 endif()
1591
1592 if(HAVE_INPUT_WSCONS)
1593 set(SDL_INPUT_WSCONS 1)
1594 endif()
1595
1596 CheckLibUDev()
1597 check_include_file("sys/inotify.h" HAVE_SYS_INOTIFY_H)
1598 check_symbol_exists(inotify_init "sys/inotify.h" HAVE_INOTIFY_INIT)
1599 check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1)
1600
1601 if(HAVE_SYS_INOTIFY_H AND HAVE_INOTIFY_INIT)
1602 set(HAVE_INOTIFY 1)
1603 endif()
1604
1605 if(PKG_CONFIG_FOUND)
1606 if(SDL_DBUS)
1607 pkg_search_module(DBUS dbus-1 dbus)
1608 if(DBUS_FOUND)
1609 set(HAVE_DBUS_DBUS_H TRUE)
1610 target_include_directories(sdl-build-options INTERFACE "${DBUS_INCLUDE_DIRS}")
1611 # Fcitx need only dbus.
1612 set(HAVE_FCITX TRUE)
1613 set(HAVE_DBUS TRUE)
1614 endif()
1615 endif()
1616
1617 if(SDL_IBUS)
1618 pkg_search_module(IBUS ibus-1.0 ibus)
1619 find_path(HAVE_SYS_INOTIFY_H NAMES sys/inotify.h)
1620 if(IBUS_FOUND AND HAVE_SYS_INOTIFY_H)
1621 set(HAVE_IBUS_IBUS_H TRUE)
1622 target_include_directories(sdl-build-options INTERFACE "${IBUS_INCLUDE_DIRS}")
1623 set(HAVE_IBUS TRUE)
1624 endif()
1625 endif()
1626
1627 if (HAVE_IBUS_IBUS_H OR HAVE_FCITX)
1628 set(SDL_USE_IME 1)
1629 endif()
1630
1631 if(FREEBSD AND NOT HAVE_INOTIFY)
1632 pkg_search_module(INOTIFY libinotify)
1633 if(INOTIFY_FOUND)
1634 set(HAVE_INOTIFY 1)
1635 target_include_directories(sdl-build-options INTERFACE "${INOTIFY_INCLUDE_DIRS}")
1636 list(APPEND EXTRA_LIBS ${INOTIFY_LIBRARIES})
1637 endif()
1638 endif()
1639
1640 endif()
1641 CheckLibUnwind()
1642
1643 if(HAVE_DBUS_DBUS_H)
1644 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_dbus.c")
1645 endif()
1646
1647 if(SDL_USE_IME)
1648 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ime.c")
1649 endif()
1650
1651 if(HAVE_IBUS_IBUS_H)
1652 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ibus.c")
1653 endif()
1654
1655 if(HAVE_FCITX)
1656 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_fcitx.c")
1657 endif()
1658
1659 if(HAVE_LIBUDEV_H)
1660 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_udev.c")
1661 endif()
1662
1663 if(HAVE_LINUX_INPUT_H)
1664 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev.c")
1665 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev_kbd.c")
1666 endif()
1667
1668 if(HAVE_INPUT_KBIO)
1669 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/freebsd/SDL_evdev_kbd_freebsd.c")
1670 endif()
1671
1672 if(HAVE_INPUT_WSCONS)
1673 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/openbsd/SDL_wscons_kbd.c")
1674 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/openbsd/SDL_wscons_mouse.c")
1675 endif()
1676
1677 # Always compiled for Linux, unconditionally:
1678 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev_capabilities.c")
1679 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_threadprio.c")
1680 list(APPEND SOURCE_FILES "${SDL2_SOURCE_DIR}/src/core/linux/SDL_sandbox.c")
1681
1682 # src/core/unix/*.c is included in a generic if(UNIX) section, elsewhere.
1683 endif()
1684
1685 if(SDL_HIDAPI)
1686 CheckHIDAPI()
1687 endif()
1688
1689 if(SDL_JOYSTICK)
1690 if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
1691 CheckUSBHID()
1692 endif()
1693 if(LINUX AND HAVE_LINUX_INPUT_H AND NOT ANDROID)
1694 set(SDL_JOYSTICK_LINUX 1)
1695 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
1696 list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
1697 set(HAVE_SDL_JOYSTICK TRUE)
1698 endif()
1699 endif()
1700
1701 CheckPTHREAD()
1702
1703 if(SDL_CLOCK_GETTIME)
1704 check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME_LIBC)
1705 if(FOUND_CLOCK_GETTIME_LIBC)
1706 set(HAVE_CLOCK_GETTIME 1)
1707 else()
1708 check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME_LIBRT)
1709 if(FOUND_CLOCK_GETTIME_LIBRT)
1710 set(HAVE_CLOCK_GETTIME 1)
1711 list(APPEND EXTRA_LIBS rt)
1712 endif()
1713 endif()
1714 endif()
1715
1716 check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
1717 if(HAVE_LINUX_VERSION_H)
1718 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
1719 endif()
1720
1721 if(SDL_MISC)
1722 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/unix/*.c)
1723 list(APPEND SOURCE_FILES ${MISC_SOURCES})
1724 set(HAVE_SDL_MISC TRUE)
1725 endif()
1726
1727 if(SDL_POWER)
1728 if(LINUX)
1729 set(SDL_POWER_LINUX 1)
1730 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
1731 list(APPEND SOURCE_FILES ${POWER_SOURCES})
1732 set(HAVE_SDL_POWER TRUE)
1733 endif()
1734 endif()
1735
1736 if(SDL_LOCALE)
1737 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
1738 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
1739 set(HAVE_SDL_LOCALE TRUE)
1740 endif()
1741
1742 if(SDL_FILESYSTEM)
1743 set(SDL_FILESYSTEM_UNIX 1)
1744 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
1745 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
1746 set(HAVE_SDL_FILESYSTEM TRUE)
1747 endif()
1748
1749 if(SDL_TIMERS)
1750 set(SDL_TIMER_UNIX 1)
1751 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1752 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
1753 set(HAVE_SDL_TIMERS TRUE)
1754 endif()
1755
1756 set(SDL_RLD_FLAGS "")
1757 if(SDL_RPATH AND SDL_SHARED)
1758 if(BSDI OR FREEBSD OR LINUX OR NETBSD)
1759 set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
1760 check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
1761 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1762 if(HAVE_ENABLE_NEW_DTAGS)
1763 set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
1764 else()
1765 set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
1766 endif()
1767 elseif(SOLARIS)
1768 set(SDL_RLD_FLAGS "-R\${libdir}")
1769 endif()
1770 set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
1771 set(HAVE_RPATH TRUE)
1772 endif()
1773
1774 if(QNX)
1775 # QNX's *printf() family generates a SIGSEGV if NULL is passed for a string
1776 # specifier (on purpose), but SDL expects "(null)". Use the built-in
1777 # implementation.
1778 set(HAVE_VSNPRINTF 0)
1779 set(USE_POSIX_SPAWN 1)
1780 endif()
1781elseif(WINDOWS)
1782 find_program(WINDRES windres)
1783
1784 check_c_source_compiles("
1785 #include <windows.h>
1786 int main(int argc, char **argv) { return 0; }" HAVE_WIN32_CC)
1787
1788 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
1789 list(APPEND SOURCE_FILES ${CORE_SOURCES})
1790
1791 if(WINDOWS_STORE)
1792 file(GLOB WINRT_SOURCE_FILES ${SDL2_SOURCE_DIR}/src/core/winrt/*.c ${SDL2_SOURCE_DIR}/src/core/winrt/*.cpp)
1793 list(APPEND SOURCE_FILES ${WINRT_SOURCE_FILES})
1794 endif()
1795
1796 if(MSVC AND NOT SDL_LIBC)
1797 # Prevent codegen that would use the VC runtime libraries.
1798 set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-;/Gs1048576")
1799 if(NOT ARCH_64 AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
1800 set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE")
1801 endif()
1802 endif()
1803
1804 if(SDL_MISC)
1805 if(WINDOWS_STORE)
1806 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/winrt/*.cpp)
1807 else()
1808 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/windows/*.c)
1809 endif()
1810 list(APPEND SOURCE_FILES ${MISC_SOURCES})
1811 set(HAVE_SDL_MISC TRUE)
1812 endif()
1813
1814 # Check for DirectX
1815 if(SDL_DIRECTX)
1816 if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
1817 set(USE_WINSDK_DIRECTX TRUE)
1818 endif()
1819 if(NOT MINGW AND NOT USE_WINSDK_DIRECTX)
1820 if("$ENV{DXSDK_DIR}" STREQUAL "")
1821 message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
1822 endif()
1823 set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
1824 endif()
1825
1826 check_include_file(d3d9.h HAVE_D3D_H)
1827 check_include_file(d3d11_1.h HAVE_D3D11_H)
1828 check_c_source_compiles("
1829 #include <winsdkver.h>
1830 #include <sdkddkver.h>
1831 #include <d3d12.h>
1832 ID3D12Device1 *device;
1833 #if WDK_NTDDI_VERSION > 0x0A000008
1834 int main(int argc, char **argv) { return 0; }
1835 #endif" HAVE_D3D12_H)
1836 check_include_file(ddraw.h HAVE_DDRAW_H)
1837 check_include_file(dsound.h HAVE_DSOUND_H)
1838 check_include_file(dinput.h HAVE_DINPUT_H)
1839 if(WINDOWS_STORE OR SDL_CPU_ARM32)
1840 set(HAVE_DINPUT_H 0)
1841 endif()
1842 check_include_file(dxgi.h HAVE_DXGI_H)
1843 if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_D3D12_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H)
1844 set(HAVE_DIRECTX TRUE)
1845 if(NOT MINGW AND NOT USE_WINSDK_DIRECTX)
1846 # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
1847 target_link_directories(sdl-build-options INTERFACE "$$ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH}")
1848 target_include_directories(sdl-build-options INTERFACE "$ENV{DXSDK_DIR}\\Include")
1849 endif()
1850 endif()
1851 set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1852 endif()
1853
1854 if(SDL_XINPUT)
1855 # xinput.h may need windows.h, but does not include it itself.
1856 check_c_source_compiles("
1857 #include <windows.h>
1858 #include <xinput.h>
1859 int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_H)
1860 check_c_source_compiles("
1861 #define COBJMACROS
1862 #include <windows.gaming.input.h>
1863 __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2 *s2;
1864 int main(int argc, char **argv) { return 0; }" HAVE_WINDOWS_GAMING_INPUT_H)
1865 endif()
1866
1867 # headers needed elsewhere
1868 check_include_file(tpcshrd.h HAVE_TPCSHRD_H)
1869 check_include_file(roapi.h HAVE_ROAPI_H)
1870 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1871 check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
1872 check_include_file(sensorsapi.h HAVE_SENSORSAPI_H)
1873 check_include_file(shellscalingapi.h HAVE_SHELLSCALINGAPI_H)
1874
1875 if(SDL_AUDIO)
1876 if(NOT WINDOWS_STORE)
1877 set(SDL_AUDIO_DRIVER_WINMM 1)
1878 file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
1879 list(APPEND SOURCE_FILES ${WINMM_AUDIO_SOURCES})
1880 set(HAVE_SDL_AUDIO TRUE)
1881 endif()
1882
1883 if(HAVE_DSOUND_H AND NOT WINDOWS_STORE)
1884 set(SDL_AUDIO_DRIVER_DSOUND 1)
1885 file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
1886 list(APPEND SOURCE_FILES ${DSOUND_AUDIO_SOURCES})
1887 set(HAVE_SDL_AUDIO TRUE)
1888 endif()
1889
1890 if(SDL_WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H)
1891 set(SDL_AUDIO_DRIVER_WASAPI 1)
1892 set(HAVE_WASAPI TRUE)
1893 file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c)
1894 if(WINDOWS_STORE)
1895 list(APPEND WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/SDL_wasapi_winrt.cpp)
1896 endif()
1897 list(APPEND SOURCE_FILES ${WASAPI_AUDIO_SOURCES})
1898 set(HAVE_SDL_AUDIO TRUE)
1899 endif()
1900 endif()
1901
1902 if(SDL_VIDEO)
1903 # requires SDL_LOADSO on Windows (IME, DX, etc.)
1904 if(NOT SDL_LOADSO)
1905 message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
1906 endif()
1907 if(WINDOWS_STORE)
1908 set(SDL_VIDEO_DRIVER_WINRT 1)
1909 file(GLOB WIN_VIDEO_SOURCES
1910 ${SDL2_SOURCE_DIR}/src/video/winrt/*.c
1911 ${SDL2_SOURCE_DIR}/src/video/winrt/*.cpp
1912 ${SDL2_SOURCE_DIR}/src/render/direct3d11/*.cpp
1913 )
1914 else()
1915 set(SDL_VIDEO_DRIVER_WINDOWS 1)
1916 file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
1917 endif()
1918 list(APPEND SOURCE_FILES ${WIN_VIDEO_SOURCES})
1919
1920 if(SDL_RENDER_D3D AND HAVE_D3D_H AND NOT WINDOWS_STORE)
1921 set(SDL_VIDEO_RENDER_D3D 1)
1922 set(HAVE_RENDER_D3D TRUE)
1923 endif()
1924 if(SDL_RENDER_D3D AND HAVE_D3D11_H)
1925 set(SDL_VIDEO_RENDER_D3D11 1)
1926 set(HAVE_RENDER_D3D TRUE)
1927 endif()
1928 if(SDL_RENDER_D3D AND HAVE_D3D12_H AND NOT WINDOWS_STORE)
1929 set(SDL_VIDEO_RENDER_D3D12 1)
1930 set(HAVE_RENDER_D3D TRUE)
1931 endif()
1932 set(HAVE_SDL_VIDEO TRUE)
1933 endif()
1934
1935 if(SDL_THREADS)
1936 set(SDL_THREAD_GENERIC_COND_SUFFIX 1)
1937 set(SDL_THREAD_WINDOWS 1)
1938 list(APPEND SOURCE_FILES
1939 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c
1940 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syscond_cv.c
1941 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
1942 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
1943 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
1944 ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c)
1945 set(HAVE_SDL_THREADS TRUE)
1946 endif()
1947
1948 if(SDL_SENSOR AND HAVE_SENSORSAPI_H AND NOT WINDOWS_STORE)
1949 set(SDL_SENSOR_WINDOWS 1)
1950 set(HAVE_SDL_SENSORS TRUE)
1951 file(GLOB WINDOWS_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/windows/*.c)
1952 list(APPEND SOURCE_FILES ${WINDOWS_SENSOR_SOURCES})
1953 endif()
1954
1955 if(SDL_POWER)
1956 if(WINDOWS_STORE)
1957 set(SDL_POWER_WINRT 1)
1958 list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/power/winrt/SDL_syspower.cpp)
1959 else()
1960 set(SDL_POWER_WINDOWS 1)
1961 list(APPEND SOURCE_FILES ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
1962 set(HAVE_SDL_POWER TRUE)
1963 endif()
1964 endif()
1965
1966 if(SDL_LOCALE)
1967 if(WINDOWS_STORE)
1968 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/winrt/*.c)
1969 else()
1970 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/windows/*.c)
1971 endif()
1972 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
1973 set(HAVE_SDL_LOCALE TRUE)
1974 endif()
1975
1976 if(SDL_FILESYSTEM)
1977 set(SDL_FILESYSTEM_WINDOWS 1)
1978 if(WINDOWS_STORE)
1979 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/winrt/*.cpp)
1980 else()
1981 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
1982 endif()
1983 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
1984 set(HAVE_SDL_FILESYSTEM TRUE)
1985 endif()
1986
1987 # Libraries for Win32 native and MinGW
1988 if(NOT WINDOWS_STORE)
1989 list(APPEND EXTRA_LIBS kernel32 user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
1990 endif()
1991
1992 if(WINDOWS_STORE)
1993 list(APPEND EXTRA_LIBS
1994 -nodefaultlib:vccorlib$<$<CONFIG:Debug>:d>
1995 -nodefaultlib:msvcrt$<$<CONFIG:Debug>:d>
1996 vccorlib$<$<CONFIG:Debug>:d>.lib
1997 msvcrt$<$<CONFIG:Debug>:d>.lib
1998 )
1999 endif()
2000
2001 if(SDL_TIMERS)
2002 set(SDL_TIMER_WINDOWS 1)
2003 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
2004 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
2005 set(HAVE_SDL_TIMERS TRUE)
2006 endif()
2007
2008 if(SDL_LOADSO)
2009 set(SDL_LOADSO_WINDOWS 1)
2010 file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
2011 list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
2012 set(HAVE_SDL_LOADSO TRUE)
2013 endif()
2014
2015 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
2016 list(APPEND SOURCE_FILES ${CORE_SOURCES})
2017
2018 if(SDL_VIDEO)
2019 if(SDL_OPENGL AND NOT WINDOWS_STORE)
2020 set(SDL_VIDEO_OPENGL 1)
2021 set(SDL_VIDEO_OPENGL_WGL 1)
2022 set(SDL_VIDEO_RENDER_OGL 1)
2023 set(HAVE_OPENGL TRUE)
2024 endif()
2025
2026 if(SDL_OPENGLES)
2027 set(SDL_VIDEO_OPENGL_EGL 1)
2028 set(SDL_VIDEO_OPENGL_ES2 1)
2029 set(SDL_VIDEO_RENDER_OGL_ES2 1)
2030 set(HAVE_OPENGLES TRUE)
2031 endif()
2032
2033 if(SDL_VULKAN)
2034 set(SDL_VIDEO_VULKAN 1)
2035 set(HAVE_VULKAN TRUE)
2036 endif()
2037 endif()
2038
2039 if(SDL_HIDAPI)
2040 CheckHIDAPI()
2041 endif()
2042
2043 if(SDL_JOYSTICK)
2044 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
2045 list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
2046
2047 if(NOT WINDOWS_STORE)
2048 set(SDL_JOYSTICK_RAWINPUT 1)
2049 endif()
2050 if(HAVE_DINPUT_H)
2051 set(SDL_JOYSTICK_DINPUT 1)
2052 list(APPEND EXTRA_LIBS dinput8)
2053 endif()
2054 if(HAVE_XINPUT_H)
2055 if(NOT WINDOWS_STORE)
2056 set(SDL_JOYSTICK_XINPUT 1)
2057 set(HAVE_XINPUT TRUE)
2058 endif()
2059 if(HAVE_WINDOWS_GAMING_INPUT_H)
2060 set(SDL_JOYSTICK_WGI 1)
2061 endif()
2062 endif()
2063 set(HAVE_SDL_JOYSTICK TRUE)
2064
2065 if(SDL_HAPTIC)
2066 if((HAVE_DINPUT_H OR HAVE_XINPUT_H) AND NOT WINDOWS_STORE)
2067 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
2068 if(HAVE_DINPUT_H)
2069 set(SDL_HAPTIC_DINPUT 1)
2070 endif()
2071 if(HAVE_XINPUT_H)
2072 set(SDL_HAPTIC_XINPUT 1)
2073 endif()
2074 else()
2075 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
2076 set(SDL_HAPTIC_DUMMY 1)
2077 endif()
2078 list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
2079 set(HAVE_SDL_HAPTIC TRUE)
2080 endif()
2081 endif()
2082
2083 file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
2084 file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
2085 if(MINGW OR CYGWIN)
2086 if(NOT SDL2_DISABLE_SDL2MAIN)
2087 list(APPEND SDL_CFLAGS "-Dmain=SDL_main")
2088 list(INSERT SDL_LIBS 0 "-lSDL2main")
2089 endif(NOT SDL2_DISABLE_SDL2MAIN)
2090 list(INSERT SDL_LIBS 0 "-lmingw32" "-mwindows")
2091 endif()
2092
2093elseif(APPLE)
2094 # TODO: rework this all for proper MacOS X, iOS and Darwin support
2095
2096 # We always need these libs on macOS at the moment.
2097 # !!! FIXME: we need Carbon for some very old API calls in
2098 # !!! FIXME: src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
2099 # !!! FIXME: how to dump those.
2100 if(DARWIN OR MACOSX)
2101 set(SDL_FRAMEWORK_COCOA 1)
2102 set(SDL_FRAMEWORK_CARBON 1)
2103 endif()
2104 set(SDL_FRAMEWORK_FOUNDATION 1)
2105 set(SDL_FRAMEWORK_COREVIDEO 1)
2106
2107 # Requires the darwin file implementation
2108 if(SDL_FILE)
2109 file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
2110 list(APPEND SOURCE_FILES ${EXTRA_SOURCES})
2111 set(HAVE_SDL_FILE TRUE)
2112 endif()
2113
2114 if(IOS OR TVOS)
2115 file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/uikit/*.c)
2116 endif()
2117
2118 if(SDL_MISC)
2119 if(IOS OR TVOS)
2120 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/ios/*.m)
2121 else()
2122 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/macosx/*.m)
2123 endif()
2124 list(APPEND SOURCE_FILES ${MISC_SOURCES})
2125 set(HAVE_SDL_MISC TRUE)
2126 endif()
2127
2128 if(SDL_AUDIO)
2129 set(SDL_AUDIO_DRIVER_COREAUDIO 1)
2130 file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
2131 list(APPEND SOURCE_FILES ${AUDIO_SOURCES})
2132 set(HAVE_SDL_AUDIO TRUE)
2133 set(SDL_FRAMEWORK_COREAUDIO 1)
2134 set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
2135 set(SDL_FRAMEWORK_AVFOUNDATION 1)
2136 endif()
2137
2138 if(SDL_HIDAPI)
2139 CheckHIDAPI()
2140 endif()
2141
2142 if(SDL_JOYSTICK)
2143 file(GLOB MFI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
2144 if(IOS OR TVOS)
2145 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
2146 set(SDL_JOYSTICK_MFI 1)
2147 if(IOS)
2148 set(SDL_FRAMEWORK_COREMOTION 1)
2149 endif()
2150 set(SDL_FRAMEWORK_GAMECONTROLLER 1)
2151 set(SDL_FRAMEWORK_COREHAPTICS 1)
2152 else()
2153 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
2154 set_property(SOURCE ${MFI_JOYSTICK_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-weak")
2155 check_objc_source_compiles("
2156 #include <AvailabilityMacros.h>
2157 #include <TargetConditionals.h>
2158 #import <Foundation/Foundation.h>
2159 #import <GameController/GameController.h>
2160 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1080
2161 #error GameController framework doesn't work on this configuration
2162 #endif
2163 #if TARGET_CPU_X86
2164 #error GameController framework doesn't work on this configuration
2165 #endif
2166 int main() { return 0; }" HAVE_FRAMEWORK_GAMECONTROLLER)
2167 check_objc_source_compiles("
2168 #include <AvailabilityMacros.h>
2169 #include <TargetConditionals.h>
2170 #import <Foundation/Foundation.h>
2171 #import <CoreHaptics/CoreHaptics.h>
2172 int main() { return 0; }" HAVE_FRAMEWORK_COREHAPTICS)
2173 if(HAVE_FRAMEWORK_GAMECONTROLLER AND HAVE_FRAMEWORK_COREHAPTICS)
2174 # Only enable MFI if we also have CoreHaptics to ensure rumble works
2175 set(SDL_JOYSTICK_MFI 1)
2176 set(SDL_FRAMEWORK_GAMECONTROLLER 1)
2177 set(SDL_FRAMEWORK_COREHAPTICS 1)
2178 endif()
2179 set(SDL_JOYSTICK_IOKIT 1)
2180 set(SDL_FRAMEWORK_IOKIT 1)
2181 set(SDL_FRAMEWORK_FF 1)
2182 endif()
2183 list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES} ${MFI_JOYSTICK_SOURCES})
2184 set(HAVE_SDL_JOYSTICK TRUE)
2185 endif()
2186
2187 if(SDL_HAPTIC)
2188 if (IOS OR TVOS)
2189 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
2190 set(SDL_HAPTIC_DUMMY 1)
2191 else()
2192 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
2193 set(SDL_HAPTIC_IOKIT 1)
2194 set(SDL_FRAMEWORK_IOKIT 1)
2195 set(SDL_FRAMEWORK_FF 1)
2196 endif()
2197 list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
2198 set(HAVE_SDL_HAPTIC TRUE)
2199 endif()
2200
2201 if(SDL_POWER)
2202 if (IOS OR TVOS)
2203 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
2204 set(SDL_POWER_UIKIT 1)
2205 else()
2206 file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
2207 set(SDL_POWER_MACOSX 1)
2208 set(SDL_FRAMEWORK_IOKIT 1)
2209 endif()
2210 list(APPEND SOURCE_FILES ${POWER_SOURCES})
2211 set(HAVE_SDL_POWER TRUE)
2212 endif()
2213
2214 if(SDL_LOCALE)
2215 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/macosx/*.m)
2216 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
2217 set(HAVE_SDL_LOCALE TRUE)
2218 endif()
2219
2220 if(SDL_TIMERS)
2221 set(SDL_TIMER_UNIX 1)
2222 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
2223 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
2224 set(HAVE_SDL_TIMERS TRUE)
2225 endif(SDL_TIMERS)
2226
2227 if(SDL_FILESYSTEM)
2228 set(SDL_FILESYSTEM_COCOA 1)
2229 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
2230 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
2231 set(HAVE_SDL_FILESYSTEM TRUE)
2232 endif()
2233
2234 if(SDL_SENSOR)
2235 if(IOS)
2236 set(SDL_SENSOR_COREMOTION 1)
2237 set(HAVE_SDL_SENSORS TRUE)
2238 file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
2239 list(APPEND SOURCE_FILES ${SENSOR_SOURCES})
2240 endif()
2241 endif()
2242
2243 # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
2244 if(SDL_VIDEO)
2245 if (IOS OR TVOS)
2246 set(SDL_VIDEO_DRIVER_UIKIT 1)
2247 set(SDL_FRAMEWORK_COREGRAPHICS 1)
2248 set(SDL_FRAMEWORK_QUARTZCORE 1)
2249 set(SDL_FRAMEWORK_UIKIT 1)
2250 set(SDL_IPHONE_KEYBOARD 1)
2251 set(SDL_IPHONE_LAUNCHSCREEN 1)
2252 file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
2253 list(APPEND SOURCE_FILES ${UIKITVIDEO_SOURCES})
2254 set(HAVE_SDL_VIDEO TRUE)
2255 else()
2256 CheckCOCOA()
2257 if(SDL_OPENGL)
2258 set(SDL_VIDEO_OPENGL 1)
2259 set(SDL_VIDEO_OPENGL_CGL 1)
2260 set(SDL_VIDEO_RENDER_OGL 1)
2261 set(HAVE_OPENGL TRUE)
2262 endif()
2263 endif()
2264
2265 if(SDL_OPENGLES)
2266 if(IOS OR TVOS)
2267 set(SDL_FRAMEWORK_OPENGLES 1)
2268 set(SDL_VIDEO_OPENGL_ES 1)
2269 set(SDL_VIDEO_RENDER_OGL_ES 1)
2270 else()
2271 set(SDL_VIDEO_OPENGL_EGL 1)
2272 endif()
2273 set(SDL_VIDEO_OPENGL_ES2 1)
2274 set(SDL_VIDEO_RENDER_OGL_ES2 1)
2275 set(HAVE_OPENGLES TRUE)
2276 endif()
2277
2278 if(SDL_VULKAN OR SDL_METAL OR SDL_RENDER_METAL)
2279 check_objc_source_compiles("
2280 #include <AvailabilityMacros.h>
2281 #import <Metal/Metal.h>
2282 #import <QuartzCore/CAMetalLayer.h>
2283
2284 #if (!TARGET_CPU_X86_64 && !TARGET_CPU_ARM64)
2285 #error Metal doesn't work on this configuration
2286 #endif
2287 int main(int argc, char **argv) { return 0; }" HAVE_FRAMEWORK_METAL)
2288 if(HAVE_FRAMEWORK_METAL)
2289 set(SDL_FRAMEWORK_METAL 1)
2290 set(SDL_FRAMEWORK_QUARTZCORE 1)
2291 if(SDL_VULKAN)
2292 set(SDL_VIDEO_VULKAN 1)
2293 set(HAVE_VULKAN TRUE)
2294 endif()
2295 if(SDL_METAL)
2296 set(SDL_VIDEO_METAL 1)
2297 set(HAVE_METAL TRUE)
2298 endif()
2299 if(SDL_RENDER_METAL)
2300 file(GLOB RENDER_METAL_SOURCES ${SDL2_SOURCE_DIR}/src/render/metal/*.m)
2301 list(APPEND SOURCE_FILES ${RENDER_METAL_SOURCES})
2302 set(SDL_VIDEO_RENDER_METAL 1)
2303 set(HAVE_RENDER_METAL TRUE)
2304 endif()
2305 endif()
2306 endif()
2307 endif()
2308
2309 # Actually load the frameworks at the end so we don't duplicate include.
2310 if(SDL_FRAMEWORK_COREVIDEO)
2311 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreVideo")
2312 endif()
2313 if(SDL_FRAMEWORK_COCOA)
2314 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Cocoa")
2315 endif()
2316 if(SDL_FRAMEWORK_IOKIT)
2317 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,IOKit")
2318 endif()
2319 if(SDL_FRAMEWORK_FF)
2320 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,ForceFeedback")
2321 endif()
2322 if(SDL_FRAMEWORK_CARBON)
2323 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Carbon")
2324 endif()
2325 if(SDL_FRAMEWORK_COREAUDIO)
2326 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreAudio")
2327 endif()
2328 if(SDL_FRAMEWORK_AUDIOTOOLBOX)
2329 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,AudioToolbox")
2330 endif()
2331 if(SDL_FRAMEWORK_AVFOUNDATION)
2332 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,AVFoundation")
2333 endif()
2334 if(SDL_FRAMEWORK_COREBLUETOOTH)
2335 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreBluetooth")
2336 endif()
2337 if(SDL_FRAMEWORK_COREGRAPHICS)
2338 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreGraphics")
2339 endif()
2340 if(SDL_FRAMEWORK_COREMOTION)
2341 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,CoreMotion")
2342 endif()
2343 if(SDL_FRAMEWORK_FOUNDATION)
2344 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Foundation")
2345 endif()
2346 if(SDL_FRAMEWORK_GAMECONTROLLER)
2347 find_library(GAMECONTROLLER GameController)
2348 if(GAMECONTROLLER)
2349 list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,GameController")
2350 endif()
2351 endif()
2352 if(SDL_FRAMEWORK_METAL)
2353 if(IOS OR TVOS)
2354 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,Metal")
2355 else()
2356 list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,Metal")
2357 endif()
2358 endif()
2359 if(SDL_FRAMEWORK_OPENGLES)
2360 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,OpenGLES")
2361 endif()
2362 if(SDL_FRAMEWORK_QUARTZCORE)
2363 if(IOS OR TVOS)
2364 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,QuartzCore")
2365 else()
2366 list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,QuartzCore")
2367 endif()
2368 endif()
2369 if(SDL_FRAMEWORK_UIKIT)
2370 list(APPEND EXTRA_LDFLAGS "-Wl,-framework,UIKit")
2371 endif()
2372 if(SDL_FRAMEWORK_COREHAPTICS)
2373 find_library(COREHAPTICS CoreHaptics)
2374 if(COREHAPTICS)
2375 list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,CoreHaptics")
2376 endif()
2377 endif()
2378
2379 CheckPTHREAD()
2380
2381elseif(HAIKU)
2382 if(SDL_AUDIO)
2383 set(SDL_AUDIO_DRIVER_HAIKU 1)
2384 file(GLOB HAIKU_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/haiku/*.cc)
2385 list(APPEND SOURCE_FILES ${HAIKU_AUDIO_SOURCES})
2386 set(HAVE_SDL_AUDIO TRUE)
2387 endif()
2388
2389 if(SDL_JOYSTICK)
2390 set(SDL_JOYSTICK_HAIKU 1)
2391 file(GLOB HAIKU_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/haiku/*.cc)
2392 list(APPEND SOURCE_FILES ${HAIKU_JOYSTICK_SOURCES})
2393 set(HAVE_SDL_JOYSTICK TRUE)
2394 endif()
2395
2396 if(SDL_MISC)
2397 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/haiku/*.cc)
2398 list(APPEND SOURCE_FILES ${MISC_SOURCES})
2399 set(HAVE_SDL_MISC TRUE)
2400 endif()
2401
2402 if(SDL_VIDEO)
2403 set(SDL_VIDEO_DRIVER_HAIKU 1)
2404 file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.cc)
2405 list(APPEND SOURCE_FILES ${HAIKUVIDEO_SOURCES})
2406 set(HAVE_SDL_VIDEO TRUE)
2407
2408 if(SDL_OPENGL)
2409 # TODO: Use FIND_PACKAGE(OpenGL) instead
2410 set(SDL_VIDEO_OPENGL 1)
2411 set(SDL_VIDEO_OPENGL_HAIKU 1)
2412 set(SDL_VIDEO_RENDER_OGL 1)
2413 list(APPEND EXTRA_LIBS GL)
2414 set(HAVE_OPENGL TRUE)
2415 endif()
2416 endif()
2417
2418 if(SDL_FILESYSTEM)
2419 set(SDL_FILESYSTEM_HAIKU 1)
2420 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
2421 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
2422 set(HAVE_SDL_FILESYSTEM TRUE)
2423 endif()
2424
2425 if(SDL_TIMERS)
2426 set(SDL_TIMER_HAIKU 1)
2427 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
2428 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
2429 set(HAVE_SDL_TIMERS TRUE)
2430 endif()
2431
2432 if(SDL_POWER)
2433 set(SDL_POWER_HAIKU 1)
2434 file(GLOB HAIKU_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/haiku/*.c)
2435 list(APPEND SOURCE_FILES ${HAIKU_POWER_SOURCES})
2436 set(HAVE_SDL_POWER TRUE)
2437 endif()
2438
2439 if(SDL_LOCALE)
2440 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/haiku/*.cc)
2441 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
2442 set(HAVE_SDL_LOCALE TRUE)
2443 endif()
2444
2445 file(GLOB MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/haiku/*.cc)
2446 list(APPEND SOURCE_FILES ${MAIN_SOURCES})
2447
2448 CheckPTHREAD()
2449 list(APPEND EXTRA_LIBS root be media game device textencoding)
2450
2451elseif(RISCOS)
2452 if(SDL_MISC)
2453 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/riscos/*.c)
2454 list(APPEND SOURCE_FILES ${MISC_SOURCES})
2455 set(HAVE_SDL_MISC TRUE)
2456 endif()
2457
2458 if(SDL_VIDEO)
2459 set(SDL_VIDEO_DRIVER_RISCOS 1)
2460 file(GLOB RISCOSVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/riscos/*.c)
2461 list(APPEND SOURCE_FILES ${RISCOSVIDEO_SOURCES})
2462 set(HAVE_SDL_VIDEO TRUE)
2463 endif()
2464
2465 if(SDL_FILESYSTEM)
2466 set(SDL_FILESYSTEM_RISCOS 1)
2467 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/riscos/*.c)
2468 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
2469 set(HAVE_SDL_FILESYSTEM TRUE)
2470 endif()
2471
2472 if(SDL_TIMERS)
2473 set(SDL_TIMER_UNIX 1)
2474 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
2475 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
2476 set(HAVE_SDL_TIMERS TRUE)
2477
2478 if(SDL_CLOCK_GETTIME)
2479 set(HAVE_CLOCK_GETTIME 1)
2480 endif()
2481 endif()
2482
2483 CheckPTHREAD()
2484
2485 if(SDL_AUDIO)
2486 CheckOSS()
2487 endif()
2488
2489elseif(VITA)
2490 # SDL_spinlock.c Needs to be compiled in ARM mode.
2491 cmake_push_check_state(RESET)
2492 set(CMAKE_REQUIRED_FLAGS "-Werror=unused-command-line-argument")
2493 check_c_compiler_flag(-marm HAVE_ARM_MODE)
2494 if(HAVE_ARM_MODE)
2495 set_property(SOURCE "${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -marm")
2496 endif()
2497 cmake_pop_check_state()
2498
2499 if(SDL_MISC)
2500 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/vita/*.c)
2501 list(APPEND SOURCE_FILES ${MISC_SOURCES})
2502 set(HAVE_SDL_MISC TRUE)
2503 endif()
2504
2505 if(SDL_AUDIO)
2506 set(SDL_AUDIO_DRIVER_VITA 1)
2507 file(GLOB VITA_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/vita/*.c)
2508 list(APPEND SOURCE_FILES ${VITA_AUDIO_SOURCES})
2509 set(HAVE_SDL_AUDIO TRUE)
2510 endif()
2511 if(SDL_FILESYSTEM)
2512 set(SDL_FILESYSTEM_VITA 1)
2513 file(GLOB VITA_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/vita/*.c)
2514 list(APPEND SOURCE_FILES ${VITA_FILESYSTEM_SOURCES})
2515 set(HAVE_SDL_FILESYSTEM TRUE)
2516 endif()
2517 if(SDL_JOYSTICK)
2518 set(SDL_JOYSTICK_VITA 1)
2519 file(GLOB VITA_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/vita/*.c)
2520 list(APPEND SOURCE_FILES ${VITA_JOYSTICK_SOURCES})
2521 set(HAVE_SDL_JOYSTICK TRUE)
2522 endif()
2523 if(SDL_POWER)
2524 set(SDL_POWER_VITA 1)
2525 file(GLOB VITA_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/vita/*.c)
2526 list(APPEND SOURCE_FILES ${VITA_POWER_SOURCES})
2527 set(HAVE_SDL_POWER TRUE)
2528 endif()
2529 if(SDL_THREADS)
2530 set(SDL_THREAD_VITA 1)
2531 list(APPEND SOURCE_FILES
2532 ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_sysmutex.c
2533 ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_syssem.c
2534 ${SDL2_SOURCE_DIR}/src/thread/vita/SDL_systhread.c
2535 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c
2536 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c)
2537 set(HAVE_SDL_THREADS TRUE)
2538 endif()
2539 if(SDL_LOCALE)
2540 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/vita/*.c)
2541 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
2542 set(HAVE_SDL_LOCALE TRUE)
2543 endif()
2544 if(SDL_TIMERS)
2545 set(SDL_TIMER_VITA 1)
2546 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/vita/*.c)
2547 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
2548 set(HAVE_SDL_TIMERS TRUE)
2549 endif()
2550 if(SDL_SENSOR)
2551 set(SDL_SENSOR_VITA 1)
2552 set(HAVE_SDL_SENSORS TRUE)
2553 file(GLOB VITA_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/vita/*.c)
2554 list(APPEND SOURCE_FILES ${VITA_SENSOR_SOURCES})
2555 endif()
2556 if(SDL_VIDEO)
2557 set(SDL_VIDEO_DRIVER_VITA 1)
2558 file(GLOB VITA_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/vita/*.c)
2559 list(APPEND SOURCE_FILES ${VITA_VIDEO_SOURCES})
2560 set(HAVE_SDL_VIDEO TRUE)
2561
2562 if(VIDEO_VITA_PIB)
2563 check_include_file(pib.h HAVE_PIGS_IN_BLANKET_H)
2564
2565 if(HAVE_PIGS_IN_BLANKET_H)
2566 set(SDL_VIDEO_OPENGL_ES2 1)
2567 list(APPEND EXTRA_LIBS
2568 pib
2569 libScePiglet_stub_weak
2570 taihen_stub_weak
2571 SceShaccCg_stub_weak
2572 )
2573 set(HAVE_VIDEO_VITA_PIB ON)
2574 set(SDL_VIDEO_VITA_PIB 1)
2575 else()
2576 set(HAVE_VIDEO_VITA_PIB OFF)
2577 endif()
2578 endif()
2579
2580 if(VIDEO_VITA_PVR)
2581 check_include_file(gpu_es4/psp2_pvr_hint.h HAVE_PVR_H)
2582 if(HAVE_PVR_H)
2583 target_compile_definitions(sdl-build-options INTERFACE "-D__psp2__")
2584 set(SDL_VIDEO_OPENGL_EGL 1)
2585 set(HAVE_OPENGLES TRUE)
2586 set(SDL_VIDEO_OPENGL_ES 1)
2587 set(SDL_VIDEO_RENDER_OGL_ES 1)
2588 set(SDL_VIDEO_OPENGL_ES2 1)
2589 set(SDL_VIDEO_RENDER_OGL_ES2 1)
2590
2591 list(APPEND EXTRA_LIBS
2592 libgpu_es4_ext_stub_weak
2593 libIMGEGL_stub_weak
2594 SceIme_stub
2595 )
2596
2597 set(HAVE_VIDEO_VITA_PVR ON)
2598 set(SDL_VIDEO_VITA_PVR 1)
2599
2600 if(SDL_OPENGL)
2601 check_include_file(gl4esinit.h HAVE_GL4ES_H)
2602 if(HAVE_GL4ES_H)
2603 set(HAVE_OPENGL TRUE)
2604 set(SDL_VIDEO_OPENGL 1)
2605 set(SDL_VIDEO_RENDER_OGL 1)
2606 list(APPEND EXTRA_LIBS libGL_stub)
2607 set(SDL_VIDEO_VITA_PVR_OGL 1)
2608 endif()
2609 endif()
2610
2611 else()
2612 set(HAVE_VIDEO_VITA_PVR OFF)
2613 endif()
2614 endif()
2615
2616 set(SDL_VIDEO_RENDER_VITA_GXM 1)
2617
2618 list(APPEND EXTRA_LIBS
2619 SceGxm_stub
2620 SceDisplay_stub
2621 SceCtrl_stub
2622 SceAppMgr_stub
2623 SceAppUtil_stub
2624 SceAudio_stub
2625 SceAudioIn_stub
2626 SceSysmodule_stub
2627 SceDisplay_stub
2628 SceCtrl_stub
2629 SceIofilemgr_stub
2630 SceCommonDialog_stub
2631 SceTouch_stub
2632 SceHid_stub
2633 SceMotion_stub
2634 ScePower_stub
2635 SceProcessmgr_stub
2636 m
2637 )
2638 endif()
2639
2640 set(HAVE_ARMSIMD TRUE)
2641# set(SDL_ARM_SIMD_BLITTERS 1)
2642# file(GLOB ARMSIMD_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S)
2643# list(APPEND SOURCE_FILES ${ARMSIMD_SOURCES})
2644
2645 set(HAVE_ARMNEON TRUE)
2646# set(SDL_ARM_NEON_BLITTERS 1)
2647# file(GLOB ARMNEON_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S)
2648# list(APPEND SOURCE_FILES ${ARMNEON_SOURCES})
2649
2650# set_property(SOURCE ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd-asm.S PROPERTY LANGUAGE C)
2651# set_property(SOURCE ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon-asm.S PROPERTY LANGUAGE C)
2652
2653 target_compile_definitions(sdl-build-options INTERFACE "-D__VITA__")
2654
2655# CheckPTHREAD()
2656
2657elseif(PSP)
2658 file(GLOB PSP_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/psp/*.c)
2659 list(APPEND SDLMAIN_SOURCES ${PSP_MAIN_SOURCES})
2660
2661 if(SDL_AUDIO)
2662 set(SDL_AUDIO_DRIVER_PSP 1)
2663 file(GLOB PSP_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/psp/*.c)
2664 list(APPEND SOURCE_FILES ${PSP_AUDIO_SOURCES})
2665 set(HAVE_SDL_AUDIO TRUE)
2666 endif()
2667 if(SDL_FILESYSTEM)
2668 set(SDL_FILESYSTEM_PSP 1)
2669 file(GLOB PSP_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/psp/*.c)
2670 list(APPEND SOURCE_FILES ${PSP_FILESYSTEM_SOURCES})
2671 set(HAVE_SDL_FILESYSTEM TRUE)
2672 endif()
2673 if(SDL_JOYSTICK)
2674 set(SDL_JOYSTICK_PSP 1)
2675 file(GLOB PSP_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/psp/*.c)
2676 list(APPEND SOURCE_FILES ${PSP_JOYSTICK_SOURCES})
2677 set(HAVE_SDL_JOYSTICK TRUE)
2678 endif()
2679 if(SDL_POWER)
2680 set(SDL_POWER_PSP 1)
2681 file(GLOB PSP_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/psp/*.c)
2682 list(APPEND SOURCE_FILES ${PSP_POWER_SOURCES})
2683 set(HAVE_SDL_POWER TRUE)
2684 endif()
2685 if(SDL_THREADS)
2686 set(SDL_THREAD_PSP 1)
2687 file(GLOB PSP_THREAD_SOURCES
2688 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c
2689 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c
2690 ${SDL2_SOURCE_DIR}/src/thread/psp/*.c)
2691 list(APPEND SOURCE_FILES ${PSP_THREAD_SOURCES})
2692 set(HAVE_SDL_THREADS TRUE)
2693 endif()
2694 if(SDL_TIMERS)
2695 set(SDL_TIMER_PSP 1)
2696 file(GLOB PSP_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/psp/*.c)
2697 list(APPEND SOURCE_FILES ${PSP_TIMER_SOURCES})
2698 set(HAVE_SDL_TIMERS TRUE)
2699 endif()
2700 if(SDL_VIDEO)
2701 set(SDL_VIDEO_DRIVER_PSP 1)
2702 set(SDL_VIDEO_RENDER_PSP 1)
2703 file(GLOB PSP_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/psp/*.c)
2704 list(APPEND SOURCE_FILES ${PSP_VIDEO_SOURCES})
2705 set(SDL_VIDEO_OPENGL 1)
2706 set(HAVE_SDL_VIDEO TRUE)
2707 endif()
2708
2709 list(APPEND EXTRA_LIBS
2710 GL
2711 pspvram
2712 pspaudio
2713 pspvfpu
2714 pspdisplay
2715 pspgu
2716 pspge
2717 psphprm
2718 pspctrl
2719 psppower
2720 )
2721 if(NOT SDL2_DISABLE_SDL2MAIN)
2722 list(INSERT SDL_LIBS 0 "-lSDL2main")
2723 endif()
2724
2725elseif(PS2)
2726 list(APPEND EXTRA_CFLAGS "-DPS2" "-D__PS2__" "-I$ENV{PS2SDK}/ports/include" "-I$ENV{PS2DEV}/gsKit/include")
2727
2728 file(GLOB PS2_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/ps2/*.c)
2729 set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${PS2_MAIN_SOURCES})
2730
2731 if(SDL_AUDIO)
2732 set(SDL_AUDIO_DRIVER_PS2 1)
2733 file(GLOB PS2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/ps2/*.c)
2734 set(SOURCE_FILES ${SOURCE_FILES} ${PS2_AUDIO_SOURCES})
2735 set(HAVE_SDL_AUDIO TRUE)
2736 endif()
2737 if(SDL_FILESYSTEM)
2738 set(SDL_FILESYSTEM_PS2 1)
2739 file(GLOB PS2_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/ps2/*.c)
2740 list(APPEND SOURCE_FILES ${PS2_FILESYSTEM_SOURCES})
2741 set(HAVE_SDL_FILESYSTEM TRUE)
2742 endif()
2743 if(SDL_JOYSTICK)
2744 set(SDL_JOYSTICK_PS2 1)
2745 file(GLOB PS2_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/ps2/*.c)
2746 list(APPEND SOURCE_FILES ${PS2_JOYSTICK_SOURCES})
2747 set(HAVE_SDL_JOYSTICK TRUE)
2748 endif()
2749 if(SDL_THREADS)
2750 set(SDL_THREAD_PS2 1)
2751 file(GLOB PS2_THREAD_SOURCES
2752 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c
2753 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_sysmutex.c
2754 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c
2755 ${SDL2_SOURCE_DIR}/src/thread/ps2/*.c)
2756 list(APPEND SOURCE_FILES ${PS2_THREAD_SOURCES})
2757 set(HAVE_SDL_THREADS TRUE)
2758 endif()
2759 if(SDL_TIMERS)
2760 set(SDL_TIMER_PS2 1)
2761 file(GLOB PS2_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/ps2/*.c)
2762 list(APPEND SOURCE_FILES ${PS2_TIMER_SOURCES})
2763 set(HAVE_SDL_TIMERS TRUE)
2764 endif()
2765 if(SDL_VIDEO)
2766 set(SDL_VIDEO_DRIVER_PS2 1)
2767 set(SDL_VIDEO_RENDER_PS2 1)
2768 file(GLOB PS2_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/ps2/*.c ${SDL2_SOURCE_DIR}/src/render/ps2/*.c)
2769 list(APPEND SOURCE_FILES ${PS2_VIDEO_SOURCES})
2770 set(SDL_VIDEO_OPENGL 0)
2771 set(HAVE_SDL_VIDEO TRUE)
2772 endif()
2773
2774 list(APPEND EXTRA_LIBS
2775 patches
2776 gskit
2777 dmakit
2778 ps2_drivers
2779 )
2780
2781elseif(OS2)
2782 list(APPEND EXTRA_CFLAGS "-DOS2EMX_PLAIN_CHAR")
2783
2784 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/os2/*.c)
2785 list(APPEND SOURCE_FILES ${CORE_SOURCES})
2786 if(NOT (HAVE_ICONV AND HAVE_ICONV_H))
2787 file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/os2/geniconv/*.c)
2788 list(APPEND SOURCE_FILES ${CORE_SOURCES})
2789 endif()
2790
2791 if(SDL_THREADS)
2792 set(SDL_THREAD_OS2 1)
2793 file(GLOB OS2_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/os2/*.c)
2794 list(APPEND SOURCE_FILES ${OS2_THREAD_SOURCES})
2795 set(HAVE_SDL_THREADS TRUE)
2796 endif()
2797
2798 if(SDL_TIMERS)
2799 set(SDL_TIMER_UNIX 1)
2800 file(GLOB OS2_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/os2/*.c)
2801 list(APPEND SOURCE_FILES ${OS2_TIMER_SOURCES})
2802 set(HAVE_SDL_TIMERS TRUE)
2803 endif()
2804
2805 if(SDL_LOADSO)
2806 set(SDL_LOADSO_OS2 1)
2807 file(GLOB OS2_LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/os2/*.c)
2808 list(APPEND SOURCE_FILES ${OS2_LOADSO_SOURCES})
2809 set(HAVE_SDL_LOADSO TRUE)
2810 endif()
2811
2812 if(SDL_FILESYSTEM)
2813 set(SDL_FILESYSTEM_OS2 1)
2814 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/os2/*.c)
2815 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
2816 set(HAVE_SDL_FILESYSTEM TRUE)
2817 endif()
2818
2819 if(SDL_LOCALE)
2820 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
2821 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
2822 set(HAVE_SDL_LOCALE TRUE)
2823 endif()
2824
2825 if(SDL_VIDEO)
2826 set(SDL_VIDEO_DRIVER_OS2 1)
2827 file(GLOB OS2_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/os2/*.c)
2828 list(APPEND SOURCE_FILES ${OS2_VIDEO_SOURCES})
2829 set(HAVE_SDL_VIDEO TRUE)
2830 endif()
2831
2832 if(SDL_AUDIO)
2833 set(SDL_AUDIO_DRIVER_OS2 1)
2834 file(GLOB OS2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/os2/*.c)
2835 list(APPEND SOURCE_FILES ${OS2_AUDIO_SOURCES})
2836 set(HAVE_SDL_AUDIO TRUE)
2837 list(APPEND EXTRA_LIBS mmpm2)
2838 endif()
2839
2840 if(SDL_JOYSTICK)
2841 set(SDL_JOYSTICK_OS2 1)
2842 file(GLOB OS2_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/os2/*.c)
2843 list(APPEND SOURCE_FILES ${OS2_JOYSTICK_SOURCES})
2844 set(HAVE_SDL_JOYSTICK TRUE)
2845 endif()
2846
2847 if(SDL_HIDAPI)
2848 CheckHIDAPI()
2849 endif()
2850
2851elseif(N3DS)
2852 file(GLOB N3DS_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/n3ds/*.c)
2853 set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${N3DS_MAIN_SOURCES})
2854
2855 if(SDL_AUDIO)
2856 set(SDL_AUDIO_DRIVER_N3DS 1)
2857 file(GLOB N3DS_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/n3ds/*.c)
2858 list(APPEND SOURCE_FILES ${N3DS_AUDIO_SOURCES})
2859 set(HAVE_SDL_AUDIO TRUE)
2860 endif()
2861
2862 if(SDL_FILESYSTEM)
2863 set(SDL_FILESYSTEM_N3DS 1)
2864 file(GLOB N3DS_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/n3ds/*.c)
2865 list(APPEND SOURCE_FILES ${N3DS_FILESYSTEM_SOURCES})
2866 set(HAVE_SDL_FILESYSTEM TRUE)
2867 endif()
2868
2869 if(SDL_JOYSTICK)
2870 set(SDL_JOYSTICK_N3DS 1)
2871 file(GLOB N3DS_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/n3ds/*.c)
2872 list(APPEND SOURCE_FILES ${N3DS_JOYSTICK_SOURCES})
2873 set(HAVE_SDL_JOYSTICK TRUE)
2874 endif()
2875
2876 if(SDL_POWER)
2877 set(SDL_POWER_N3DS 1)
2878 file(GLOB N3DS_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/n3ds/*.c)
2879 list(APPEND SOURCE_FILES ${N3DS_POWER_SOURCES})
2880 set(HAVE_SDL_POWER TRUE)
2881 endif()
2882
2883 if(SDL_THREADS)
2884 set(SDL_THREAD_N3DS 1)
2885 file(GLOB N3DS_THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/n3ds/*.c)
2886 list(APPEND SOURCE_FILES ${N3DS_THREAD_SOURCES}
2887 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c
2888 ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
2889 set(HAVE_SDL_THREADS TRUE)
2890 endif()
2891
2892 if(SDL_TIMERS)
2893 set(SDL_TIMER_N3DS 1)
2894 file(GLOB N3DS_TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/n3ds/*.c)
2895 list(APPEND SOURCE_FILES ${N3DS_TIMER_SOURCES})
2896 set(HAVE_SDL_TIMERS TRUE)
2897 endif()
2898
2899 if(SDL_SENSOR)
2900 set(SDL_SENSOR_N3DS 1)
2901 file(GLOB N3DS_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/n3ds/*.c)
2902 list(APPEND SOURCE_FILES ${N3DS_SENSOR_SOURCES})
2903 set(HAVE_SDL_SENSORS TRUE)
2904 endif()
2905
2906 if(SDL_VIDEO)
2907 set(SDL_VIDEO_DRIVER_N3DS 1)
2908 file(GLOB N3DS_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/n3ds/*.c)
2909 list(APPEND SOURCE_FILES ${N3DS_VIDEO_SOURCES})
2910 set(HAVE_SDL_VIDEO TRUE)
2911 endif()
2912
2913 if(SDL_LOCALE)
2914 file(GLOB N3DS_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/n3ds/*.c)
2915 list(APPEND SOURCE_FILES ${N3DS_LOCALE_SOURCES})
2916 set(HAVE_SDL_LOCALE TRUE)
2917 endif()
2918
2919 # Requires the n3ds file implementation
2920 if(SDL_FILE)
2921 file(GLOB N3DS_FILE_SOURCES ${SDL2_SOURCE_DIR}/src/file/n3ds/*.c)
2922 list(APPEND SOURCE_FILES ${N3DS_FILE_SOURCES})
2923 set(HAVE_SDL_FILE TRUE)
2924 else()
2925 message_error("SDL_FILE must be enabled to build on N3DS")
2926 endif()
2927
2928 if(NOT SDL2_DISABLE_SDL2MAIN)
2929 list(INSERT SDL_LIBS 0 "-lSDL2main")
2930 endif()
2931
2932 foreach(lib ${CMAKE_C_STANDARD_LIBRARIES})
2933 if(lib MATCHES "^-l")
2934 string(SUBSTRING "${lib}" 2 -1 lib)
2935 endif()
2936 list(APPEND EXTRA_LIBS ${lib})
2937 endforeach()
2938endif()
2939
2940if(HAVE_VULKAN AND NOT SDL_LOADSO)
2941 message(STATUS "Vulkan support is available, but disabled because there's no loadso.")
2942 set(HAVE_VULKAN FALSE)
2943 set(SDL_VIDEO_VULKAN 0)
2944endif()
2945
2946# Platform-independent options
2947CheckLibSampleRate()
2948
2949# Dummies
2950# configure.ac does it differently:
2951# if not have X
2952# if enable_X { SDL_X_DISABLED = 1 }
2953# [add dummy sources]
2954# so it always adds a dummy, without checking, if it was actually requested.
2955# This leads to missing internal references on building, since the
2956# src/X/*.c does not get included.
2957if(NOT HAVE_SDL_AUDIO)
2958 set(SDL_AUDIO_DRIVER_DUMMY 1)
2959 file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
2960 list(APPEND SOURCE_FILES ${AUDIO_SOURCES})
2961endif()
2962if(NOT HAVE_SDL_VIDEO)
2963 set(SDL_VIDEO_DRIVER_DUMMY 1)
2964 file(GLOB VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
2965 list(APPEND SOURCE_FILES ${VIDEO_SOURCES})
2966endif()
2967if(NOT HAVE_SDL_JOYSTICK)
2968 set(SDL_JOYSTICK_DUMMY 1)
2969 file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
2970 list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES})
2971endif()
2972if(NOT HAVE_SDL_HAPTIC)
2973 set(SDL_HAPTIC_DUMMY 1)
2974 file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
2975 list(APPEND SOURCE_FILES ${HAPTIC_SOURCES})
2976endif()
2977if(NOT HAVE_SDL_SENSORS)
2978 set(SDL_SENSOR_DUMMY 1)
2979 file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c)
2980 list(APPEND SOURCE_FILES ${SENSORS_SOURCES})
2981endif()
2982if(NOT HAVE_SDL_LOADSO)
2983 set(SDL_LOADSO_DUMMY 1)
2984 file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
2985 list(APPEND SOURCE_FILES ${LOADSO_SOURCES})
2986endif()
2987if(NOT HAVE_SDL_FILESYSTEM)
2988 set(SDL_FILESYSTEM_DUMMY 1)
2989 file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
2990 list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES})
2991endif()
2992if(NOT HAVE_SDL_LOCALE)
2993 set(SDL_LOCALE_DUMMY 1)
2994 file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
2995 list(APPEND SOURCE_FILES ${LOCALE_SOURCES})
2996endif()
2997if(NOT HAVE_SDL_MISC)
2998 set(SDL_MISC_DUMMY 1)
2999 file(GLOB MISC_SOURCES ${SDL2_SOURCE_DIR}/src/misc/dummy/*.c)
3000 list(APPEND SOURCE_FILES ${MISC_SOURCES})
3001endif()
3002
3003# We always need to have threads and timers around
3004if(NOT HAVE_SDL_THREADS)
3005 # The emscripten platform has been carefully vetted to work without threads
3006 if (EMSCRIPTEN)
3007 set(SDL_THREADS_DISABLED 1)
3008 file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
3009 list(APPEND SOURCE_FILES ${THREADS_SOURCES})
3010 else()
3011 message_error("Threads are needed by many SDL subsystems and may not be disabled")
3012 endif()
3013endif()
3014if(NOT HAVE_SDL_TIMERS)
3015 set(SDL_TIMER_DUMMY 1)
3016 file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
3017 list(APPEND SOURCE_FILES ${TIMER_SOURCES})
3018endif()
3019
3020if(NOT SDLMAIN_SOURCES)
3021 file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
3022endif()
3023
3024if(SDL_WERROR)
3025 if(MSVC)
3026 cmake_push_check_state(RESET)
3027 check_c_compiler_flag(/WX HAVE_WX)
3028 if(HAVE_WX)
3029 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
3030 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
3031 endif()
3032 elseif(USE_GCC OR USE_CLANG OR USE_INTELCC)
3033 cmake_push_check_state(RESET)
3034 check_c_compiler_flag(-Werror HAVE_WERROR)
3035 if(HAVE_WERROR)
3036 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
3037 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
3038 set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -Werror")
3039 endif()
3040 cmake_pop_check_state()
3041 endif()
3042endif()
3043
3044# Append the -MMD -MT flags
3045# if(DEPENDENCY_TRACKING)
3046# if(COMPILER_IS_GNUCC)
3047# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
3048# endif()
3049# endif()
3050
3051# config variables may contain generator expression, so we need to generate SDL_config.h in 2 steps:
3052# 1. replace all `#cmakedefine`'s and `@abc@`
3053configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
3054 "${SDL2_BINARY_DIR}/SDL_config.h.intermediate")
3055# 2. Create the "include-config-${CMAKE_BUILD_TYPE}" folder (fails on older CMake versions when it does not exist)
3056string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_build_type)
3057execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include-config-${lower_build_type}")
3058# 3. generate SDL_config in an build_type-dependent folder (which should be first in the include search path)
3059file(GENERATE
3060 OUTPUT "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2/SDL_config.h"
3061 INPUT "${SDL2_BINARY_DIR}/SDL_config.h.intermediate")
3062
3063# Prepare the flags and remove duplicates
3064if(EXTRA_LDFLAGS)
3065 list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
3066endif()
3067if(EXTRA_LIBS)
3068 list(REMOVE_DUPLICATES EXTRA_LIBS)
3069endif()
3070if(EXTRA_CFLAGS)
3071 list(REMOVE_DUPLICATES EXTRA_CFLAGS)
3072endif()
3073listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
3074set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
3075
3076if(USE_GCC OR USE_CLANG)
3077 string(REGEX REPLACE "(^| )-I" "\\1 -isystem" EXTRA_CFLAGS "${EXTRA_CFLAGS}")
3078endif()
3079
3080# Compat helpers for the configuration files
3081
3082if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION.txt")
3083 file(READ "${PROJECT_SOURCE_DIR}/VERSION.txt" SDL_SOURCE_VERSION)
3084 string(STRIP "${SDL_SOURCE_VERSION}" SDL_SOURCE_VERSION)
3085endif()
3086
3087find_package(Git)
3088if(Git_FOUND)
3089 execute_process(COMMAND
3090 "${GIT_EXECUTABLE}" describe --always --tags --long
3091 WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
3092 RESULT_VARIABLE GIT_REVISION_STATUS
3093 OUTPUT_VARIABLE GIT_REVISION
3094 ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
3095else()
3096 set(GIT_REVISION_STATUS 1)
3097 set(GIT_REVISION "")
3098endif()
3099
3100if(SDL_SOURCE_VERSION)
3101 set(SDL_REVISION "SDL-${SDL_SOURCE_VERSION}")
3102elseif(GIT_REVISION_STATUS EQUAL 0)
3103 if(GIT_REVISION MATCHES "^[0-9a-f]+$")
3104 # Just a truncated sha1, so prefix it with the version number
3105 set(SDL_REVISION "SDL-${SDL_VERSION}-g${GIT_REVISION}")
3106 else()
3107 # e.g. release-2.24.0-542-g96361fc47
3108 set(SDL_REVISION "SDL-${GIT_REVISION}")
3109 endif()
3110else()
3111 set(SDL_REVISION "SDL-${SDL_VERSION}-no-vcs")
3112endif()
3113
3114configure_file("${SDL2_SOURCE_DIR}/include/SDL_revision.h.cmake"
3115 "${SDL2_BINARY_DIR}/include/SDL2/SDL_revision.h")
3116
3117# Copy all non-generated headers to "${SDL2_BINARY_DIR}/include/SDL2"
3118# This is done to avoid the inclusion of a pre-generated SDL_config.h
3119file(GLOB SDL2_INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
3120set(SDL2_COPIED_INCLUDE_FILES)
3121foreach(_hdr IN LISTS SDL2_INCLUDE_FILES)
3122 if(_hdr MATCHES ".*(SDL_config|SDL_revision).*")
3123 list(REMOVE_ITEM SDL2_INCLUDE_FILES "${_hdr}")
3124 else()
3125 get_filename_component(_name "${_hdr}" NAME)
3126 set(_bin_hdr "${SDL2_BINARY_DIR}/include/SDL2/${_name}")
3127 list(APPEND SDL2_COPIED_INCLUDE_FILES "${_bin_hdr}")
3128 add_custom_command(OUTPUT "${_bin_hdr}"
3129 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_hdr}" "${_bin_hdr}"
3130 DEPENDS "${_hdr}")
3131 endif()
3132endforeach()
3133list(APPEND SDL_GENERATED_HEADERS ${SDL2_COPIED_INCLUDE_FILES})
3134
3135if(CMAKE_STATIC_LIBRARY_PREFIX STREQUAL "" AND CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL ".lib")
3136 # Avoid conflict between the dll import library and the static library
3137 set(sdl_static_libname "SDL2-static")
3138else()
3139 set(sdl_static_libname "SDL2")
3140endif()
3141
3142# CMAKE_PREFIX_PATH and CMAKE_INSTALL_FULL_BINDIR can be a non-absolute path
3143# when a master-project does e.g. `set(CMAKE_INSTALL_PREFIX "libs/SDL2" CACHE PATH "prefix" FORCE)`.
3144if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}")
3145 set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}")
3146endif()
3147if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_FULL_BINDIR}")
3148 set(CMAKE_INSTALL_FULL_BINDIR "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_FULL_BINDIR}")
3149endif()
3150file(RELATIVE_PATH bin_prefix_relpath "${CMAKE_INSTALL_FULL_BINDIR}" "${CMAKE_INSTALL_PREFIX}")
3151
3152set(prefix ${CMAKE_INSTALL_PREFIX})
3153set(exec_prefix "\${prefix}")
3154set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
3155set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
3156set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
3157if(SDL_STATIC)
3158 set(ENABLE_STATIC_TRUE "")
3159 set(ENABLE_STATIC_FALSE "#")
3160else()
3161 set(ENABLE_STATIC_TRUE "#")
3162 set(ENABLE_STATIC_FALSE "")
3163endif()
3164if(SDL_SHARED)
3165 set(PKGCONFIG_LIBS_PRIV "
3166Libs.private:")
3167 set(ENABLE_SHARED_TRUE "")
3168 set(ENABLE_SHARED_FALSE "#")
3169else()
3170 set(PKGCONFIG_LIBS_PRIV "")
3171 set(ENABLE_SHARED_TRUE "#")
3172 set(ENABLE_SHARED_FALSE "")
3173endif()
3174
3175# Clean up the different lists
3176listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
3177set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
3178list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
3179listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
3180set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
3181listtostr(SDL_LIBS _SDL_LIBS)
3182set(SDL_LIBS ${_SDL_LIBS})
3183listtostr(SDL_CFLAGS _SDL_CFLAGS "")
3184set(SDL_CFLAGS ${_SDL_CFLAGS})
3185string(REGEX REPLACE "-lSDL2( |$)" "-l${sdl_static_libname} " SDL_STATIC_LIBS "${SDL_STATIC_LIBS}")
3186if(NOT SDL_SHARED)
3187 string(REGEX REPLACE "-lSDL2( |$)" "-l${sdl_static_libname} " SDL_LIBS "${SDL_LIBS}")
3188endif()
3189listtostr(PKGCONFIG_DEPENDS PKGCONFIG_DEPENDS)
3190
3191if(SDL_STATIC AND SDL_SHARED AND NOT sdl_static_libname STREQUAL "SDL2")
3192 message(STATUS "\"pkg-config --static --libs sdl2\" will return invalid information")
3193endif()
3194
3195# MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
3196# MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
3197
3198configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
3199 "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
3200configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
3201 "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
3202configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
3203 "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
3204
3205macro(check_add_debug_flag FLAG SUFFIX)
3206 check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX})
3207 if (HAS_C_FLAG_${SUFFIX})
3208 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
3209 endif()
3210
3211 check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
3212 if (HAS_CXX_${SUFFIX})
3213 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
3214 endif()
3215endmacro()
3216
3217macro(asan_check_add_debug_flag ASAN_FLAG)
3218 check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}")
3219 if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
3220 set(HAVE_ASAN ON)
3221 endif()
3222endmacro()
3223
3224macro(asan_check_add_debug_flag2 ASAN_FLAG)
3225 # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES:
3226 # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html
3227
3228 set(FLAG "-fsanitize=${ASAN_FLAG}")
3229
3230 set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
3231 set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
3232 check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
3233 check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
3234 set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
3235
3236 if (HAS_C_FLAG_${ASAN_FLAG})
3237 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
3238 endif()
3239
3240 if (HAS_CXX_${ASAN_FLAG})
3241 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
3242 endif()
3243
3244 if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
3245 set(HAVE_ASAN ON)
3246 endif()
3247endmacro()
3248
3249# enable AddressSanitizer if supported
3250if (SDL_ASAN)
3251 asan_check_add_debug_flag2("address")
3252 asan_check_add_debug_flag("bool")
3253 asan_check_add_debug_flag("bounds")
3254 asan_check_add_debug_flag("enum")
3255 asan_check_add_debug_flag("float-cast-overflow")
3256 asan_check_add_debug_flag("float-divide-by-zero")
3257 asan_check_add_debug_flag("nonnull-attribute")
3258 asan_check_add_debug_flag("returns-nonnull-attribute")
3259 asan_check_add_debug_flag("signed-integer-overflow")
3260 asan_check_add_debug_flag("undefined")
3261 asan_check_add_debug_flag("vla-bound")
3262 asan_check_add_debug_flag("leak")
3263 # The object size sanitizer has no effect on unoptimized builds on Clang,
3264 # but causes warnings.
3265 if((NOT USE_CLANG) OR ("${CMAKE_BUILD_TYPE}" STREQUAL ""))
3266 asan_check_add_debug_flag("object-size")
3267 endif()
3268endif()
3269
3270if(SDL_CCACHE AND NOT CMAKE_VERSION VERSION_LESS 3.4)
3271 cmake_minimum_required(VERSION 3.4...3.5)
3272 find_program(CCACHE_BINARY ccache)
3273 if(CCACHE_BINARY)
3274 set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY})
3275 set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_BINARY})
3276 set(CMAKE_OBJC_COMPILER_LAUNCHER ${CCACHE_BINARY})
3277 set(HAVE_CCACHE ON)
3278 else()
3279 set(HAVE_CCACHE OFF)
3280 endif()
3281else()
3282 set(HAVE_CCACHE OFF)
3283endif()
3284
3285if(SDL_TESTS)
3286 set(HAVE_TESTS ON)
3287endif()
3288
3289# Create target that collects all all generated include files.
3290add_custom_target(sdl_headers_copy
3291 DEPENDS ${SDL_GENERATED_HEADERS})
3292
3293##### Info output #####
3294message(STATUS "")
3295message(STATUS "SDL2 was configured with the following options:")
3296message(STATUS "")
3297message(STATUS "Platform: ${CMAKE_SYSTEM}")
3298message(STATUS "64-bit: ${ARCH_64}")
3299message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
3300message(STATUS "Revision: ${SDL_REVISION}")
3301message(STATUS "")
3302message(STATUS "Subsystems:")
3303foreach(_SUB ${SDL_SUBSYSTEMS})
3304 string(TOUPPER ${_SUB} _OPT)
3305 message_bool_option(${_SUB} SDL_${_OPT})
3306endforeach()
3307message(STATUS "")
3308message(STATUS "Options:")
3309list(SORT ALLOPTIONS)
3310foreach(_OPT ${ALLOPTIONS})
3311 # Get the padding
3312 string(LENGTH ${_OPT} _OPTLEN)
3313 math(EXPR _PADLEN "(${LONGESTOPTIONNAME} + 1) - ${_OPTLEN}")
3314 string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
3315 message_tested_option(${_OPT} ${_PADDING})
3316endforeach()
3317if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
3318 message(STATUS "")
3319 message(STATUS " CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}")
3320 message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
3321endif()
3322message(STATUS "")
3323message(STATUS " CFLAGS: ${CMAKE_C_FLAGS}")
3324message(STATUS " EXTRA_CFLAGS: ${EXTRA_CFLAGS}")
3325message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD}")
3326message(STATUS " EXTRA_LIBS: ${EXTRA_LIBS}")
3327message(STATUS "")
3328message(STATUS " Build Shared Library: ${SDL_SHARED}")
3329message(STATUS " Build Static Library: ${SDL_STATIC}")
3330if(SDL_STATIC)
3331 message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
3332endif()
3333message(STATUS "")
3334if(UNIX)
3335 message(STATUS "If something was not detected, although the libraries")
3336 message(STATUS "were installed, then make sure you have set the")
3337 message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
3338 message(STATUS "")
3339endif()
3340
3341if(WARN_ABOUT_ARM_SIMD_ASM_MIT)
3342 message(STATUS "")
3343 message(STATUS "SDL is being built with ARM SIMD optimizations, which")
3344 message(STATUS "uses code licensed under the MIT license. If this is a")
3345 message(STATUS "problem, please disable that code by rerunning CMake with:")
3346 message(STATUS "")
3347 message(STATUS " -DSDL_ARMSIMD=OFF")
3348endif()
3349
3350if(WARN_ABOUT_ARM_NEON_ASM_MIT)
3351 message(STATUS "")
3352 message(STATUS "SDL is being built with ARM NEON optimizations, which")
3353 message(STATUS "uses code licensed under the MIT license. If this is a")
3354 message(STATUS "problem, please disable that code by rerunning CMake with:")
3355 message(STATUS "")
3356 message(STATUS " -DSDL_ARMNEON=OFF")
3357endif()
3358
3359# Ensure that the extra cflags are used at compile time
3360set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${EXTRA_CFLAGS_BUILD}")
3361
3362if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
3363 # Build SDLmain
3364 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
3365 add_dependencies(SDL2main sdl_headers_copy)
3366 # alias target for in-tree builds
3367 add_library(SDL2::SDL2main ALIAS SDL2main)
3368 target_include_directories(SDL2main BEFORE
3369 PRIVATE "${SDL2_BINARY_DIR}/include"
3370 PRIVATE "${SDL2_BINARY_DIR}/include/SDL2"
3371 PRIVATE "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2"
3372 )
3373 target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>" $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>)
3374 if (WIN32)
3375 target_link_libraries(SDL2main PRIVATE shell32)
3376 endif()
3377 if(MINGW OR CYGWIN)
3378 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
3379 target_link_libraries(SDL2main PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=_WinMain@16>")
3380 else()
3381 target_link_libraries(SDL2main PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-Wl,--undefined=WinMain>")
3382 endif()
3383 endif()
3384 if (NOT ANDROID)
3385 set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
3386 endif()
3387 set_property(TARGET SDL2main APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
3388 set_property(TARGET SDL2main PROPERTY INTERFACE_SDL_VERSION "SDL2")
3389endif()
3390
3391if(ANDROID)
3392 target_include_directories(sdl-build-options INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures")
3393endif()
3394
3395if(APPLE)
3396 cmake_push_check_state(RESET)
3397 check_c_compiler_flag(-fobjc-arc COMPILER_SUPPORTS_FOBJC_ARC)
3398 cmake_pop_check_state()
3399 if(NOT COMPILER_SUPPORTS_FOBJC_ARC)
3400 message(FATAL_ERROR "Compiler does not support -fobjc-arc: this is required on Apple platforms")
3401 endif()
3402 target_compile_options(sdl-build-options INTERFACE "-fobjc-arc")
3403endif()
3404
3405if(PS2)
3406 target_compile_options(sdl-build-options INTERFACE "-Wno-error=declaration-after-statement")
3407endif()
3408
3409if(APPLE)
3410 foreach(SOURCE_FILE ${SOURCE_FILES})
3411 get_filename_component(FILE_EXTENSION ${SOURCE_FILE} EXT)
3412 if(FILE_EXTENSION STREQUAL ".m")
3413 set_property(SOURCE ${SOURCE_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS " -x objective-c")
3414 endif()
3415 endforeach()
3416endif()
3417
3418if(SDL_SHARED)
3419 add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
3420 add_dependencies(SDL2 sdl_headers_copy)
3421 # alias target for in-tree builds
3422 add_library(SDL2::SDL2 ALIAS SDL2)
3423 set_target_properties(SDL2 PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
3424 set_target_properties(SDL2 PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
3425 if(NOT SDL_LIBC)
3426 if(SDL_CPU_X86)
3427 # FIXME: should be added for all architectures (missing symbols for ARM)
3428 target_link_libraries(SDL2 PRIVATE "-nodefaultlib:MSVCRT")
3429 endif()
3430 if(HAS_Q_NO_USE_LIBIRC)
3431 target_compile_options(SDL2 PRIVATE /Q_no-use-libirc)
3432 endif()
3433 endif()
3434 if(APPLE)
3435 # FIXME: Remove SOVERSION in SDL3
3436 set_target_properties(SDL2 PROPERTIES
3437 MACOSX_RPATH 1
3438 SOVERSION 0
3439 OUTPUT_NAME "SDL2-${LT_RELEASE}")
3440 elseif(UNIX AND NOT ANDROID)
3441 set_target_properties(SDL2 PROPERTIES
3442 VERSION ${LT_VERSION}
3443 SOVERSION ${LT_MAJOR}
3444 OUTPUT_NAME "SDL2-${LT_RELEASE}")
3445 else()
3446 if(WINDOWS OR CYGWIN)
3447 set_target_properties(SDL2 PROPERTIES
3448 DEFINE_SYMBOL DLL_EXPORT)
3449 elseif(OS2)
3450 set_target_properties(SDL2 PROPERTIES
3451 DEFINE_SYMBOL BUILD_SDL)
3452 endif()
3453 set_target_properties(SDL2 PROPERTIES
3454 VERSION ${SDL_VERSION}
3455 SOVERSION ${LT_REVISION}
3456 OUTPUT_NAME "SDL2")
3457 endif()
3458 # Note: The clang toolset for Visual Studio does not support /NODEFAULTLIB.
3459 if(MSVC AND NOT SDL_LIBC AND NOT MSVC_CLANG AND NOT SDL_CPU_ARM32)
3460 # Don't try to link with the default set of libraries.
3461 if(NOT WINDOWS_STORE)
3462 set_property(TARGET SDL2 APPEND_STRING PROPERTY LINK_FLAGS " /NODEFAULTLIB")
3463 endif()
3464 set_property(TARGET SDL2 APPEND_STRING PROPERTY STATIC_LIBRARY_FLAGS " /NODEFAULTLIB")
3465 endif()
3466 # FIXME: if CMAKE_VERSION >= 3.13, use target_link_options for EXTRA_LDFLAGS
3467 target_link_libraries(SDL2 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${EXTRA_LDFLAGS_BUILD} ${CMAKE_DEPENDS})
3468 target_include_directories(SDL2 PUBLIC
3469 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
3470 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include/SDL2>"
3471 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2>"
3472 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
3473 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>"
3474 )
3475 # This picks up all the compiler options and such we've accumulated up to here.
3476 target_link_libraries(SDL2 PRIVATE $<BUILD_INTERFACE:sdl-build-options>)
3477 if(MINGW OR CYGWIN)
3478 if(NOT CMAKE_VERSION VERSION_LESS "3.13")
3479 target_link_options(SDL2 PRIVATE -static-libgcc)
3480 endif()
3481 endif()
3482 if(NOT ANDROID)
3483 set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
3484 endif()
3485 # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
3486 set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
3487 set_property(TARGET SDL2 PROPERTY INTERFACE_SDL2_SHARED TRUE)
3488 set_property(TARGET SDL2 APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
3489 set_property(TARGET SDL2 PROPERTY INTERFACE_SDL_VERSION "SDL2")
3490endif()
3491
3492if(SDL_STATIC)
3493 add_library(SDL2-static STATIC ${SOURCE_FILES})
3494 add_dependencies(SDL2-static sdl_headers_copy)
3495 # alias target for in-tree builds
3496 add_library(SDL2::SDL2-static ALIAS SDL2-static)
3497 set_target_properties(SDL2-static PROPERTIES
3498 OUTPUT_NAME "${sdl_static_libname}"
3499 POSITION_INDEPENDENT_CODE "${SDL_STATIC_PIC}")
3500 target_compile_definitions(SDL2-static PRIVATE SDL_STATIC_LIB)
3501 # TODO: Win32 platforms keep the same suffix .lib for import and static
3502 # libraries - do we need to consider this?
3503 target_link_libraries(SDL2-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS} ${CMAKE_DEPENDS})
3504 target_include_directories(SDL2-static PUBLIC
3505 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
3506 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include/SDL2>"
3507 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2>"
3508 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
3509 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>"
3510 )
3511 # This picks up all the compiler options and such we've accumulated up to here.
3512 target_link_libraries(SDL2-static PRIVATE $<BUILD_INTERFACE:sdl-build-options>)
3513 if(NOT ANDROID)
3514 set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
3515 endif()
3516 # Use `Compatible Interface Properties` to allow consumers to enforce a shared/static library
3517 set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SDL2_SHARED)
3518 set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL2_SHARED FALSE)
3519 set_property(TARGET SDL2-static APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
3520 set_property(TARGET SDL2-static PROPERTY INTERFACE_SDL_VERSION "SDL2")
3521endif()
3522
3523set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MAJOR_VERSION=${SDL_MAJOR_VERSION}")
3524set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MINOR_VERSION=${SDL_MINOR_VERSION}")
3525set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MICRO_VERSION=${SDL_MICRO_VERSION}")
3526
3527##### Tests #####
3528
3529if(SDL_TEST)
3530 file(GLOB TEST_SOURCES ${SDL2_SOURCE_DIR}/src/test/*.c)
3531 add_library(SDL2_test STATIC ${TEST_SOURCES})
3532 add_dependencies(SDL2_test sdl_headers_copy)
3533 add_library(SDL2::SDL2test ALIAS SDL2_test)
3534 set_target_properties(SDL2_test PROPERTIES
3535 EXPORT_NAME SDL2test)
3536 target_include_directories(SDL2_test PUBLIC
3537 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include>"
3538 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include/SDL2>"
3539 "$<BUILD_INTERFACE:${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2>"
3540 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
3541 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
3542 target_link_libraries(SDL2_test PRIVATE ${EXTRA_TEST_LIBS})
3543 target_include_directories(SDL2_test PRIVATE ${EXTRA_TEST_INCLUDES})
3544 set_property(TARGET SDL2_test APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION")
3545 set_property(TARGET SDL2_test PROPERTY INTERFACE_SDL_VERSION "SDL2")
3546endif()
3547
3548##### Installation targets #####
3549if(NOT SDL2_DISABLE_INSTALL)
3550 if(SDL_SHARED)
3551 install(TARGETS SDL2 EXPORT SDL2Targets
3552 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3553 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3554 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
3555 if(MSVC)
3556 SDL_install_pdb(SDL2 "${CMAKE_INSTALL_BINDIR}")
3557 endif()
3558 endif()
3559
3560 if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
3561 install(TARGETS SDL2main EXPORT SDL2mainTargets
3562 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3563 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3564 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
3565 if(MSVC)
3566 SDL_install_pdb(SDL2main "${CMAKE_INSTALL_LIBDIR}")
3567 endif()
3568 endif()
3569
3570 if(SDL_STATIC)
3571 install(TARGETS SDL2-static EXPORT SDL2staticTargets
3572 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3573 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3574 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
3575 if(MSVC)
3576 SDL_install_pdb(SDL2-static "${CMAKE_INSTALL_LIBDIR}")
3577 endif()
3578 endif()
3579
3580 if(SDL_TEST)
3581 install(TARGETS SDL2_test EXPORT SDL2testTargets
3582 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3583 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
3584 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
3585 if(MSVC)
3586 SDL_install_pdb(SDL2_test "${CMAKE_INSTALL_LIBDIR}")
3587 endif()
3588 endif()
3589
3590 ##### Export files #####
3591 if (WINDOWS AND NOT MINGW)
3592 set(SDL_INSTALL_CMAKEDIR_DEFAULT "cmake")
3593 set(LICENSES_PREFIX "licenses/SDL2")
3594 else ()
3595 set(SDL_INSTALL_CMAKEDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}/cmake/SDL2")
3596 set(LICENSES_PREFIX "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}")
3597 endif ()
3598 set(SDL_INSTALL_CMAKEDIR "${SDL_INSTALL_CMAKEDIR_DEFAULT}" CACHE STRING "Location where to install SDL2Config.cmake")
3599
3600 include(CMakePackageConfigHelpers)
3601 configure_package_config_file(SDL2Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/SDL2Config.cmake"
3602 PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_FULL_BINDIR CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR
3603 INSTALL_DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3604 )
3605 write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL2ConfigVersion.cmake"
3606 VERSION ${SDL_VERSION}
3607 COMPATIBILITY AnyNewerVersion
3608 )
3609
3610 if(SDL_SHARED)
3611 install(EXPORT SDL2Targets
3612 FILE SDL2Targets.cmake
3613 NAMESPACE SDL2::
3614 DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3615 )
3616 if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
3617 install(EXPORT_ANDROID_MK SDL2Targets
3618 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2")
3619 endif()
3620 endif()
3621
3622 if(NOT WINDOWS_STORE AND NOT SDL2_DISABLE_SDL2MAIN)
3623 install(EXPORT SDL2mainTargets
3624 FILE SDL2mainTargets.cmake
3625 NAMESPACE SDL2::
3626 DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3627 )
3628 if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
3629 install(EXPORT_ANDROID_MK SDL2mainTargets
3630 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2main")
3631 endif()
3632 endif()
3633
3634 if(SDL_STATIC)
3635 install(EXPORT SDL2staticTargets
3636 FILE SDL2staticTargets.cmake
3637 NAMESPACE SDL2::
3638 DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3639 )
3640 if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
3641 install(EXPORT_ANDROID_MK SDL2staticTargets
3642 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2-static")
3643 endif()
3644 endif()
3645
3646 if(SDL_TEST)
3647 install(EXPORT SDL2testTargets
3648 FILE SDL2testTargets.cmake
3649 NAMESPACE SDL2::
3650 DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3651 )
3652 if(ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.7)
3653 install(EXPORT_ANDROID_MK SDL2testTargets
3654 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/ndk-modules/SDL2test")
3655 endif()
3656 endif()
3657
3658 install(
3659 FILES
3660 ${CMAKE_CURRENT_BINARY_DIR}/SDL2Config.cmake
3661 ${CMAKE_CURRENT_BINARY_DIR}/SDL2ConfigVersion.cmake
3662 ${SDL2_SOURCE_DIR}/cmake/sdlfind.cmake
3663 DESTINATION "${SDL_INSTALL_CMAKEDIR}"
3664 COMPONENT Devel
3665 )
3666
3667 install(
3668 FILES
3669 ${SDL2_INCLUDE_FILES}
3670 "${SDL2_BINARY_DIR}/include/SDL2/SDL_revision.h"
3671 "${SDL2_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>/SDL2/SDL_config.h"
3672 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SDL2)
3673
3674 string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
3675 if (UPPER_BUILD_TYPE MATCHES DEBUG)
3676 set(SOPOSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
3677 else()
3678 set(SOPOSTFIX "")
3679 endif()
3680
3681 install(FILES "LICENSE.txt" DESTINATION "${LICENSES_PREFIX}")
3682 if(FREEBSD)
3683 # FreeBSD uses ${PREFIX}/libdata/pkgconfig
3684 install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
3685 else()
3686 install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
3687 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
3688 endif()
3689 if(NOT (WINDOWS OR CYGWIN) OR MINGW)
3690 if(SDL_SHARED)
3691 set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
3692 get_target_property(SONAME SDL2 OUTPUT_NAME)
3693 if(NOT ANDROID AND NOT MINGW AND NOT OS2)
3694 install(CODE "
3695 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
3696 \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\"
3697 WORKING_DIRECTORY \"${SDL2_BINARY_DIR}\")")
3698 install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
3699 endif()
3700 endif()
3701 install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION "${CMAKE_INSTALL_BINDIR}")
3702 # TODO: what about the .spec file? Is it only needed for RPM creation?
3703 install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/aclocal")
3704 endif()
3705endif()
3706
3707##### Uninstall target #####
3708
3709if(NOT SDL2_DISABLE_UNINSTALL)
3710 if(NOT TARGET uninstall)
3711 configure_file(
3712 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
3713 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
3714 IMMEDIATE @ONLY)
3715
3716 add_custom_target(uninstall
3717 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
3718 endif()
3719endif()
3720
3721##### Tests subproject (must appear after the install/uninstall targets) #####
3722
3723if(SDL_TESTS)
3724 set(HAVE_TESTS ON)
3725 enable_testing()
3726 add_subdirectory(test)
3727endif()
3728
3729##### Fix Objective C builds #####
3730set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} ${CMAKE_C_FLAGS}")
3731
3732# Make sure SDL2::SDL2 always exists
3733if(TARGET SDL2::SDL2-static AND NOT TARGET SDL2::SDL2)
3734 add_library(SDL2::SDL2 ALIAS SDL2-static)
3735endif()