1if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
2  message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there")
3endif()
4
5cmake_minimum_required(VERSION 3.0.0)
6project(SDL2 C CXX)
7
8# !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
9# !!! FIXME:  for the SDL2 shared library (so you get an
10# !!! FIXME:  install_name ("soname") of "@rpath/libSDL-whatever.dylib"
11# !!! FIXME:  instead of "/usr/local/lib/libSDL-whatever.dylib"), but I'm
12# !!! FIXME:  punting for now and leaving the existing behavior. Until this
13# !!! FIXME:  properly resolved, this line silences a warning in CMake 3.0+.
14# !!! FIXME:  remove it and this comment entirely once the problem is
15# !!! FIXME:  properly resolved.
16#cmake_policy(SET CMP0042 OLD)
17
18include(CheckLibraryExists)
19include(CheckIncludeFiles)
20include(CheckIncludeFile)
21include(CheckSymbolExists)
22include(CheckCSourceCompiles)
23include(CheckCSourceRuns)
24include(CheckCCompilerFlag)
25include(CheckTypeSize)
26include(CheckStructHasMember)
27include(CMakeDependentOption)
28include(FindPkgConfig)
29include(GNUInstallDirs)
30set(CMAKE_MODULE_PATH "${SDL2_SOURCE_DIR}/cmake")
31include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
32include(${SDL2_SOURCE_DIR}/cmake/sdlchecks.cmake)
33
34# General settings
35# Edit include/SDL_version.h and change the version, then:
36#   SDL_MICRO_VERSION += 1;
37#   SDL_INTERFACE_AGE += 1;
38#   SDL_BINARY_AGE += 1;
39# if any functions have been added, set SDL_INTERFACE_AGE to 0.
40# if backwards compatibility has been broken,
41# set SDL_BINARY_AGE and SDL_INTERFACE_AGE to 0.
42set(SDL_MAJOR_VERSION 2)
43set(SDL_MINOR_VERSION 0)
44set(SDL_MICRO_VERSION 13)
45set(SDL_INTERFACE_AGE 1)
46set(SDL_BINARY_AGE 13)
47set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
48# the following should match the versions in Xcode project file:
49set(DYLIB_CURRENT_VERSION 12.0.0)
50set(DYLIB_COMPATIBILITY_VERSION 1.0.0)
51
52# Set defaults preventing destination file conflicts
53set(SDL_CMAKE_DEBUG_POSTFIX "d"
54    CACHE STRING "Name suffix for debug builds")
55
56mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX SDL_CMAKE_DEBUG_POSTFIX)
57
58# Calculate a libtool-like version number
59math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
60math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
61math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
62set(LT_REVISION "${SDL_INTERFACE_AGE}")
63set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
64set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
65
66#message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
67
68# General settings & flags
69set(LIBRARY_OUTPUT_DIRECTORY "build")
70# Check for 64 or 32 bit
71set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
72if(CMAKE_SIZEOF_VOID_P EQUAL 8)
73  set(ARCH_64 TRUE)
74  set(PROCESSOR_ARCH "x64")
75else()
76  set(ARCH_64 FALSE)
77  set(PROCESSOR_ARCH "x86")
78endif()
79set(LIBNAME SDL2)
80if(NOT LIBTYPE)
81  set(LIBTYPE SHARED)
82endif()
83
84# Get the platform
85if(WIN32)
86  if(NOT WINDOWS)
87    set(WINDOWS TRUE)
88  endif()
89elseif(UNIX AND NOT APPLE)
90  if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
91    set(LINUX TRUE)
92  elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
93    set(FREEBSD TRUE)
94  elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
95    set(NETBSD TRUE)
96  elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
97    set(OPENBSD TRUE)
98  elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
99    set(GNU TRUE)
100  elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
101    set(BSDI TRUE)
102  elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
103    set(FREEBSD TRUE)
104  elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
105    set(SYSV5 TRUE)
106  elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*")
107    set(SOLARIS TRUE)
108  elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
109    set(HPUX TRUE)
110  elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
111    set(AIX TRUE)
112  elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
113    set(MINIX TRUE)
114  endif()
115elseif(APPLE)
116  if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
117    set(DARWIN TRUE)
118  elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
119    set(MACOSX TRUE)
120  elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*")
121    set(TVOS TRUE)
122  endif()
123  # TODO: iOS?
124elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
125  message_error("BeOS support has been removed as of SDL 2.0.2.")
126elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
127  set(HAIKU TRUE)
128endif()
129
130# Don't mistake osx for unix
131if(UNIX AND NOT APPLE AND NOT RISCOS)
132  set(UNIX_SYS ON)
133else()
134  set(UNIX_SYS OFF)
135endif()
136
137if(UNIX OR APPLE)
138  set(UNIX_OR_MAC_SYS ON)
139else()
140  set(UNIX_OR_MAC_SYS OFF)
141endif()
142
143if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
144  set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
145else()
146  set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
147endif()
148
149# Default option knobs
150if(APPLE OR ARCH_64)
151  if(NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm")
152    set(OPT_DEF_SSEMATH ON)
153  endif()
154endif()
155if(UNIX OR MINGW OR MSYS)
156  set(OPT_DEF_LIBC ON)
157endif()
158
159# The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
160#  so we'll just use libusb when it's available. libusb does not support iOS,
161#  so we default to yes on iOS.
162#  TODO: Windows can support libusb, the hid.c file just depends on Unix APIs
163if(WINDOWS OR IOS OR TVOS OR ANDROID)
164  set(HIDAPI_SKIP_LIBUSB TRUE)
165else()
166  set(HIDAPI_SKIP_LIBUSB FALSE)
167endif()
168if (HIDAPI_SKIP_LIBUSB)
169  set(OPT_DEF_HIDAPI ON)
170endif()
171
172# On the other hand, *BSD specifically uses libusb only, so we make a special
173#  case just for them.
174if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
175  set(HIDAPI_ONLY_LIBUSB TRUE)
176else()
177  set(HIDAPI_ONLY_LIBUSB FALSE)
178endif()
179
180# Compiler info
181if(CMAKE_COMPILER_IS_GNUCC)
182  set(USE_GCC TRUE)
183  set(OPT_DEF_ASM TRUE)
184elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
185  set(USE_CLANG TRUE)
186  set(OPT_DEF_ASM TRUE)
187elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
188  set(OPT_DEF_ASM TRUE)
189  #set(CMAKE_C_FLAGS "/ZI /WX- /
190else()
191  set(OPT_DEF_ASM FALSE)
192endif()
193
194if(USE_GCC OR USE_CLANG)
195  set(OPT_DEF_GCC_ATOMICS ON)
196endif()
197
198# Default flags, if not set otherwise
199if("$ENV{CFLAGS}" STREQUAL "")
200  if(CMAKE_BUILD_TYPE STREQUAL "")
201    if(USE_GCC OR USE_CLANG)
202      set(CMAKE_C_FLAGS "-g -O3")
203    endif()
204  endif()
205else()
206  set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
207  list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
208endif()
209if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
210  list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
211endif()
212
213if(MSVC)
214  option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
215  if(FORCE_STATIC_VCRT)
216    foreach(flag_var
217        CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
218        CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
219      if(${flag_var} MATCHES "/MD")
220        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
221      endif()
222    endforeach()
223  endif()
224
225  # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
226  foreach(flag_var
227      CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
228      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
229    string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
230  endforeach(flag_var)
231endif()
232
233# Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
234# etc. are created correctly.
235set(SDL_LIBS "-lSDL2")
236set(SDL_CFLAGS "")
237
238# When building shared lib for Windows with MinGW,
239# avoid the DLL having a "lib" prefix
240if(WINDOWS)
241  set(CMAKE_SHARED_LIBRARY_PREFIX "")
242endif()
243
244# Emscripten toolchain has a nonempty default value for this, and the checks
245# in this file need to change that, so remember the original value, and
246# restore back to that afterwards. For check_function_exists() to work in
247# Emscripten, this value must be at its default value.
248set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
249
250if(CYGWIN)
251  # We build SDL on cygwin without the UNIX emulation layer
252  include_directories("-I/usr/include/mingw")
253  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
254  check_c_source_compiles("int main(int argc, char **argv) {}"
255    HAVE_GCC_NO_CYGWIN)
256  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
257  if(HAVE_GCC_NO_CYGWIN)
258    list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
259    list(APPEND SDL_LIBS "-mno-cygwin")
260  endif()
261  set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
262endif()
263
264add_definitions(-DUSING_GENERATED_CONFIG_H)
265# General includes
266include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
267if(USE_GCC OR USE_CLANG)
268  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter ${SDL2_SOURCE_DIR}/src/video/khronos")
269else()
270  include_directories(${SDL2_SOURCE_DIR}/src/video/khronos)
271endif()
272
273# All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
274#  you only need to have a platform override them if they are disabling.
275set(OPT_DEF_ASM TRUE)
276if(EMSCRIPTEN)
277  # Set up default values for the currently supported set of subsystems:
278  # Emscripten/Javascript does not have assembly support, a dynamic library
279  # loading architecture, low-level CPU inspection or multithreading.
280  set(OPT_DEF_ASM FALSE)
281  set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
282  set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
283  set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
284  set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
285  set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
286  set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
287endif()
288
289# When defined, respect CMake's BUILD_SHARED_LIBS setting:
290set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
291if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
292  # ...unless decided already (as for EMSCRIPTEN)
293
294  set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
295
296  if (NOT DEFINED BUILD_SHARED_LIBS)
297    # No preference? Build both, just like the AC/AM configure
298    set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
299
300  elseif (BUILD_SHARED_LIBS)
301    # In this case, we assume the user wants a shared lib and don't build
302    # the static one
303    set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
304    set(SDL_STATIC_ENABLED_BY_DEFAULT OFF)
305  endif()
306endif()
307
308set(SDL_SUBSYSTEMS
309    Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
310    File Loadso CPUinfo Filesystem Dlopen Sensor Locale)
311foreach(_SUB ${SDL_SUBSYSTEMS})
312  string(TOUPPER ${_SUB} _OPT)
313  if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
314    set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
315  endif()
316  option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
317endforeach()
318
319option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
320#set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
321set_option(LIBC                "Use the system C library" ${OPT_DEF_LIBC})
322set_option(GCC_ATOMICS         "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS})
323set_option(ASSEMBLY            "Enable assembly routines" ${OPT_DEF_ASM})
324set_option(SSEMATH             "Allow GCC to use SSE floating point math" ${OPT_DEF_SSEMATH})
325set_option(MMX                 "Use MMX assembly routines" ${OPT_DEF_ASM})
326set_option(3DNOW               "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
327set_option(SSE                 "Use SSE assembly routines" ${OPT_DEF_ASM})
328set_option(SSE2                "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
329set_option(SSE3                "Use SSE3 assembly routines" ${OPT_DEF_SSEMATH})
330set_option(ALTIVEC             "Use Altivec assembly routines" ${OPT_DEF_ASM})
331set_option(ARMSIMD             "use SIMD assembly blitters on ARM" OFF)
332set_option(ARMNEON             "use NEON assembly blitters on ARM" OFF)
333set_option(DISKAUDIO           "Support the disk writer audio driver" ON)
334set_option(DUMMYAUDIO          "Support the dummy audio driver" ON)
335set_option(VIDEO_DIRECTFB      "Use DirectFB video driver" OFF)
336dep_option(DIRECTFB_SHARED     "Dynamically load directfb support" ON "VIDEO_DIRECTFB" OFF)
337set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
338set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
339set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
340set_option(PTHREADS            "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
341dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
342set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ${SDL_DLOPEN_ENABLED_BY_DEFAULT})
343dep_option(OSS                 "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF)
344set_option(ALSA                "Support the ALSA audio API" ${UNIX_SYS})
345dep_option(ALSA_SHARED         "Dynamically load ALSA audio support" ON "ALSA" OFF)
346set_option(JACK                "Support the JACK audio API" ${UNIX_SYS})
347dep_option(JACK_SHARED         "Dynamically load JACK audio support" ON "JACK" OFF)
348set_option(ESD                 "Support the Enlightened Sound Daemon" ${UNIX_SYS})
349dep_option(ESD_SHARED          "Dynamically load ESD audio support" ON "ESD" OFF)
350set_option(PULSEAUDIO          "Use PulseAudio" ${UNIX_SYS})
351dep_option(PULSEAUDIO_SHARED   "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF)
352set_option(ARTS                "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
353dep_option(ARTS_SHARED         "Dynamically load aRts audio support" ON "ARTS" OFF)
354set_option(NAS                 "Support the NAS audio API" ${UNIX_SYS})
355set_option(NAS_SHARED          "Dynamically load NAS audio API" ${UNIX_SYS})
356set_option(SNDIO               "Support the sndio audio API" ${UNIX_SYS})
357dep_option(SNDIO_SHARED        "Dynamically load the sndio audio API" ${UNIX_SYS} ON "SNDIO" OFF)
358set_option(FUSIONSOUND         "Use FusionSound audio driver" OFF)
359dep_option(FUSIONSOUND_SHARED  "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF)
360set_option(LIBSAMPLERATE       "Use libsamplerate for audio rate conversion" ${UNIX_SYS})
361dep_option(LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON "LIBSAMPLERATE" OFF)
362set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
363set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
364set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
365set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
366set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
367dep_option(WAYLAND_SHARED      "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
368dep_option(VIDEO_WAYLAND_QT_TOUCH  "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
369set_option(VIDEO_RPI           "Use Raspberry Pi video driver" ${UNIX_SYS})
370dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
371set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
372foreach(_SUB ${SDL_X11_OPTIONS})
373  string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
374  dep_option(${_OPT}           "Enable ${_SUB} support" ON "VIDEO_X11" OFF)
375endforeach()
376set_option(VIDEO_COCOA         "Use Cocoa video driver" ${APPLE})
377set_option(DIRECTX             "Use DirectX for Windows audio/video" ${WINDOWS})
378set_option(WASAPI              "Use the Windows WASAPI audio driver" ${WINDOWS})
379set_option(RENDER_D3D          "Enable the Direct3D render driver" ${WINDOWS})
380set_option(RENDER_METAL        "Enable the Metal render driver" ${APPLE})
381set_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ${UNIX_SYS})
382dep_option(VIDEO_VULKAN        "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
383set_option(VIDEO_METAL         "Enable Metal support" ${APPLE})
384set_option(VIDEO_KMSDRM        "Use KMS DRM video driver" ${UNIX_SYS})
385dep_option(KMSDRM_SHARED       "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
386set_option(VIDEO_OFFSCREEN     "Use offscreen video driver" OFF)
387option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
388option_string(FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
389set_option(HIDAPI              "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
390set_option(JOYSTICK_VIRTUAL    "Enable the virtual-joystick driver" ON)
391
392set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
393set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
394
395dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
396set_option(SDL_TEST            "Build the test directory" OFF)
397
398# General source files
399file(GLOB SOURCE_FILES
400  ${SDL2_SOURCE_DIR}/src/*.c
401  ${SDL2_SOURCE_DIR}/src/atomic/*.c
402  ${SDL2_SOURCE_DIR}/src/audio/*.c
403  ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
404  ${SDL2_SOURCE_DIR}/src/dynapi/*.c
405  ${SDL2_SOURCE_DIR}/src/events/*.c
406  ${SDL2_SOURCE_DIR}/src/file/*.c
407  ${SDL2_SOURCE_DIR}/src/libm/*.c
408  ${SDL2_SOURCE_DIR}/src/locale/*.c
409  ${SDL2_SOURCE_DIR}/src/power/*.c
410  ${SDL2_SOURCE_DIR}/src/render/*.c
411  ${SDL2_SOURCE_DIR}/src/render/*/*.c
412  ${SDL2_SOURCE_DIR}/src/sensor/*.c
413  ${SDL2_SOURCE_DIR}/src/stdlib/*.c
414  ${SDL2_SOURCE_DIR}/src/thread/*.c
415  ${SDL2_SOURCE_DIR}/src/timer/*.c
416  ${SDL2_SOURCE_DIR}/src/video/*.c
417  ${SDL2_SOURCE_DIR}/src/video/yuv2rgb/*.c)
418
419
420if(ASSERTIONS STREQUAL "auto")
421  # Do nada - use optimization settings to determine the assertion level
422elseif(ASSERTIONS STREQUAL "disabled")
423  set(SDL_DEFAULT_ASSERT_LEVEL 0)
424elseif(ASSERTIONS STREQUAL "release")
425  set(SDL_DEFAULT_ASSERT_LEVEL 1)
426elseif(ASSERTIONS STREQUAL "enabled")
427  set(SDL_DEFAULT_ASSERT_LEVEL 2)
428elseif(ASSERTIONS STREQUAL "paranoid")
429  set(SDL_DEFAULT_ASSERT_LEVEL 3)
430else()
431  message_error("unknown assertion level")
432endif()
433set(HAVE_ASSERTIONS ${ASSERTIONS})
434
435if(NOT BACKGROUNDING_SIGNAL STREQUAL "OFF")
436  add_definitions("-DSDL_BACKGROUNDING_SIGNAL=${BACKGROUNDING_SIGNAL}")
437endif()
438
439if(NOT FOREGROUNDING_SIGNAL STREQUAL "OFF")
440  add_definitions("-DSDL_FOREGROUNDING_SIGNAL=${FOREGROUNDING_SIGNAL}")
441endif()
442
443# Compiler option evaluation
444if(USE_GCC OR USE_CLANG)
445  # Check for -Wall first, so later things can override pieces of it.
446  check_c_compiler_flag(-Wall HAVE_GCC_WALL)
447  if(HAVE_GCC_WALL)
448    list(APPEND EXTRA_CFLAGS "-Wall")
449    if(HAIKU)
450      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
451    endif()
452  endif()
453
454  check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
455  if(HAVE_GCC_NO_STRICT_ALIASING)
456    list(APPEND EXTRA_CFLAGS "-fno-strict-aliasing")
457  endif()
458
459  check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
460  if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
461    check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
462    if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
463      list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
464    endif()
465    list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
466  endif()
467
468  if(DEPENDENCY_TRACKING)
469    check_c_source_compiles("
470        #if !defined(__GNUC__) || __GNUC__ < 3
471        #error Dependency tracking requires GCC 3.0 or newer
472        #endif
473        int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
474  endif()
475
476  if(GCC_ATOMICS)
477    check_c_source_compiles("int main(int argc, char **argv) {
478        int a;
479        void *x, *y, *z;
480        __sync_lock_test_and_set(&a, 4);
481        __sync_lock_test_and_set(&x, y);
482        __sync_fetch_and_add(&a, 1);
483        __sync_bool_compare_and_swap(&a, 5, 10);
484        __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
485    if(NOT HAVE_GCC_ATOMICS)
486      check_c_source_compiles("int main(int argc, char **argv) {
487          int a;
488          __sync_lock_test_and_set(&a, 1);
489          __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
490    endif()
491  endif()
492
493  set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
494  check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
495    HAVE_GCC_PREFERRED_STACK_BOUNDARY)
496  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
497
498  set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
499  check_c_source_compiles("
500      #if !defined(__GNUC__) || __GNUC__ < 4
501      #error SDL only uses visibility attributes in GCC 4 or newer
502      #endif
503      int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
504  if(HAVE_GCC_FVISIBILITY)
505    list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
506  endif()
507  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
508
509  check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
510  if(HAVE_GCC_WSHADOW)
511    list(APPEND EXTRA_CFLAGS "-Wshadow")
512  endif()
513
514  if(APPLE)
515    list(APPEND EXTRA_LDFLAGS "-Wl,-undefined,error")
516    list(APPEND EXTRA_LDFLAGS "-Wl,-compatibility_version,${DYLIB_COMPATIBILITY_VERSION}")
517    list(APPEND EXTRA_LDFLAGS "-Wl,-current_version,${DYLIB_CURRENT_VERSION}")
518  else()
519    set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
520    check_c_compiler_flag("" HAVE_NO_UNDEFINED)
521    set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
522    if(HAVE_NO_UNDEFINED)
523      list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
524    endif()
525  endif()
526endif()
527
528if(ASSEMBLY)
529  if(USE_GCC OR USE_CLANG)
530    set(SDL_ASSEMBLY_ROUTINES 1)
531    # TODO: Those all seem to be quite GCC specific - needs to be
532    # reworked for better compiler support
533    set(HAVE_ASSEMBLY TRUE)
534    if(MMX)
535      set(CMAKE_REQUIRED_FLAGS "-mmmx")
536      check_c_source_compiles("
537          #ifdef __MINGW32__
538          #include <_mingw.h>
539          #ifdef __MINGW64_VERSION_MAJOR
540          #include <intrin.h>
541          #else
542          #include <mmintrin.h>
543          #endif
544          #else
545          #include <mmintrin.h>
546          #endif
547          #ifndef __MMX__
548          #error Assembler CPP flag not enabled
549          #endif
550          int main(int argc, char **argv) { }" HAVE_MMX)
551      if(HAVE_MMX)
552        list(APPEND EXTRA_CFLAGS "-mmmx")
553      endif()
554      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
555    endif()
556
557    if(3DNOW)
558      set(CMAKE_REQUIRED_FLAGS "-m3dnow")
559      check_c_source_compiles("
560          #include <mm3dnow.h>
561          #ifndef __3dNOW__
562          #error Assembler CPP flag not enabled
563          #endif
564          int main(int argc, char **argv) {
565            void *p = 0;
566            _m_prefetch(p);
567          }" HAVE_3DNOW)
568      if(HAVE_3DNOW)
569        list(APPEND EXTRA_CFLAGS "-m3dnow")
570      endif()
571      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
572    endif()
573
574    if(SSE)
575      set(CMAKE_REQUIRED_FLAGS "-msse")
576      check_c_source_compiles("
577          #ifdef __MINGW32__
578          #include <_mingw.h>
579          #ifdef __MINGW64_VERSION_MAJOR
580          #include <intrin.h>
581          #else
582          #include <xmmintrin.h>
583          #endif
584          #else
585          #include <xmmintrin.h>
586          #endif
587          #ifndef __SSE__
588          #error Assembler CPP flag not enabled
589          #endif
590          int main(int argc, char **argv) { }" HAVE_SSE)
591      if(HAVE_SSE)
592        list(APPEND EXTRA_CFLAGS "-msse")
593      endif()
594      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
595    endif()
596
597    if(SSE2)
598      set(CMAKE_REQUIRED_FLAGS "-msse2")
599      check_c_source_compiles("
600          #ifdef __MINGW32__
601          #include <_mingw.h>
602          #ifdef __MINGW64_VERSION_MAJOR
603          #include <intrin.h>
604          #else
605          #include <emmintrin.h>
606          #endif
607          #else
608          #include <emmintrin.h>
609          #endif
610          #ifndef __SSE2__
611          #error Assembler CPP flag not enabled
612          #endif
613          int main(int argc, char **argv) { }" HAVE_SSE2)
614      if(HAVE_SSE2)
615        list(APPEND EXTRA_CFLAGS "-msse2")
616      endif()
617      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
618    endif()
619
620    if(SSE3)
621      set(CMAKE_REQUIRED_FLAGS "-msse3")
622      check_c_source_compiles("
623          #ifdef __MINGW32__
624          #include <_mingw.h>
625          #ifdef __MINGW64_VERSION_MAJOR
626          #include <intrin.h>
627          #else
628          #include <pmmintrin.h>
629          #endif
630          #else
631          #include <pmmintrin.h>
632          #endif
633          #ifndef __SSE3__
634          #error Assembler CPP flag not enabled
635          #endif
636          int main(int argc, char **argv) { }" HAVE_SSE3)
637      if(HAVE_SSE3)
638        list(APPEND EXTRA_CFLAGS "-msse3")
639      endif()
640      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
641    endif()
642
643    if(NOT SSEMATH)
644      if(SSE OR SSE2 OR SSE3)
645        if(USE_GCC)
646          check_c_compiler_flag(-mfpmath=387 HAVE_FP_387)
647          if(HAVE_FP_387)
648            list(APPEND EXTRA_CFLAGS "-mfpmath=387")
649          endif()
650        endif()
651        set(HAVE_SSEMATH TRUE)
652      endif()
653    endif()
654
655    check_include_file("immintrin.h" HAVE_IMMINTRIN_H)
656
657    if(ALTIVEC)
658      set(CMAKE_REQUIRED_FLAGS "-maltivec")
659      check_c_source_compiles("
660          #include <altivec.h>
661          vector unsigned int vzero() {
662              return vec_splat_u32(0);
663          }
664          int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
665      check_c_source_compiles("
666          vector unsigned int vzero() {
667              return vec_splat_u32(0);
668          }
669          int main(int argc, char **argv) { }" HAVE_ALTIVEC)
670      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
671      if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
672        set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
673        list(APPEND EXTRA_CFLAGS "-maltivec")
674        set(SDL_ALTIVEC_BLITTERS 1)
675        if(HAVE_ALTIVEC_H_HDR)
676          set(HAVE_ALTIVEC_H 1)
677        endif()
678      endif()
679    endif()
680
681    if(ARMSIMD)
682      set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
683      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
684      check_c_source_compiles("
685        .text
686        .arch armv6
687        .object_arch armv4
688        .arm
689        .altmacro
690        #ifndef __ARM_EABI__
691        #error EABI is required (to be sure that calling conventions are compatible)
692        #endif
693        pld [r0]
694        uqadd8 r0, r0, r0
695      " ARMSIMD_FOUND)
696      set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
697
698      if(ARMSIMD_FOUND)
699        set(HAVE_ARMSIMD TRUE)
700        set(SDL_ARM_SIMD_BLITTERS 1)
701        file(GLOB ARMSIMD_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S)
702        set(SOURCE_FILES ${SOURCE_FILES} ${ARMSIMD_SOURCES})
703        set(WARN_ABOUT_ARM_SIMD_ASM_MIT TRUE)
704      endif()
705    endif()
706
707    if(ARMNEON)
708      set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
709      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
710      check_c_source_compiles("
711        .text
712        .fpu neon
713        .arch armv7a
714        .object_arch armv4
715        .eabi_attribute 10, 0
716        .arm
717        .altmacro
718        #ifndef __ARM_EABI__
719        #error EABI is required (to be sure that calling conventions are compatible)
720        #endif
721        pld [r0]
722        vmovn.u16 d0, q0
723      " ARMNEON_FOUND)
724      set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
725
726      if(ARMNEON_FOUND)
727        set(HAVE_ARMNEON TRUE)
728        set(SDL_ARM_NEON_BLITTERS 1)
729        file(GLOB ARMNEON_SOURCES ${SDL2_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S)
730        set(SOURCE_FILES ${SOURCE_FILES} ${ARMNEON_SOURCES})
731        set(WARN_ABOUT_ARM_NEON_ASM_MIT TRUE)
732      endif()
733    endif()
734
735  elseif(MSVC_VERSION GREATER 1500)
736    # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
737    # for MSVC - right now it is always activated
738    if(NOT ARCH_64)
739      set(HAVE_MMX TRUE)
740      set(HAVE_3DNOW TRUE)
741    endif()
742    set(HAVE_SSE TRUE)
743    set(HAVE_SSE2 TRUE)
744    set(HAVE_SSE3 TRUE)
745    set(SDL_ASSEMBLY_ROUTINES 1)
746  endif()
747# TODO:
748#else()
749#  if(USE_GCC OR USE_CLANG)
750#    list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-sse3" "-mno-mmx")
751#  endif()
752endif()
753
754# TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
755# anything.
756if(LIBC)
757  if(WINDOWS AND NOT MINGW)
758    set(HAVE_LIBC TRUE)
759    foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h)
760      string(TOUPPER "HAVE_${_HEADER}" _UPPER)
761      string(REPLACE "." "_" _HAVE_H ${_UPPER})
762      set(${_HAVE_H} 1)
763    endforeach()
764    set(HAVE_SIGNAL_H 1)
765    foreach(_FN
766            malloc calloc realloc free qsort abs memset memcpy memmove memcmp
767            wcslen wcslcpy wcslcat wcsdup wcsstr wcscmp wcsncmp
768            strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
769            _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
770            _stricmp _strnicmp strtok_s sscanf
771            acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf
772            copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf
773            log logf log10 log10f pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf
774            trunc truncf)
775      string(TOUPPER ${_FN} _UPPER)
776      set(HAVE_${_UPPER} 1)
777    endforeach()
778    if(NOT CYGWIN AND NOT MINGW)
779      set(HAVE_ALLOCA 1)
780    endif()
781    set(HAVE_M_PI 1)
782    add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
783    set(STDC_HEADERS 1)
784  else()
785    set(HAVE_LIBC TRUE)
786    check_include_file(sys/types.h HAVE_SYS_TYPES_H)
787    foreach(_HEADER
788            stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h limits.h
789            strings.h wchar.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h libunwind.h)
790      string(TOUPPER "HAVE_${_HEADER}" _UPPER)
791      string(REPLACE "." "_" _HAVE_H ${_UPPER})
792      check_include_file("${_HEADER}" ${_HAVE_H})
793    endforeach()
794
795    set(STDC_HEADER_NAMES "dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;stdio.h;strings.h;wchar.h;string.h;float.h")
796    check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
797    check_type_size("size_t" SIZEOF_SIZE_T)
798    check_symbol_exists(M_PI math.h HAVE_M_PI)
799    # TODO: refine the mprotect check
800    check_c_source_compiles("#include <sys/types.h>
801                             #include <sys/mman.h>
802                             int main() { }" HAVE_MPROTECT)
803    foreach(_FN
804            strtod malloc calloc realloc free getenv setenv putenv unsetenv
805            qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
806            _strrev _strupr _strlwr strchr strrchr strstr strtok_r itoa _ltoa
807            _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
808            atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
809            wcscmp wcsdup wcslcat wcslcpy wcslen wcsncmp wcsstr
810            sscanf vsscanf vsnprintf fopen64 fseeko fseeko64 _Exit
811            )
812      string(TOUPPER ${_FN} _UPPER)
813      set(_HAVEVAR "HAVE_${_UPPER}")
814      check_symbol_exists("${_FN}" "${STDC_HEADER_NAMES}" ${_HAVEVAR})
815    endforeach()
816
817    check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION)
818    check_symbol_exists(setjmp "setjmp.h" HAVE_SETJMP)
819    check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP)
820    check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF)
821    check_symbol_exists(sysctlbyname "sys/types.h;sys/sysctl.h" HAVE_SYSCTLBYNAME)
822    check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL)
823    check_symbol_exists(poll "poll.h" HAVE_POLL)
824
825    check_library_exists(m pow "" HAVE_LIBM)
826    if(HAVE_LIBM)
827      set(CMAKE_REQUIRED_LIBRARIES m)
828      foreach(_FN
829              atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf
830              exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f
831              pow powf scalbn scalbnf sin sinf sqrt sqrtf tan tanf acos acosf
832              asin asinf trunc truncf)
833        string(TOUPPER ${_FN} _UPPER)
834        set(_HAVEVAR "HAVE_${_UPPER}")
835        check_symbol_exists("${_FN}" "math.h" ${_HAVEVAR})
836      endforeach()
837      set(CMAKE_REQUIRED_LIBRARIES)
838      list(APPEND EXTRA_LIBS m)
839    endif()
840
841    check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
842    if(HAVE_LIBICONV)
843      list(APPEND EXTRA_LIBS iconv)
844      set(HAVE_ICONV 1)
845    endif()
846
847    if(NOT APPLE)
848      check_include_file(alloca.h HAVE_ALLOCA_H)
849      check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA)
850    else()
851      set(HAVE_ALLOCA_H 1)
852      set(HAVE_ALLOCA 1)
853    endif()
854
855    check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
856  endif()
857else()
858  if(WINDOWS)
859    set(HAVE_STDARG_H 1)
860    set(HAVE_STDDEF_H 1)
861  endif()
862endif()
863
864
865# Enable/disable various subsystems of the SDL library
866foreach(_SUB ${SDL_SUBSYSTEMS})
867  string(TOUPPER ${_SUB} _OPT)
868  if(NOT SDL_${_OPT})
869    set(SDL_${_OPT}_DISABLED 1)
870  endif()
871endforeach()
872if(SDL_JOYSTICK)
873  file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
874  set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
875endif()
876if(SDL_HAPTIC)
877  if(NOT SDL_JOYSTICK)
878    # Haptic requires some private functions from the joystick subsystem.
879    message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
880  endif()
881  file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
882  set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
883endif()
884
885
886# TODO: in configure.ac, the test for LOADSO and SDL_DLOPEN is a bit weird:
887# if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
888# If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
889# SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
890
891# General SDL subsystem options, valid for all platforms
892if(SDL_AUDIO)
893  # CheckDummyAudio/CheckDiskAudio - valid for all platforms
894  if(DUMMYAUDIO)
895    set(SDL_AUDIO_DRIVER_DUMMY 1)
896    file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
897    set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
898    set(HAVE_DUMMYAUDIO TRUE)
899  endif()
900  if(DISKAUDIO)
901    set(SDL_AUDIO_DRIVER_DISK 1)
902    file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
903    set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
904    set(HAVE_DISKAUDIO TRUE)
905  endif()
906endif()
907
908if(SDL_DLOPEN)
909  # Relevant for Unix/Darwin only
910  if(UNIX OR APPLE)
911    CheckDLOPEN()
912  endif()
913endif()
914
915if(SDL_JOYSTICK)
916  if(JOYSTICK_VIRTUAL)
917    set(SDL_JOYSTICK_VIRTUAL 1)
918    file(GLOB JOYSTICK_VIRTUAL_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/virtual/*.c)
919    set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_VIRTUAL_SOURCES})
920  endif()
921endif()
922
923if(SDL_VIDEO)
924  if(VIDEO_DUMMY)
925    set(SDL_VIDEO_DRIVER_DUMMY 1)
926    file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
927    set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
928    set(HAVE_VIDEO_DUMMY TRUE)
929    set(HAVE_SDL_VIDEO TRUE)
930  endif()
931  if(VIDEO_OFFSCREEN)
932    set(SDL_VIDEO_DRIVER_OFFSCREEN 1)
933    file(GLOB VIDEO_OFFSCREEN_SOURCES ${SDL2_SOURCE_DIR}/src/video/offscreen/*.c)
934    set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_OFFSCREEN_SOURCES})
935    set(HAVE_VIDEO_OFFSCREEN TRUE)
936    set(HAVE_SDL_VIDEO TRUE)
937  endif()
938endif()
939
940# Platform-specific options and settings
941if(ANDROID)
942  file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
943  set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
944
945  # SDL_spinlock.c Needs to be compiled in ARM mode.
946  # There seems to be no better way currently to set the ARM mode.
947  # see: https://issuetracker.google.com/issues/62264618
948  # Another option would be to set ARM mode to all compiled files
949  check_c_compiler_flag(-marm HAVE_ARM_MODE)
950  if(HAVE_ARM_MODE)
951    set_source_files_properties(${SDL2_SOURCE_DIR}/src/atomic/SDL_spinlock.c PROPERTIES COMPILE_FLAGS -marm)
952  endif()
953
954  file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
955  set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${ANDROID_MAIN_SOURCES})
956
957  if(SDL_AUDIO)
958    set(SDL_AUDIO_DRIVER_ANDROID 1)
959    file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
960    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
961    set(HAVE_SDL_AUDIO TRUE)
962  endif()
963  if(SDL_FILESYSTEM)
964    set(SDL_FILESYSTEM_ANDROID 1)
965    file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
966    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
967    set(HAVE_SDL_FILESYSTEM TRUE)
968  endif()
969  if(SDL_HAPTIC)
970    set(SDL_HAPTIC_ANDROID 1)
971    file(GLOB ANDROID_HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/android/*.c)
972    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
973    set(HAVE_SDL_HAPTIC TRUE)
974  endif()
975  if(SDL_JOYSTICK)
976    CheckHIDAPI()
977    set(SDL_JOYSTICK_ANDROID 1)
978    file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
979    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
980    set(HAVE_SDL_JOYSTICK TRUE)
981  endif()
982  if(SDL_LOADSO)
983    set(SDL_LOADSO_DLOPEN 1)
984    file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
985    set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
986    set(HAVE_SDL_LOADSO TRUE)
987  endif()
988  if(SDL_POWER)
989    set(SDL_POWER_ANDROID 1)
990    file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
991    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
992    set(HAVE_SDL_POWER TRUE)
993  endif()
994  if(SDL_LOCALE)
995    file(GLOB ANDROID_LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/android/*.c)
996    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_LOCALE_SOURCES})
997    set(HAVE_SDL_LOCALE TRUE)
998  endif()
999  if(SDL_TIMERS)
1000    set(SDL_TIMER_UNIX 1)
1001    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1002    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1003    set(HAVE_SDL_TIMERS TRUE)
1004  endif()
1005  if(SDL_SENSOR)
1006    set(SDL_SENSOR_ANDROID 1)
1007    set(HAVE_SDL_SENSORS TRUE)
1008    file(GLOB ANDROID_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/android/*.c)
1009    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_SENSOR_SOURCES})
1010  endif()
1011  if(SDL_VIDEO)
1012    set(SDL_VIDEO_DRIVER_ANDROID 1)
1013    file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
1014    set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
1015    set(HAVE_SDL_VIDEO TRUE)
1016
1017    # Core stuff
1018    # find_library(ANDROID_DL_LIBRARY dl)
1019    # FIXME failing dlopen https://github.com/android-ndk/ndk/issues/929
1020    find_library(ANDROID_DL_LIBRARY NAMES libdl.so dl)
1021    find_library(ANDROID_LOG_LIBRARY log)
1022    find_library(ANDROID_LIBRARY_LIBRARY android)
1023    list(APPEND EXTRA_LIBS ${ANDROID_DL_LIBRARY} ${ANDROID_LOG_LIBRARY} ${ANDROID_LIBRARY_LIBRARY})
1024    add_definitions(-DGL_GLEXT_PROTOTYPES)
1025
1026    if (HAVE_HIDAPI)
1027        list(APPEND EXTRA_LIBS hidapi)
1028    endif()
1029
1030    #enable gles
1031    if(VIDEO_OPENGLES)
1032      set(SDL_VIDEO_OPENGL_EGL 1)
1033      set(HAVE_VIDEO_OPENGLES TRUE)
1034      set(SDL_VIDEO_OPENGL_ES 1)
1035      set(SDL_VIDEO_RENDER_OGL_ES 1)
1036      set(SDL_VIDEO_OPENGL_ES2 1)
1037      set(SDL_VIDEO_RENDER_OGL_ES2 1)
1038
1039      find_library(OpenGLES1_LIBRARY GLESv1_CM)
1040      find_library(OpenGLES2_LIBRARY GLESv2)
1041      list(APPEND EXTRA_LIBS ${OpenGLES1_LIBRARY} ${OpenGLES2_LIBRARY})
1042    endif()
1043
1044    CHECK_C_SOURCE_COMPILES("
1045    #if defined(__ARM_ARCH) && __ARM_ARCH < 7
1046    #error Vulkan doesn't work on this configuration
1047    #endif
1048    int main()
1049    {
1050        return 0;
1051    }
1052    " VULKAN_PASSED_ANDROID_CHECKS)
1053    if(NOT VULKAN_PASSED_ANDROID_CHECKS)
1054      set(VIDEO_VULKAN OFF)
1055      message(STATUS "Vulkan doesn't work on this configuration")
1056    endif()
1057  endif()
1058
1059  CheckPTHREAD()
1060
1061elseif(EMSCRIPTEN)
1062  # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
1063  # project. Uncomment at will for verbose cross-compiling -I/../ path info.
1064  add_definitions(-Wno-warn-absolute-paths)
1065  if(SDL_AUDIO)
1066    set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
1067    file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
1068    set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
1069    set(HAVE_SDL_AUDIO TRUE)
1070  endif()
1071  if(SDL_FILESYSTEM)
1072    set(SDL_FILESYSTEM_EMSCRIPTEN 1)
1073    file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
1074    set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
1075    set(HAVE_SDL_FILESYSTEM TRUE)
1076  endif()
1077  if(SDL_JOYSTICK)
1078    set(SDL_JOYSTICK_EMSCRIPTEN 1)
1079    file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
1080    set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
1081    set(HAVE_SDL_JOYSTICK TRUE)
1082  endif()
1083  if(SDL_POWER)
1084    set(SDL_POWER_EMSCRIPTEN 1)
1085    file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
1086    set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
1087    set(HAVE_SDL_POWER TRUE)
1088  endif()
1089  if(SDL_LOCALE)
1090    file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/emscripten/*.c)
1091    set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1092    set(HAVE_SDL_LOCALE TRUE)
1093  endif()
1094  if(SDL_TIMERS)
1095    set(SDL_TIMER_UNIX 1)
1096    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1097    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1098    set(HAVE_SDL_TIMERS TRUE)
1099
1100    if(CLOCK_GETTIME)
1101      set(HAVE_CLOCK_GETTIME 1)
1102    endif()
1103  endif()
1104  if(SDL_VIDEO)
1105    set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
1106    file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
1107    set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
1108    set(HAVE_SDL_VIDEO TRUE)
1109
1110    #enable gles
1111    if(VIDEO_OPENGLES)
1112      set(SDL_VIDEO_OPENGL_EGL 1)
1113      set(HAVE_VIDEO_OPENGLES TRUE)
1114      set(SDL_VIDEO_OPENGL_ES2 1)
1115      set(SDL_VIDEO_RENDER_OGL_ES2 1)
1116    endif()
1117  endif()
1118
1119elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
1120  if(SDL_AUDIO)
1121    if(SYSV5 OR SOLARIS OR HPUX)
1122        set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
1123        file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
1124        set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
1125        set(HAVE_SDL_AUDIO TRUE)
1126    elseif(NETBSD)
1127        set(SDL_AUDIO_DRIVER_NETBSD 1)
1128        file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
1129        set(SOURCE_FILES ${SOURCE_FILES} ${NETBSD_AUDIO_SOURCES})
1130        set(HAVE_SDL_AUDIO TRUE)
1131    elseif(AIX)
1132        set(SDL_AUDIO_DRIVER_PAUDIO 1)
1133        file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
1134        set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
1135        set(HAVE_SDL_AUDIO TRUE)
1136    endif()
1137    CheckOSS()
1138    CheckALSA()
1139    CheckJACK()
1140    CheckPulseAudio()
1141    CheckESD()
1142    CheckARTS()
1143    CheckNAS()
1144    CheckSNDIO()
1145    CheckFusionSound()
1146    CheckLibSampleRate()
1147  endif()
1148
1149  if(SDL_VIDEO)
1150    # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
1151    CheckRPI()
1152    CheckX11()
1153    CheckDirectFB()
1154    CheckOpenGLX11()
1155    CheckOpenGLESX11()
1156    CheckWayland()
1157    CheckVivante()
1158    CheckKMSDRM()
1159  endif()
1160
1161  if(UNIX)
1162    file(GLOB CORE_UNIX_SOURCES ${SDL2_SOURCE_DIR}/src/core/unix/*.c)
1163    set(SOURCE_FILES ${SOURCE_FILES} ${CORE_UNIX_SOURCES})
1164  endif()
1165
1166  if(LINUX)
1167    check_c_source_compiles("
1168        #include <linux/input.h>
1169        #ifndef EVIOCGNAME
1170        #error EVIOCGNAME() ioctl not available
1171        #endif
1172        int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
1173
1174    check_c_source_compiles("
1175        #include <linux/kd.h>
1176        #include <linux/keyboard.h>
1177
1178        int main(int argc, char **argv)
1179        {
1180            struct kbentry kbe;
1181            kbe.kb_table = KG_CTRL;
1182            ioctl(0, KDGKBENT, &kbe);
1183        }" HAVE_INPUT_KD)
1184
1185    if(HAVE_INPUT_EVENTS)
1186      set(SDL_INPUT_LINUXEV 1)
1187    endif()
1188
1189    if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
1190      set(SDL_HAPTIC_LINUX 1)
1191      file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
1192      set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1193      set(HAVE_SDL_HAPTIC TRUE)
1194    endif()
1195
1196    if(HAVE_INPUT_KD)
1197      set(SDL_INPUT_LINUXKD 1)
1198    endif()
1199
1200    check_include_file("libudev.h" HAVE_LIBUDEV_H)
1201
1202    if(PKG_CONFIG_FOUND)
1203      pkg_search_module(DBUS dbus-1 dbus)
1204      if(DBUS_FOUND)
1205        set(HAVE_DBUS_DBUS_H TRUE)
1206        include_directories(${DBUS_INCLUDE_DIRS})
1207        list(APPEND EXTRA_LIBS ${DBUS_LIBRARIES})
1208        # Fcitx need only dbus.
1209        set(HAVE_FCITX TRUE)
1210      endif()
1211
1212      pkg_search_module(IBUS ibus-1.0 ibus)
1213      if(IBUS_FOUND)
1214        set(HAVE_IBUS_IBUS_H TRUE)
1215        include_directories(${IBUS_INCLUDE_DIRS})
1216        list(APPEND EXTRA_LIBS ${IBUS_LIBRARIES})
1217      endif()
1218
1219      if (HAVE_IBUS_IBUS_H OR HAVE_FCITX)
1220        set(SDL_USE_IME TRUE)
1221        add_definitions(-DSDL_USE_IME)   # !!! FIXME: why isn't this a definition and not in SDL_config.h.cmake?
1222      endif()
1223      if(HAVE_LIBUNWIND_H)
1224        # We've already found the header, so REQUIRE the lib to be present
1225        pkg_search_module(UNWIND REQUIRED libunwind)
1226        pkg_search_module(UNWIND_GENERIC REQUIRED libunwind-generic)
1227        list(APPEND EXTRA_LIBS ${UNWIND_LIBRARIES} ${UNWIND_GENERIC_LIBRARIES})
1228      endif()
1229    endif()
1230
1231    if(HAVE_DBUS_DBUS_H)
1232      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_dbus.c")
1233    endif()
1234
1235    if(SDL_USE_IME)
1236      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ime.c")
1237    endif()
1238
1239    if(HAVE_IBUS_IBUS_H)
1240      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_ibus.c")
1241    endif()
1242
1243    if(HAVE_FCITX)
1244      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_fcitx.c")
1245    endif()
1246
1247    if(HAVE_LIBUDEV_H)
1248      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_udev.c")
1249    endif()
1250
1251    if(HAVE_INPUT_EVENTS)
1252      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev.c")
1253      set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_evdev_kbd.c")
1254    endif()
1255
1256    # Always compiled for Linux, unconditionally:
1257    set(SOURCE_FILES ${SOURCE_FILES} "${SDL2_SOURCE_DIR}/src/core/linux/SDL_threadprio.c")
1258
1259    # src/core/unix/*.c is included in a generic if(UNIX) section, elsewhere.
1260  endif()
1261
1262  if(INPUT_TSLIB)
1263    check_c_source_compiles("
1264        #include \"tslib.h\"
1265        int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
1266    if(HAVE_INPUT_TSLIB)
1267      set(SDL_INPUT_TSLIB 1)
1268      list(APPEND EXTRA_LIBS ts)
1269    endif()
1270  endif()
1271
1272  if(SDL_JOYSTICK)
1273    if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
1274      CheckUSBHID()
1275    endif()
1276    CheckHIDAPI()
1277    if(LINUX AND NOT ANDROID)
1278      set(SDL_JOYSTICK_LINUX 1)
1279      file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
1280      set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1281      set(HAVE_SDL_JOYSTICK TRUE)
1282    endif()
1283  endif()
1284
1285  CheckPTHREAD()
1286
1287  if(CLOCK_GETTIME)
1288    check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
1289    if(FOUND_CLOCK_GETTIME)
1290      list(APPEND EXTRA_LIBS rt)
1291      set(HAVE_CLOCK_GETTIME 1)
1292    else()
1293      check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
1294      if(FOUND_CLOCK_GETTIME)
1295        set(HAVE_CLOCK_GETTIME 1)
1296      endif()
1297    endif()
1298  endif()
1299
1300  check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
1301  if(HAVE_LINUX_VERSION_H)
1302    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
1303  endif()
1304
1305  if(SDL_POWER)
1306    if(LINUX)
1307      set(SDL_POWER_LINUX 1)
1308      file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
1309      set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
1310      set(HAVE_SDL_POWER TRUE)
1311    endif()
1312  endif()
1313
1314  if(SDL_LOCALE)
1315    file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/unix/*.c)
1316    set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1317    set(HAVE_SDL_LOCALE TRUE)
1318  endif()
1319
1320  if(SDL_FILESYSTEM)
1321    set(SDL_FILESYSTEM_UNIX 1)
1322    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
1323    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1324    set(HAVE_SDL_FILESYSTEM TRUE)
1325  endif()
1326
1327  if(SDL_TIMERS)
1328    set(SDL_TIMER_UNIX 1)
1329    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1330    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1331    set(HAVE_SDL_TIMERS TRUE)
1332  endif()
1333
1334  set(SDL_RLD_FLAGS "")
1335  if(RPATH AND SDL_SHARED)
1336    if(BSDI OR FREEBSD OR LINUX OR NETBSD)
1337      set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
1338      check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
1339      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1340      if(HAVE_ENABLE_NEW_DTAGS)
1341        set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
1342      else()
1343        set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
1344      endif()
1345    elseif(SOLARIS)
1346      set(SDL_RLD_FLAGS "-R\${libdir}")
1347    endif()
1348    set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
1349    set(HAVE_RPATH TRUE)
1350  endif()
1351
1352elseif(WINDOWS)
1353  find_program(WINDRES windres)
1354
1355  check_c_source_compiles("
1356    #include <windows.h>
1357    int main(int argc, char **argv) { }" HAVE_WIN32_CC)
1358
1359  file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
1360  set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
1361
1362  if(MSVC)
1363    # Prevent codegen that would use the VC runtime libraries.
1364    set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-")
1365    if(NOT ARCH_64)
1366      set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE")
1367    endif()
1368  endif()
1369
1370  # Check for DirectX
1371  if(DIRECTX)
1372    if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
1373        set(USE_WINSDK_DIRECTX TRUE)
1374    endif()
1375    if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
1376      if("$ENV{DXSDK_DIR}" STREQUAL "")
1377        message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
1378      endif()
1379      set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
1380    endif()
1381
1382    if(HAVE_WIN32_CC)
1383      # xinput.h may need windows.h, but doesn't include it itself.
1384      check_c_source_compiles("
1385        #include <windows.h>
1386        #include <xinput.h>
1387        int main(int argc, char **argv) { }" HAVE_XINPUT_H)
1388      check_c_source_compiles("
1389        #include <windows.h>
1390        #include <xinput.h>
1391        XINPUT_GAMEPAD_EX x1;
1392        int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
1393      check_c_source_compiles("
1394        #include <windows.h>
1395        #include <xinput.h>
1396        XINPUT_STATE_EX s1;
1397        int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
1398    else()
1399      check_include_file(xinput.h HAVE_XINPUT_H)
1400    endif()
1401
1402    check_include_file(d3d9.h HAVE_D3D_H)
1403    check_include_file(d3d11_1.h HAVE_D3D11_H)
1404    check_include_file(ddraw.h HAVE_DDRAW_H)
1405    check_include_file(dsound.h HAVE_DSOUND_H)
1406    check_include_file(dinput.h HAVE_DINPUT_H)
1407    check_include_file(dxgi.h HAVE_DXGI_H)
1408    if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H)
1409      set(HAVE_DIRECTX TRUE)
1410      if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
1411      # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
1412        link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
1413        include_directories($ENV{DXSDK_DIR}\\Include)
1414      endif()
1415    endif()
1416    set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1417  endif()
1418
1419  # headers needed elsewhere
1420  check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1421  check_include_file(audioclient.h HAVE_AUDIOCLIENT_H)
1422
1423  if(SDL_AUDIO)
1424    set(SDL_AUDIO_DRIVER_WINMM 1)
1425    file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
1426    set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
1427    set(HAVE_SDL_AUDIO TRUE)
1428
1429    if(HAVE_DSOUND_H)
1430      set(SDL_AUDIO_DRIVER_DSOUND 1)
1431      file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
1432      set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
1433    endif()
1434
1435    if(WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H)
1436      set(SDL_AUDIO_DRIVER_WASAPI 1)
1437      file(GLOB WASAPI_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/wasapi/*.c)
1438      set(SOURCE_FILES ${SOURCE_FILES} ${WASAPI_AUDIO_SOURCES})
1439    endif()
1440  endif()
1441
1442  if(SDL_VIDEO)
1443    # requires SDL_LOADSO on Windows (IME, DX, etc.)
1444    if(NOT SDL_LOADSO)
1445      message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
1446    endif()
1447    set(SDL_VIDEO_DRIVER_WINDOWS 1)
1448    file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
1449    set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
1450
1451    if(RENDER_D3D AND HAVE_D3D_H)
1452      set(SDL_VIDEO_RENDER_D3D 1)
1453      set(HAVE_RENDER_D3D TRUE)
1454    endif()
1455    if(RENDER_D3D AND HAVE_D3D11_H)
1456      set(SDL_VIDEO_RENDER_D3D11 1)
1457      set(HAVE_RENDER_D3D TRUE)
1458    endif()
1459    set(HAVE_SDL_VIDEO TRUE)
1460  endif()
1461
1462  if(SDL_THREADS)
1463    set(SDL_THREAD_WINDOWS 1)
1464    set(SOURCE_FILES ${SOURCE_FILES}
1465      ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
1466      ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
1467      ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
1468      ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
1469      ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
1470    set(HAVE_SDL_THREADS TRUE)
1471  endif()
1472
1473  if(SDL_SENSOR)
1474    set(SDL_SENSOR_WINDOWS 1)
1475    set(HAVE_SDL_SENSORS TRUE)
1476    file(GLOB WINDOWS_SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/windows/*.c)
1477    set(SOURCE_FILES ${SOURCE_FILES} ${WINDOWS_SENSOR_SOURCES})
1478  endif()
1479
1480  if(SDL_POWER)
1481    set(SDL_POWER_WINDOWS 1)
1482    set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
1483    set(HAVE_SDL_POWER TRUE)
1484  endif()
1485
1486  if(SDL_LOCALE)
1487    file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/windows/*.c)
1488    set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1489    set(HAVE_SDL_LOCALE TRUE)
1490  endif()
1491
1492  if(SDL_FILESYSTEM)
1493    set(SDL_FILESYSTEM_WINDOWS 1)
1494    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
1495    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1496    set(HAVE_SDL_FILESYSTEM TRUE)
1497  endif()
1498
1499  # Libraries for Win32 native and MinGW
1500  list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)
1501
1502  # TODO: in configure.ac the check for timers is set on
1503  # cygwin | mingw32* - does this include mingw32CE?
1504  if(SDL_TIMERS)
1505    set(SDL_TIMER_WINDOWS 1)
1506    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
1507    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1508    set(HAVE_SDL_TIMERS TRUE)
1509  endif()
1510
1511  if(SDL_LOADSO)
1512    set(SDL_LOADSO_WINDOWS 1)
1513    file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
1514    set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
1515    set(HAVE_SDL_LOADSO TRUE)
1516  endif()
1517
1518  file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
1519  set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
1520
1521  if(SDL_VIDEO)
1522    if(VIDEO_OPENGL)
1523      set(SDL_VIDEO_OPENGL 1)
1524      set(SDL_VIDEO_OPENGL_WGL 1)
1525      set(SDL_VIDEO_RENDER_OGL 1)
1526      set(HAVE_VIDEO_OPENGL TRUE)
1527    endif()
1528
1529    if(VIDEO_OPENGLES)
1530      set(SDL_VIDEO_OPENGL_EGL 1)
1531      set(SDL_VIDEO_OPENGL_ES2 1)
1532      set(SDL_VIDEO_RENDER_OGL_ES2 1)
1533      set(HAVE_VIDEO_OPENGLES TRUE)
1534    endif()
1535  endif()
1536
1537  if(SDL_JOYSTICK)
1538    CheckHIDAPI()
1539    # TODO: Remove this hid.c block when SDL_hidapi.c is supported on Windows!
1540    if(HAVE_HIDAPI)
1541      set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/windows/hid.c)
1542    endif()
1543    file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
1544    set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1545    if(HAVE_DINPUT_H)
1546      set(SDL_JOYSTICK_DINPUT 1)
1547      list(APPEND EXTRA_LIBS dinput8)
1548    endif()
1549    if(HAVE_XINPUT_H)
1550      set(SDL_JOYSTICK_XINPUT 1)
1551    endif()
1552    if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
1553      set(SDL_JOYSTICK_WINMM 1)
1554    endif()
1555    set(HAVE_SDL_JOYSTICK TRUE)
1556
1557    if(SDL_HAPTIC)
1558      if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
1559        file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
1560        if(HAVE_DINPUT_H)
1561          set(SDL_HAPTIC_DINPUT 1)
1562        endif()
1563        if(HAVE_XINPUT_H)
1564          set(SDL_HAPTIC_XINPUT 1)
1565        endif()
1566      else()
1567        file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
1568        set(SDL_HAPTIC_DUMMY 1)
1569      endif()
1570      set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1571      set(HAVE_SDL_HAPTIC TRUE)
1572    endif()
1573  endif()
1574
1575  file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
1576  file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
1577  if(MINGW OR CYGWIN)
1578    list(APPEND EXTRA_LIBS mingw32)
1579    list(APPEND EXTRA_LDFLAGS "-mwindows")
1580    set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
1581    list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
1582  endif()
1583
1584elseif(APPLE)
1585  # TODO: rework this all for proper MacOS X, iOS and Darwin support
1586
1587  # We always need these libs on macOS at the moment.
1588  # !!! FIXME: we need Carbon for some very old API calls in
1589  # !!! FIXME:  src/video/cocoa/SDL_cocoakeyboard.c, but we should figure out
1590  # !!! FIXME:  how to dump those.
1591  if(DARWIN OR MACOSX)
1592    set(SDL_FRAMEWORK_COCOA 1)
1593    set(SDL_FRAMEWORK_CARBON 1)
1594  endif()
1595  set(SDL_FRAMEWORK_FOUNDATION 1)
1596
1597  # Requires the darwin file implementation
1598  if(SDL_FILE)
1599    file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
1600    set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
1601    # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
1602    set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
1603    set(HAVE_SDL_FILE TRUE)
1604    # !!! FIXME: why is COREVIDEO inside this if() block?
1605    set(SDL_FRAMEWORK_COREVIDEO 1)
1606  else()
1607    message_error("SDL_FILE must be enabled to build on MacOS X")
1608  endif()
1609
1610  if(SDL_AUDIO)
1611    set(SDL_AUDIO_DRIVER_COREAUDIO 1)
1612    file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
1613    # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
1614    set_source_files_properties(${AUDIO_SOURCES} PROPERTIES LANGUAGE C)
1615    set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
1616    set(HAVE_SDL_AUDIO TRUE)
1617    set(SDL_FRAMEWORK_COREAUDIO 1)
1618    set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
1619    set(SDL_FRAMEWORK_AVFOUNDATION 1)
1620  endif()
1621
1622  if(SDL_JOYSTICK)
1623    CheckHIDAPI()
1624    if(HAVE_HIDAPI)
1625      if(IOS OR TVOS)
1626        set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
1627        set(SDL_FRAMEWORK_COREBLUETOOTH 1)
1628      endif()
1629    endif()
1630    if(IOS OR TVOS)
1631      file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
1632      set(SDL_JOYSTICK_MFI 1)
1633      if(IOS)
1634        set(SDL_FRAMEWORK_COREMOTION 1)
1635      endif()
1636      set(SDL_FRAMEWORK_GAMECONTROLLER 1)
1637      set(HAVE_SDL_SENSORS 1)
1638    else()
1639      file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
1640      set(SDL_JOYSTICK_IOKIT 1)
1641      set(SDL_FRAMEWORK_IOKIT 1)
1642      set(SDL_FRAMEWORK_FF 1)
1643    endif()
1644    set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1645    set(HAVE_SDL_JOYSTICK TRUE)
1646  endif()
1647
1648  if(SDL_HAPTIC)
1649    if (IOS OR TVOS)
1650      file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
1651      set(SDL_HAPTIC_DUMMY 1)
1652    else()
1653      file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
1654      set(SDL_HAPTIC_IOKIT 1)
1655      set(SDL_FRAMEWORK_IOKIT 1)
1656      set(SDL_FRAMEWORK_FF 1)
1657    endif()
1658    set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1659    set(HAVE_SDL_HAPTIC TRUE)
1660    if(NOT SDL_JOYSTICK)
1661      message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
1662    endif()
1663  endif()
1664
1665  if(SDL_POWER)
1666    if (IOS OR TVOS)
1667      file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
1668      set(SDL_POWER_UIKIT 1)
1669    else()
1670      file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
1671      set(SDL_POWER_MACOSX 1)
1672      set(SDL_FRAMEWORK_IOKIT 1)
1673    endif()
1674    set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
1675    set(HAVE_SDL_POWER TRUE)
1676  endif()
1677
1678  if(SDL_LOCALE)
1679    file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/macosx/*.m)
1680    set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1681    set(HAVE_SDL_LOCALE TRUE)
1682  endif()
1683
1684  if(SDL_TIMERS)
1685    set(SDL_TIMER_UNIX 1)
1686    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1687    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1688    set(HAVE_SDL_TIMERS TRUE)
1689  endif(SDL_TIMERS)
1690
1691  if(SDL_FILESYSTEM)
1692    set(SDL_FILESYSTEM_COCOA 1)
1693    file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
1694    # !!! FIXME: modern CMake doesn't need "LANGUAGE C" for Objective-C.
1695    set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
1696    set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1697    set(HAVE_SDL_FILESYSTEM TRUE)
1698  endif()
1699
1700  if(SDL_SENSOR)
1701    if(IOS)
1702      set(SDL_SENSOR_COREMOTION 1)
1703      set(HAVE_SDL_SENSORS TRUE)
1704      file(GLOB SENSOR_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/coremotion/*.m)
1705      set(SOURCE_FILES ${SOURCE_FILES} ${SENSOR_SOURCES})
1706    endif()
1707  endif()
1708
1709  # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
1710  if(SDL_VIDEO)
1711    if (IOS OR TVOS)
1712      set(SDL_VIDEO_DRIVER_UIKIT 1)
1713      set(SDL_FRAMEWORK_COREGRAPHICS 1)
1714      set(SDL_FRAMEWORK_QUARTZCORE 1)
1715      set(SDL_FRAMEWORK_UIKIT 1)
1716      set(SDL_IPHONE_KEYBOARD 1)
1717      set(SDL_IPHONE_LAUNCHSCREEN 1)
1718      file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
1719      set(SOURCE_FILES ${SOURCE_FILES} ${UIKITVIDEO_SOURCES})
1720    else()
1721      CheckCOCOA()
1722      if(VIDEO_OPENGL)
1723        set(SDL_VIDEO_OPENGL 1)
1724        set(SDL_VIDEO_OPENGL_CGL 1)
1725        set(SDL_VIDEO_RENDER_OGL 1)
1726        set(HAVE_VIDEO_OPENGL TRUE)
1727      endif()
1728    endif()
1729
1730    if(VIDEO_OPENGLES)
1731      if(IOS OR TVOS)
1732        set(SDL_FRAMEWORK_OPENGLES 1)
1733        set(SDL_VIDEO_OPENGL_ES 1)
1734        set(SDL_VIDEO_RENDER_OGL_ES 1)
1735      else()
1736        set(SDL_VIDEO_OPENGL_EGL 1)
1737      endif()
1738      set(SDL_VIDEO_OPENGL_ES2 1)
1739      set(SDL_VIDEO_RENDER_OGL_ES2 1)
1740      set(HAVE_VIDEO_OPENGLES TRUE)
1741    endif()
1742
1743    if(VIDEO_VULKAN OR VIDEO_METAL OR RENDER_METAL)
1744      set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
1745      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -ObjC")
1746      check_c_source_compiles("
1747        #include <AvailabilityMacros.h>
1748        #import <Metal/Metal.h>
1749        #import <QuartzCore/CAMetalLayer.h>
1750
1751        #if TARGET_OS_SIMULATOR || (!TARGET_CPU_X86_64 && !TARGET_CPU_ARM64)
1752        #error Metal doesn't work on this configuration
1753        #endif
1754        int main()
1755        {
1756            return 0;
1757        }
1758        " HAVE_FRAMEWORK_METAL)
1759      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
1760      if(HAVE_FRAMEWORK_METAL)
1761        set(SDL_FRAMEWORK_METAL 1)
1762        set(SDL_FRAMEWORK_QUARTZCORE 1)
1763      else()
1764        set(VIDEO_VULKAN 0)
1765        set(VIDEO_METAL 0)
1766        set(RENDER_METAL 0)
1767      endif()
1768    endif()
1769
1770    if(VIDEO_METAL)
1771      set(SDL_VIDEO_METAL 1)
1772      set(HAVE_VIDEO_METAL TRUE)
1773    endif()
1774
1775    if(RENDER_METAL)
1776      file(GLOB RENDER_METAL_SOURCES ${SDL2_SOURCE_DIR}/src/render/metal/*.m)
1777      set(SOURCE_FILES ${SOURCE_FILES} ${RENDER_METAL_SOURCES})
1778      set(SDL_VIDEO_RENDER_METAL 1)
1779      set(HAVE_RENDER_METAL TRUE)
1780    endif()
1781  endif()
1782
1783  # Actually load the frameworks at the end so we don't duplicate include.
1784  if(SDL_FRAMEWORK_COREVIDEO)
1785    find_library(COREVIDEO CoreVideo)
1786    list(APPEND EXTRA_LIBS ${COREVIDEO})
1787  endif()
1788  if(SDL_FRAMEWORK_COCOA)
1789    find_library(COCOA_LIBRARY Cocoa)
1790    list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
1791  endif()
1792  if(SDL_FRAMEWORK_IOKIT)
1793    find_library(IOKIT IOKit)
1794    list(APPEND EXTRA_LIBS ${IOKIT})
1795  endif()
1796  if(SDL_FRAMEWORK_FF)
1797    find_library(FORCEFEEDBACK ForceFeedback)
1798    list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
1799  endif()
1800  if(SDL_FRAMEWORK_CARBON)
1801    find_library(CARBON_LIBRARY Carbon)
1802    list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
1803  endif()
1804  if(SDL_FRAMEWORK_COREAUDIO)
1805    find_library(COREAUDIO CoreAudio)
1806    list(APPEND EXTRA_LIBS ${COREAUDIO})
1807  endif()
1808  if(SDL_FRAMEWORK_AUDIOTOOLBOX)
1809    find_library(AUDIOTOOLBOX AudioToolbox)
1810    list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
1811  endif()
1812  if(SDL_FRAMEWORK_AVFOUNDATION)
1813    find_library(AVFOUNDATION AVFoundation)
1814    list(APPEND EXTRA_LIBS ${AVFOUNDATION})
1815  endif()
1816  if(SDL_FRAMEWORK_COREBLUETOOTH)
1817    find_library(COREBLUETOOTH CoreBluetooth)
1818    list(APPEND EXTRA_LIBS ${COREBLUETOOTH})
1819  endif()
1820  if(SDL_FRAMEWORK_COREGRAPHICS)
1821    find_library(COREGRAPHICS CoreGraphics)
1822    list(APPEND EXTRA_LIBS ${COREGRAPHICS})
1823  endif()
1824  if(SDL_FRAMEWORK_COREMOTION)
1825    find_library(COREMOTION CoreMotion)
1826    list(APPEND EXTRA_LIBS ${COREMOTION})
1827  endif()
1828  if(SDL_FRAMEWORK_FOUNDATION)
1829    find_library(FOUNDATION Foundation)
1830    list(APPEND EXTRA_LIBS ${FOUNDATION})
1831  endif()
1832  if(SDL_FRAMEWORK_GAMECONTROLLER)
1833    find_library(GAMECONTROLLER GameController)
1834    list(APPEND EXTRA_LIBS ${GAMECONTROLLER})
1835  endif()
1836  if(SDL_FRAMEWORK_METAL)
1837    if(IOS OR TVOS)
1838      find_library(METAL Metal)
1839      list(APPEND EXTRA_LIBS ${METAL})
1840    else()
1841      list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,Metal")
1842    endif()
1843  endif()
1844  if(SDL_FRAMEWORK_OPENGLES)
1845    find_library(OPENGLES OpenGLES)
1846    list(APPEND EXTRA_LIBS ${OPENGLES})
1847  endif()
1848  if(SDL_FRAMEWORK_QUARTZCORE)
1849    if(IOS OR TVOS)
1850      find_library(QUARTZCORE QuartzCore)
1851      list(APPEND EXTRA_LIBS ${QUARTZCORE})
1852    else()
1853      list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,QuartzCore")
1854    endif()
1855  endif()
1856  if(SDL_FRAMEWORK_UIKIT)
1857    find_library(UIKIT UIKit)
1858    list(APPEND EXTRA_LIBS ${UIKIT})
1859  endif()
1860
1861  CheckPTHREAD()
1862
1863elseif(HAIKU)
1864  if(SDL_VIDEO)
1865    set(SDL_VIDEO_DRIVER_HAIKU 1)
1866    file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
1867    set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
1868    set(HAVE_SDL_VIDEO TRUE)
1869
1870    if(VIDEO_OPENGL)
1871      # TODO: Use FIND_PACKAGE(OpenGL) instead
1872      set(SDL_VIDEO_OPENGL 1)
1873      set(SDL_VIDEO_OPENGL_BGL 1)
1874      set(SDL_VIDEO_RENDER_OGL 1)
1875      list(APPEND EXTRA_LIBS GL)
1876      set(HAVE_VIDEO_OPENGL TRUE)
1877    endif()
1878  endif()
1879
1880  set(SDL_FILESYSTEM_HAIKU 1)
1881  file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
1882  set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1883  set(HAVE_SDL_FILESYSTEM TRUE)
1884
1885  if(SDL_TIMERS)
1886    set(SDL_TIMER_HAIKU 1)
1887    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
1888    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1889    set(HAVE_SDL_TIMERS TRUE)
1890  endif()
1891
1892  if(SDL_LOCALE)
1893    file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/haiku/*.cc)
1894    set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1895    set(HAVE_SDL_LOCALE TRUE)
1896  endif()
1897
1898  CheckPTHREAD()
1899
1900elseif(RISCOS)
1901  if(SDL_TIMERS)
1902    set(SDL_TIMER_UNIX 1)
1903    file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
1904    set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1905    set(HAVE_SDL_TIMERS TRUE)
1906
1907    if(CLOCK_GETTIME)
1908      set(HAVE_CLOCK_GETTIME 1)
1909    endif()
1910  endif()
1911
1912  CheckPTHREAD()
1913
1914  if(SDL_AUDIO)
1915    CheckOSS()
1916  endif()
1917endif()
1918
1919if(VIDEO_VULKAN)
1920  set(SDL_VIDEO_VULKAN 1)
1921  set(HAVE_VIDEO_VULKAN TRUE)
1922endif()
1923
1924# Dummies
1925# configure.ac does it differently:
1926# if not have X
1927#   if enable_X {  SDL_X_DISABLED = 1 }
1928#   [add dummy sources]
1929# so it always adds a dummy, without checking, if it was actually requested.
1930# This leads to missing internal references on building, since the
1931# src/X/*.c does not get included.
1932if(NOT HAVE_SDL_JOYSTICK)
1933  set(SDL_JOYSTICK_DUMMY 1)
1934  if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
1935
1936    file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
1937    set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
1938  endif()
1939endif()
1940if(NOT HAVE_SDL_HAPTIC)
1941  set(SDL_HAPTIC_DUMMY 1)
1942  file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
1943  set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
1944endif()
1945if(NOT HAVE_SDL_SENSORS)
1946  set(SDL_SENSOR_DUMMY 1)
1947  file(GLOB SENSORS_SOURCES ${SDL2_SOURCE_DIR}/src/sensor/dummy/*.c)
1948  set(SOURCE_FILES ${SOURCE_FILES} ${SENSORS_SOURCES})
1949endif()
1950if(NOT HAVE_SDL_LOADSO)
1951  set(SDL_LOADSO_DISABLED 1)
1952  file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
1953  set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
1954endif()
1955if(NOT HAVE_SDL_FILESYSTEM)
1956  set(SDL_FILESYSTEM_DISABLED 1)
1957  file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
1958  set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
1959endif()
1960if(NOT HAVE_SDL_LOCALE)
1961  set(SDL_LOCALE_DISABLED 1)
1962  file(GLOB LOCALE_SOURCES ${SDL2_SOURCE_DIR}/src/locale/dummy/*.c)
1963  set(SOURCE_FILES ${SOURCE_FILES} ${LOCALE_SOURCES})
1964endif()
1965
1966# We always need to have threads and timers around
1967if(NOT HAVE_SDL_THREADS)
1968  set(SDL_THREADS_DISABLED 1)
1969  file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
1970  set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
1971endif()
1972if(NOT HAVE_SDL_TIMERS)
1973  set(SDL_TIMERS_DISABLED 1)
1974  file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
1975  set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
1976endif()
1977
1978if(NOT SDLMAIN_SOURCES)
1979  file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
1980endif()
1981
1982# Append the -MMD -MT flags
1983# if(DEPENDENCY_TRACKING)
1984#   if(COMPILER_IS_GNUCC)
1985#     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
1986#   endif()
1987# endif()
1988
1989configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
1990  "${SDL2_BINARY_DIR}/include/SDL_config.h")
1991
1992# Prepare the flags and remove duplicates
1993if(EXTRA_LDFLAGS)
1994  list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
1995endif()
1996if(EXTRA_LIBS)
1997  list(REMOVE_DUPLICATES EXTRA_LIBS)
1998endif()
1999if(EXTRA_CFLAGS)
2000  list(REMOVE_DUPLICATES EXTRA_CFLAGS)
2001endif()
2002listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
2003set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
2004
2005# Compat helpers for the configuration files
2006if(NOT WINDOWS OR CYGWIN)
2007  # TODO: we need a Windows script, too
2008  execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
2009
2010  set(prefix ${CMAKE_INSTALL_PREFIX})
2011  set(exec_prefix "\${prefix}")
2012  set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
2013  set(bindir "\${exec_prefix}/bin")
2014  set(includedir "\${prefix}/include")
2015  if(SDL_STATIC)
2016    set(ENABLE_STATIC_TRUE "")
2017    set(ENABLE_STATIC_FALSE "#")
2018  else()
2019    set(ENABLE_STATIC_TRUE "#")
2020    set(ENABLE_STATIC_FALSE "")
2021  endif()
2022  if(SDL_SHARED)
2023    set(PKG_CONFIG_LIBS_PRIV "
2024Libs.private:")
2025    set(ENABLE_SHARED_TRUE "")
2026    set(ENABLE_SHARED_FALSE "#")
2027  else()
2028    set(PKG_CONFIG_LIBS_PRIV "")
2029    set(ENABLE_SHARED_TRUE "#")
2030    set(ENABLE_SHARED_FALSE "")
2031  endif()
2032
2033  # Clean up the different lists
2034  listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
2035  set(SDL_STATIC_LIBS ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
2036  list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
2037  listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
2038  set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
2039  listtostr(SDL_LIBS _SDL_LIBS)
2040  set(SDL_LIBS ${_SDL_LIBS})
2041
2042  # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
2043  # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
2044
2045  configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
2046    "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
2047  configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
2048    "${SDL2_BINARY_DIR}/sdl2-config")
2049  configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
2050    "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
2051  configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
2052    "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
2053endif()
2054
2055##### Info output #####
2056message(STATUS "")
2057message(STATUS "SDL2 was configured with the following options:")
2058message(STATUS "")
2059message(STATUS "Platform: ${CMAKE_SYSTEM}")
2060message(STATUS "64-bit:   ${ARCH_64}")
2061message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
2062message(STATUS "")
2063message(STATUS "Subsystems:")
2064foreach(_SUB ${SDL_SUBSYSTEMS})
2065  string(TOUPPER ${_SUB} _OPT)
2066  message_bool_option(${_SUB} SDL_${_OPT})
2067endforeach()
2068message(STATUS "")
2069message(STATUS "Options:")
2070list(SORT ALLOPTIONS)
2071foreach(_OPT ${ALLOPTIONS})
2072  # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
2073  # Get the padding
2074  string(LENGTH ${_OPT} _OPTLEN)
2075  math(EXPR _PADLEN "23 - ${_OPTLEN}")
2076  string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
2077  message_tested_option(${_OPT} ${_PADDING})
2078endforeach()
2079message(STATUS "")
2080message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
2081message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
2082message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
2083message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
2084message(STATUS "")
2085message(STATUS " Build Shared Library: ${SDL_SHARED}")
2086message(STATUS " Build Static Library: ${SDL_STATIC}")
2087if(SDL_STATIC)
2088    message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
2089endif()
2090message(STATUS "")
2091if(UNIX)
2092  message(STATUS "If something was not detected, although the libraries")
2093  message(STATUS "were installed, then make sure you have set the")
2094  message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
2095  message(STATUS "")
2096endif()
2097
2098if(WARN_ABOUT_ARM_SIMD_ASM_MIT)
2099  message(STATUS "")
2100  message(STATUS "SDL is being built with ARM SIMD optimizations, which")
2101  message(STATUS "uses code licensed under the MIT license. If this is a")
2102  message(STATUS "problem, please disable that code by rerunning CMake with:")
2103  message(STATUS "")
2104  message(STATUS "    -DARMSIMD=OFF")
2105endif()
2106
2107if(WARN_ABOUT_ARM_NEON_ASM_MIT)
2108  message(STATUS "")
2109  message(STATUS "SDL is being built with ARM NEON optimizations, which")
2110  message(STATUS "uses code licensed under the MIT license. If this is a")
2111  message(STATUS "problem, please disable that code by rerunning CMake with:")
2112  message(STATUS "")
2113  message(STATUS "    -DARMNEON=OFF")
2114endif()
2115
2116# Ensure that the extra cflags are used at compile time
2117set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
2118
2119# Always build SDLmain
2120add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
2121target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/SDL2>)
2122set(_INSTALL_LIBS "SDL2main")
2123if (NOT ANDROID)
2124  set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
2125endif()
2126
2127if (ANDROID AND HAVE_HIDAPI)
2128  set(_INSTALL_LIBS ${_INSTALL_LIBS} "hidapi")
2129endif()
2130
2131if(SDL_SHARED)
2132  add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
2133  if(APPLE)
2134    set_target_properties(SDL2 PROPERTIES
2135      MACOSX_RPATH 1
2136      OUTPUT_NAME "SDL2-${LT_RELEASE}")
2137  elseif(UNIX AND NOT ANDROID)
2138    set_target_properties(SDL2 PROPERTIES
2139      VERSION ${LT_VERSION}
2140      SOVERSION ${LT_REVISION}
2141      OUTPUT_NAME "SDL2-${LT_RELEASE}")
2142  else()
2143    set_target_properties(SDL2 PROPERTIES
2144      VERSION ${SDL_VERSION}
2145      SOVERSION ${LT_REVISION}
2146      OUTPUT_NAME "SDL2")
2147  endif()
2148  if(MSVC AND NOT LIBC)
2149    # Don't try to link with the default set of libraries.
2150    set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
2151    set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
2152    set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
2153  endif()
2154  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
2155  target_link_libraries(SDL2 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
2156  target_include_directories(SDL2 PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/SDL2>)
2157  if(ANDROID)
2158    target_include_directories(SDL2 PRIVATE ${ANDROID_NDK}/sources/android/cpufeatures)
2159  else()
2160    set_target_properties(SDL2 PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
2161  endif()
2162  if(IOS OR TVOS)
2163    set_property(TARGET SDL2 APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc")
2164    target_compile_definitions(SDL2 PRIVATE IOS_DYLIB=1)
2165  endif()
2166endif()
2167
2168if(ANDROID)
2169  if(HAVE_HIDAPI)
2170    add_library(hidapi SHARED ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
2171  endif()
2172
2173  if(MSVC AND NOT LIBC)
2174    # Don't try to link with the default set of libraries.
2175    set_target_properties(hidapi PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
2176    set_target_properties(hidapi PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
2177    set_target_properties(hidapi PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
2178  endif()
2179  if(HAVE_HIDAPI)
2180    target_link_libraries(hidapi log)
2181  endif()
2182endif()
2183
2184if(SDL_STATIC)
2185  set (BUILD_SHARED_LIBS FALSE)
2186  add_library(SDL2-static STATIC ${SOURCE_FILES})
2187  if (NOT SDL_SHARED OR NOT WIN32)
2188    set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
2189    # Note: Apparently, OUTPUT_NAME must really be unique; even when
2190    # CMAKE_IMPORT_LIBRARY_SUFFIX or the like are given. Otherwise
2191    # the static build may race with the import lib and one will get
2192    # clobbered, when the suffix is realized via subsequent rename.
2193  endif()
2194  set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC})
2195  if(MSVC AND NOT LIBC)
2196    set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
2197    set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
2198    set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
2199  endif()
2200  # TODO: Win32 platforms keep the same suffix .lib for import and static
2201  # libraries - do we need to consider this?
2202  set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
2203  target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
2204  target_include_directories(SDL2-static PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/SDL2>)
2205  if(ANDROID)
2206    target_include_directories(SDL2-static PRIVATE ${ANDROID_NDK}/sources/android/cpufeatures)
2207  else()
2208    set_target_properties(SDL2-static PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
2209  endif()
2210  if(IOS OR TVOS)
2211    set_property(TARGET SDL2-static APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc")
2212  endif()
2213endif()
2214
2215##### Tests #####
2216
2217if(SDL_TEST)
2218  file(GLOB TEST_SOURCES ${SDL2_SOURCE_DIR}/src/test/*.c)
2219  add_library(SDL2_test STATIC ${TEST_SOURCES})
2220
2221  add_subdirectory(test)
2222endif()
2223
2224##### Installation targets #####
2225install(TARGETS ${_INSTALL_LIBS} EXPORT SDL2Targets
2226  LIBRARY DESTINATION "lib${LIB_SUFFIX}"
2227  ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
2228  RUNTIME DESTINATION bin)
2229
2230##### Export files #####
2231if (WINDOWS)
2232  set(PKG_PREFIX "cmake")
2233else ()
2234  set(PKG_PREFIX "lib${LIB_SUFFIX}/cmake/SDL2")
2235endif ()
2236
2237include(CMakePackageConfigHelpers)
2238write_basic_package_version_file("${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake"
2239  VERSION ${SDL_VERSION}
2240  COMPATIBILITY AnyNewerVersion
2241)
2242
2243install(EXPORT SDL2Targets
2244  FILE SDL2Targets.cmake
2245  NAMESPACE SDL2::
2246  DESTINATION ${PKG_PREFIX}
2247)
2248install(
2249  FILES
2250    ${CMAKE_CURRENT_SOURCE_DIR}/SDL2Config.cmake
2251    ${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake
2252  DESTINATION ${PKG_PREFIX}
2253  COMPONENT Devel
2254)
2255
2256file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
2257file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
2258foreach(_FNAME ${BIN_INCLUDE_FILES})
2259  get_filename_component(_INCNAME ${_FNAME} NAME)
2260  list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
2261endforeach()
2262list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
2263install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
2264
2265string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
2266if (UPPER_BUILD_TYPE MATCHES DEBUG)
2267  set(SOPOSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
2268else()
2269  set(SOPOSTFIX "")
2270endif()
2271
2272if(NOT (WINDOWS OR CYGWIN))
2273  if(SDL_SHARED)
2274    set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
2275    get_target_property(SONAME SDL2 OUTPUT_NAME)
2276    if(NOT ANDROID)
2277        install(CODE "
2278          execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
2279            \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\"
2280            WORKING_DIRECTORY \"${SDL2_BINARY_DIR}\")")
2281        install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "lib${LIB_SUFFIX}")
2282    endif()
2283  endif()
2284  if(FREEBSD)
2285    # FreeBSD uses ${PREFIX}/libdata/pkgconfig
2286    install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
2287  else()
2288    install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
2289      DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
2290  endif()
2291  install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
2292  # TODO: what about the .spec file? Is it only needed for RPM creation?
2293  install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/aclocal")
2294endif()
2295
2296##### Uninstall target #####
2297
2298if(NOT TARGET uninstall)
2299  configure_file(
2300      "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
2301      "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
2302      IMMEDIATE @ONLY)
2303
2304  add_custom_target(uninstall
2305      COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
2306endif()
2307