CMakeLists.txt
author Sam Lantinga <slouken@libsdl.org>
Fri, 29 May 2020 21:26:32 -0700
changeset 13884 ba1ed72249c0
parent 13882 3fee2d328a71
permissions -rw-r--r--
Fixed bug 5113 - SDL_UpdateWindowSurfaceRects BitBlt the entire surface on Win32

Ryan C. Gordon

As discussed here:
https://discourse.libsdl.org/t/question-about-implementation-of-sdl-updatewindowsurfacerects/27561

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