CMakeLists.txt
author David Ludwig
Mon, 23 Sep 2019 18:24:03 -0400
changeset 13086 144fc4e62b72
parent 13084 c3880ebab198
child 13089 9692ad570003
permissions -rw-r--r--
CMake: bug-fix for tvOS support

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