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