CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Mon, 23 Jan 2017 01:05:44 -0500
changeset 10835 0e9e7a128391
parent 10777 2883d23b5a28
child 10848 7764aba2f211
permissions -rw-r--r--
audio: Wired up new SSE code to build system.
     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.5)
     6 project(SDL2 C)
     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(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 5)
    45 set(SDL_INTERFACE_AGE 1)
    46 set(SDL_BINARY_AGE 5)
    47 set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
    48 
    49 # Calculate a libtool-like version number
    50 math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
    51 math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
    52 math(EXPR LT_MAJOR "${LT_CURRENT}- ${LT_AGE}")
    53 set(LT_REVISION "${SDL_INTERFACE_AGE}")
    54 set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
    55 set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
    56 
    57 message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
    58 
    59 # General settings & flags
    60 set(LIBRARY_OUTPUT_DIRECTORY "build")
    61 # Check for 64 or 32 bit
    62 set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
    63 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    64   set(ARCH_64 TRUE)
    65   set(PROCESSOR_ARCH "x64")
    66 else()
    67   set(ARCH_64 FALSE)
    68   set(PROCESSOR_ARCH "x86")
    69 endif()
    70 set(LIBNAME SDL2)
    71 if(NOT LIBTYPE)
    72   set(LIBTYPE SHARED)
    73 endif()
    74 
    75 # Get the platform
    76 if(WIN32)
    77   if(NOT WINDOWS)
    78     set(WINDOWS TRUE)
    79   endif()
    80 elseif(UNIX AND NOT APPLE)
    81   if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
    82     set(LINUX TRUE)
    83   elseif(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
    84     set(FREEBSD TRUE)
    85   elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
    86     set(NETBSD TRUE)
    87   elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
    88     set(OPENBSD TRUE)
    89   elseif(CMAKE_SYSTEM_NAME MATCHES ".*GNU.*")
    90     set(GNU TRUE)
    91   elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
    92     set(BSDI TRUE)
    93   elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
    94     set(FREEBSD TRUE)
    95   elseif(CMAKE_SYSTEM_NAME MATCHES "SYSV5.*")
    96     set(SYSV5 TRUE)
    97   elseif(CMAKE_SYSTEM_NAME MATCHES "Solaris.*")
    98     set(SOLARIS TRUE)
    99   elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX.*")
   100     set(HPUX TRUE)
   101   elseif(CMAKE_SYSTEM_NAME MATCHES "AIX.*")
   102     set(AIX TRUE)
   103   elseif(CMAKE_SYSTEM_NAME MATCHES "Minix.*")
   104     set(MINIX TRUE)
   105   endif()
   106 elseif(APPLE)
   107   if(CMAKE_SYSTEM_NAME MATCHES ".*Darwin.*")
   108     set(DARWIN TRUE)
   109   elseif(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
   110     set(MACOSX TRUE)
   111   endif()
   112   # TODO: iOS?
   113 elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*")
   114   message_error("BeOS support has been removed as of SDL 2.0.2.")
   115 elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*")
   116   set(HAIKU TRUE)
   117 endif()
   118 
   119 # Don't mistake osx for unix
   120 if(UNIX AND NOT APPLE)
   121   set(UNIX_SYS ON)
   122 else()
   123   set(UNIX_SYS OFF)
   124 endif()
   125 
   126 if(UNIX OR APPLE)
   127   set(UNIX_OR_MAC_SYS ON)
   128 else()
   129   set(UNIX_OR_MAC_SYS OFF)
   130 endif()
   131 
   132 if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
   133   set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
   134 else()
   135   set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
   136 endif()
   137 
   138 # Default option knobs
   139 if(APPLE OR ARCH_64)
   140   set(OPT_DEF_SSEMATH ON)
   141 endif()
   142 if(UNIX OR MINGW OR MSYS)
   143   set(OPT_DEF_LIBC ON)
   144 endif()
   145 
   146 # Compiler info
   147 if(CMAKE_COMPILER_IS_GNUCC)
   148   set(USE_GCC TRUE)
   149   set(OPT_DEF_ASM TRUE)
   150 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
   151   set(USE_CLANG TRUE)
   152   set(OPT_DEF_ASM TRUE)
   153 elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+
   154   set(OPT_DEF_ASM TRUE)
   155   #set(CMAKE_C_FLAGS "/ZI /WX- /
   156 else()
   157   set(OPT_DEF_ASM FALSE)
   158 endif()
   159 
   160 # Default flags, if not set otherwise
   161 if("$ENV{CFLAGS}" STREQUAL "")
   162   if(CMAKE_BUILD_TYPE STREQUAL "")
   163     if(USE_GCC OR USE_CLANG)
   164       set(CMAKE_C_FLAGS "-g -O3")
   165     endif()
   166   endif()
   167 else()
   168   set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
   169   list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
   170 endif()
   171 if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
   172   list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
   173 endif()
   174 
   175 if(MSVC)
   176   option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
   177   if(FORCE_STATIC_VCRT)
   178     foreach(flag_var
   179         CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
   180         CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
   181       if(${flag_var} MATCHES "/MD")
   182         string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
   183       endif()
   184     endforeach()
   185   endif()
   186 
   187   # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
   188   foreach(flag_var
   189       CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
   190       CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
   191     string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
   192   endforeach(flag_var)
   193 endif()
   194 
   195 # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
   196 # etc. are created correctly.
   197 set(SDL_LIBS "-lSDL2")
   198 set(SDL_CFLAGS "")
   199 
   200 # Emscripten toolchain has a nonempty default value for this, and the checks 
   201 # in this file need to change that, so remember the original value, and 
   202 # restore back to that afterwards. For check_function_exists() to work in
   203 # Emscripten, this value must be at its default value.
   204 set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
   205 
   206 if(CYGWIN)
   207   # We build SDL on cygwin without the UNIX emulation layer
   208   include_directories("-I/usr/include/mingw")
   209   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
   210   check_c_source_compiles("int main(int argc, char **argv) {}"
   211     HAVE_GCC_NO_CYGWIN)
   212   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   213   if(HAVE_GCC_NO_CYGWIN)
   214     list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
   215     list(APPEND SDL_LIBS "-mno-cygwin")
   216   endif()
   217   set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
   218 endif()
   219 
   220 add_definitions(-DUSING_GENERATED_CONFIG_H)
   221 # General includes
   222 include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
   223 
   224 # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
   225 #  you only need to have a platform override them if they are disabling.
   226 set(OPT_DEF_ASM TRUE)
   227 if(EMSCRIPTEN)
   228   # Set up default values for the currently supported set of subsystems:
   229   # Emscripten/Javascript does not have assembly support, a dynamic library 
   230   # loading architecture, low-level CPU inspection or multithreading.
   231   set(OPT_DEF_ASM FALSE)
   232   set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
   233   set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
   234   set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
   235   set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
   236   set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
   237   set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
   238 endif()
   239 
   240 if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
   241     set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
   242 endif()
   243 
   244 set(SDL_SUBSYSTEMS
   245     Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
   246     File Loadso CPUinfo Filesystem Dlopen)
   247 foreach(_SUB ${SDL_SUBSYSTEMS})
   248   string(TOUPPER ${_SUB} _OPT)
   249   if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
   250     set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
   251   endif()
   252   option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
   253 endforeach()
   254 
   255 option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
   256 #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
   257 set_option(LIBC                "Use the system C library" ${OPT_DEF_LIBC})
   258 set_option(GCC_ATOMICS         "Use gcc builtin atomics" ${USE_GCC})
   259 set_option(ASSEMBLY            "Enable assembly routines" ${OPT_DEF_ASM})
   260 set_option(SSEMATH             "Allow GCC to use SSE floating point math" ${OPT_DEF_SSEMATH})
   261 set_option(MMX                 "Use MMX assembly routines" ${OPT_DEF_ASM})
   262 set_option(3DNOW               "Use 3Dnow! MMX assembly routines" ${OPT_DEF_ASM})
   263 set_option(SSE                 "Use SSE assembly routines" ${OPT_DEF_ASM})
   264 set_option(SSE2                "Use SSE2 assembly routines" ${OPT_DEF_SSEMATH})
   265 set_option(SSE3                "Use SSE3 assembly routines" ${OPT_DEF_SSEMATH})
   266 set_option(ALTIVEC             "Use Altivec assembly routines" ${OPT_DEF_ASM})
   267 set_option(DISKAUDIO           "Support the disk writer audio driver" ON)
   268 set_option(DUMMYAUDIO          "Support the dummy audio driver" ON)
   269 set_option(VIDEO_DIRECTFB      "Use DirectFB video driver" OFF)
   270 dep_option(DIRECTFB_SHARED     "Dynamically load directfb support" ON "VIDEO_DIRECTFB" OFF)
   271 set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
   272 set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
   273 set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
   274 set_option(PTHREADS            "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT})
   275 dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
   276 set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ${SDL_DLOPEN_ENABLED_BY_DEFAULT})
   277 set_option(OSS                 "Support the OSS audio API" ${UNIX_SYS})
   278 set_option(ALSA                "Support the ALSA audio API" ${UNIX_SYS})
   279 dep_option(ALSA_SHARED         "Dynamically load ALSA audio support" ON "ALSA" OFF)
   280 set_option(ESD                 "Support the Enlightened Sound Daemon" ${UNIX_SYS})
   281 dep_option(ESD_SHARED          "Dynamically load ESD audio support" ON "ESD" OFF)
   282 set_option(PULSEAUDIO          "Use PulseAudio" ${UNIX_SYS})
   283 dep_option(PULSEAUDIO_SHARED   "Dynamically load PulseAudio support" ON "PULSEAUDIO" OFF)
   284 set_option(ARTS                "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
   285 dep_option(ARTS_SHARED         "Dynamically load aRts audio support" ON "ARTS" OFF)
   286 set_option(NAS                 "Support the NAS audio API" ${UNIX_SYS})
   287 set_option(NAS_SHARED          "Dynamically load NAS audio API" ${UNIX_SYS})
   288 set_option(SNDIO               "Support the sndio audio API" ${UNIX_SYS})
   289 set_option(FUSIONSOUND         "Use FusionSound audio driver" OFF)
   290 dep_option(FUSIONSOUND_SHARED  "Dynamically load fusionsound audio support" ON "FUSIONSOUND" OFF)
   291 set_option(LIBSAMPLERATE       "Use libsamplerate for audio rate conversion" ${UNIX_SYS})
   292 dep_option(LIBSAMPLERATE_SHARED "Dynamically load libsamplerate" ON "LIBSAMPLERATE" OFF)
   293 set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
   294 set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
   295 set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
   296 set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
   297 set_option(VIDEO_WAYLAND       "Use Wayland video driver" ${UNIX_SYS})
   298 dep_option(WAYLAND_SHARED      "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
   299 dep_option(VIDEO_WAYLAND_QT_TOUCH  "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
   300 set_option(VIDEO_MIR           "Use Mir video driver" ${UNIX_SYS})
   301 dep_option(MIR_SHARED          "Dynamically load Mir support" ON "VIDEO_MIR" OFF)
   302 set_option(VIDEO_RPI           "Use Raspberry Pi video driver" ${UNIX_SYS})
   303 dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
   304 set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
   305 foreach(_SUB ${SDL_X11_OPTIONS})
   306   string(TOUPPER "VIDEO_X11_${_SUB}" _OPT)
   307   dep_option(${_OPT}           "Enable ${_SUB} support" ON "VIDEO_X11" OFF)
   308 endforeach()
   309 set_option(VIDEO_COCOA         "Use Cocoa video driver" ${APPLE})
   310 set_option(DIRECTX             "Use DirectX for Windows audio/video" ${WINDOWS})
   311 set_option(RENDER_D3D          "Enable the Direct3D render driver" ${WINDOWS})
   312 set_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ${UNIX_SYS})
   313 
   314 # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
   315 # The options below are for compatibility to configure's default behaviour.
   316 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
   317 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
   318 
   319 dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
   320 
   321 # General source files
   322 file(GLOB SOURCE_FILES
   323   ${SDL2_SOURCE_DIR}/src/*.c
   324   ${SDL2_SOURCE_DIR}/src/atomic/*.c
   325   ${SDL2_SOURCE_DIR}/src/audio/*.c
   326   ${SDL2_SOURCE_DIR}/src/cpuinfo/*.c
   327   ${SDL2_SOURCE_DIR}/src/dynapi/*.c
   328   ${SDL2_SOURCE_DIR}/src/events/*.c
   329   ${SDL2_SOURCE_DIR}/src/file/*.c
   330   ${SDL2_SOURCE_DIR}/src/libm/*.c
   331   ${SDL2_SOURCE_DIR}/src/render/*.c
   332   ${SDL2_SOURCE_DIR}/src/render/*/*.c
   333   ${SDL2_SOURCE_DIR}/src/stdlib/*.c
   334   ${SDL2_SOURCE_DIR}/src/thread/*.c
   335   ${SDL2_SOURCE_DIR}/src/timer/*.c
   336   ${SDL2_SOURCE_DIR}/src/video/*.c)
   337 
   338 
   339 if(ASSERTIONS STREQUAL "auto")
   340   # Do nada - use optimization settings to determine the assertion level
   341 elseif(ASSERTIONS STREQUAL "disabled")
   342   set(SDL_DEFAULT_ASSERT_LEVEL 0)
   343 elseif(ASSERTIONS STREQUAL "release")
   344   set(SDL_DEFAULT_ASSERT_LEVEL 1)
   345 elseif(ASSERTIONS STREQUAL "enabled")
   346   set(SDL_DEFAULT_ASSERT_LEVEL 2)
   347 elseif(ASSERTIONS STREQUAL "paranoid")
   348   set(SDL_DEFAULT_ASSERT_LEVEL 3)
   349 else()
   350   message_error("unknown assertion level")
   351 endif()
   352 set(HAVE_ASSERTIONS ${ASSERTIONS})
   353 
   354 # Compiler option evaluation
   355 if(USE_GCC OR USE_CLANG)
   356   # Check for -Wall first, so later things can override pieces of it.
   357   check_c_compiler_flag(-Wall HAVE_GCC_WALL)
   358   if(HAVE_GCC_WALL)
   359     list(APPEND EXTRA_CFLAGS "-Wall")
   360     if(HAIKU)
   361       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
   362     endif()
   363   endif()
   364 
   365   check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
   366   if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
   367     check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
   368     if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
   369       list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
   370     endif()
   371     list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
   372   endif()
   373 
   374   if(DEPENDENCY_TRACKING)
   375     check_c_source_compiles("
   376         #if !defined(__GNUC__) || __GNUC__ < 3
   377         #error Dependency tracking requires GCC 3.0 or newer
   378         #endif
   379         int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
   380   endif()
   381 
   382   if(GCC_ATOMICS)
   383     check_c_source_compiles("int main(int argc, char **argv) {
   384         int a;
   385         void *x, *y, *z;
   386         __sync_lock_test_and_set(&a, 4);
   387         __sync_lock_test_and_set(&x, y);
   388         __sync_fetch_and_add(&a, 1);
   389         __sync_bool_compare_and_swap(&a, 5, 10);
   390         __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
   391     if(NOT HAVE_GCC_ATOMICS)
   392       check_c_source_compiles("int main(int argc, char **argv) {
   393           int a;
   394           __sync_lock_test_and_set(&a, 1);
   395           __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
   396     endif()
   397   endif()
   398 
   399   set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
   400   check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
   401     HAVE_GCC_PREFERRED_STACK_BOUNDARY)
   402   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   403 
   404   set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
   405   check_c_source_compiles("
   406       #if !defined(__GNUC__) || __GNUC__ < 4
   407       #error SDL only uses visibility attributes in GCC 4 or newer
   408       #endif
   409       int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
   410   if(HAVE_GCC_FVISIBILITY)
   411     list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
   412   endif()
   413   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   414 
   415   check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
   416   if(HAVE_GCC_WSHADOW)
   417     list(APPEND EXTRA_CFLAGS "-Wshadow")
   418   endif()
   419 
   420   set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
   421   check_c_compiler_flag("" HAVE_NO_UNDEFINED)
   422   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   423   if(HAVE_NO_UNDEFINED)
   424     list(APPEND EXTRA_LDFLAGS "-Wl,--no-undefined")
   425   endif()
   426 endif()
   427 
   428 if(ASSEMBLY)
   429   if(USE_GCC OR USE_CLANG)
   430     set(SDL_ASSEMBLY_ROUTINES 1)
   431     # TODO: Those all seem to be quite GCC specific - needs to be
   432     # reworked for better compiler support
   433     set(HAVE_ASSEMBLY TRUE)
   434     if(MMX)
   435       set(CMAKE_REQUIRED_FLAGS "-mmmx")
   436       check_c_source_compiles("
   437           #ifdef __MINGW32__
   438           #include <_mingw.h>
   439           #ifdef __MINGW64_VERSION_MAJOR
   440           #include <intrin.h>
   441           #else
   442           #include <mmintrin.h>
   443           #endif
   444           #else
   445           #include <mmintrin.h>
   446           #endif
   447           #ifndef __MMX__
   448           #error Assembler CPP flag not enabled
   449           #endif
   450           int main(int argc, char **argv) { }" HAVE_MMX)
   451       if(HAVE_MMX)
   452         list(APPEND EXTRA_CFLAGS "-mmmx")
   453       endif()
   454       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   455     endif()
   456 
   457     if(3DNOW)
   458       set(CMAKE_REQUIRED_FLAGS "-m3dnow")
   459       check_c_source_compiles("
   460           #include <mm3dnow.h>
   461           #ifndef __3dNOW__
   462           #error Assembler CPP flag not enabled
   463           #endif
   464           int main(int argc, char **argv) {
   465             void *p = 0;
   466             _m_prefetch(p);
   467           }" HAVE_3DNOW)
   468       if(HAVE_3DNOW)
   469         list(APPEND EXTRA_CFLAGS "-m3dnow")
   470       endif()
   471       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   472     endif()
   473 
   474     if(SSE)
   475       set(CMAKE_REQUIRED_FLAGS "-msse")
   476       check_c_source_compiles("
   477           #ifdef __MINGW32__
   478           #include <_mingw.h>
   479           #ifdef __MINGW64_VERSION_MAJOR
   480           #include <intrin.h>
   481           #else
   482           #include <xmmintrin.h>
   483           #endif
   484           #else
   485           #include <xmmintrin.h>
   486           #endif
   487           #ifndef __SSE__
   488           #error Assembler CPP flag not enabled
   489           #endif
   490           int main(int argc, char **argv) { }" HAVE_SSE)
   491       if(HAVE_SSE)
   492         list(APPEND EXTRA_CFLAGS "-msse")
   493       endif()
   494       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   495     endif()
   496 
   497     if(SSE2)
   498       set(CMAKE_REQUIRED_FLAGS "-msse2")
   499       check_c_source_compiles("
   500           #ifdef __MINGW32__
   501           #include <_mingw.h>
   502           #ifdef __MINGW64_VERSION_MAJOR
   503           #include <intrin.h>
   504           #else
   505           #include <emmintrin.h>
   506           #endif
   507           #else
   508           #include <emmintrin.h>
   509           #endif
   510           #ifndef __SSE2__
   511           #error Assembler CPP flag not enabled
   512           #endif
   513           int main(int argc, char **argv) { }" HAVE_SSE2)
   514       if(HAVE_SSE2)
   515         list(APPEND EXTRA_CFLAGS "-msse2")
   516       endif()
   517       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   518     endif()
   519 
   520     if(SSE3)
   521       set(CMAKE_REQUIRED_FLAGS "-msse3")
   522       check_c_source_compiles("
   523           #ifdef __MINGW32__
   524           #include <_mingw.h>
   525           #ifdef __MINGW64_VERSION_MAJOR
   526           #include <intrin.h>
   527           #else
   528           #include <pmmintrin.h>
   529           #endif
   530           #else
   531           #include <pmmintrin.h>
   532           #endif
   533           #ifndef __SSE3__
   534           #error Assembler CPP flag not enabled
   535           #endif
   536           int main(int argc, char **argv) { }" HAVE_SSE3)
   537       if(HAVE_SSE3)
   538         list(APPEND EXTRA_CFLAGS "-msse3")
   539       endif()
   540       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   541     endif()
   542 
   543     if(SSEMATH)
   544       if(SSE OR SSE2 OR SSE3)
   545         if(USE_GCC)
   546           list(APPEND EXTRA_CFLAGS "-mfpmath=387")
   547         endif()
   548         set(HAVE_SSEMATH TRUE)
   549       endif()
   550     endif()
   551 
   552     if(ALTIVEC)
   553       set(CMAKE_REQUIRED_FLAGS "-maltivec")
   554       check_c_source_compiles("
   555           #include <altivec.h>
   556           vector unsigned int vzero() {
   557               return vec_splat_u32(0);
   558           }
   559           int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
   560       check_c_source_compiles("
   561           vector unsigned int vzero() {
   562               return vec_splat_u32(0);
   563           }
   564           int main(int argc, char **argv) { }" HAVE_ALTIVEC)
   565       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   566       if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
   567         set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
   568         list(APPEND EXTRA_CFLAGS "-maltivec")
   569         set(SDL_ALTIVEC_BLITTERS 1)
   570         if(HAVE_ALTIVEC_H_HDR)
   571           set(HAVE_ALTIVEC_H 1)
   572         endif()
   573       endif()
   574     endif()
   575   elseif(MSVC_VERSION GREATER 1500)
   576     # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
   577     # for MSVC - right now it is always activated
   578     if(NOT ARCH_64)
   579       set(HAVE_MMX TRUE)
   580       set(HAVE_3DNOW TRUE)
   581     endif()
   582     set(HAVE_SSE TRUE)
   583     set(HAVE_SSE2 TRUE)
   584     set(HAVE_SSE3 TRUE)
   585     set(SDL_ASSEMBLY_ROUTINES 1)
   586   endif()
   587 # TODO:
   588 #else()
   589 #  if(USE_GCC OR USE_CLANG)
   590 #    list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-sse3" "-mno-mmx")
   591 #  endif()
   592 endif()
   593 
   594 # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
   595 # anything.
   596 if(LIBC)
   597   if(WINDOWS AND NOT MINGW)
   598     set(HAVE_LIBC TRUE)
   599     foreach(_HEADER stdio.h string.h ctype.h math.h)
   600       string(TOUPPER "HAVE_${_HEADER}" _UPPER)
   601       string(REPLACE "." "_" _HAVE_H ${_UPPER})
   602       set(${_HAVE_H} 1)
   603     endforeach()
   604     set(HAVE_SIGNAL_H 1)
   605     foreach(_FN
   606             malloc calloc realloc free qsort abs memset memcpy memmove memcmp
   607             strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
   608             _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
   609             _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
   610             cosf fabs floor log pow scalbn sin sinf sqrt sqrtf tan tanf)
   611       string(TOUPPER ${_FN} _UPPER)
   612       set(HAVE_${_UPPER} 1)
   613     endforeach()
   614     if(NOT CYGWIN AND NOT MINGW)
   615       set(HAVE_ALLOCA 1)
   616     endif()
   617     set(HAVE_M_PI 1)
   618     add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
   619     set(STDC_HEADERS 1)
   620   else()
   621     set(HAVE_LIBC TRUE)
   622     check_include_file(sys/types.h HAVE_SYS_TYPES_H)
   623     foreach(_HEADER
   624             stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h
   625             strings.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h)
   626       string(TOUPPER "HAVE_${_HEADER}" _UPPER)
   627       string(REPLACE "." "_" _HAVE_H ${_UPPER})
   628       check_include_file("${_HEADER}" ${_HAVE_H})
   629     endforeach()
   630 
   631     check_include_files("dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" STDC_HEADERS)
   632     check_type_size("size_t" SIZEOF_SIZE_T)
   633     check_symbol_exists(M_PI math.h HAVE_M_PI)
   634     # TODO: refine the mprotect check
   635     check_c_source_compiles("#include <sys/types.h>
   636                              #include <sys/mman.h>
   637                              int main() { }" HAVE_MPROTECT)
   638     foreach(_FN
   639             strtod malloc calloc realloc free getenv setenv putenv unsetenv
   640             qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
   641             strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
   642             _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
   643             atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
   644             vsscanf vsnprintf fseeko fseeko64 sigaction setjmp
   645             nanosleep sysconf sysctlbyname getauxval
   646             )
   647       string(TOUPPER ${_FN} _UPPER)
   648       set(_HAVEVAR "HAVE_${_UPPER}")
   649       check_function_exists("${_FN}" ${_HAVEVAR})
   650     endforeach()
   651 
   652     check_library_exists(m pow "" HAVE_LIBM)
   653     if(HAVE_LIBM)
   654       set(CMAKE_REQUIRED_LIBRARIES m)
   655       foreach(_FN
   656               atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
   657               sinf sqrt sqrtf tan tanf acos asin)
   658         string(TOUPPER ${_FN} _UPPER)
   659         set(_HAVEVAR "HAVE_${_UPPER}")
   660         check_function_exists("${_FN}" ${_HAVEVAR})
   661       endforeach()
   662       set(CMAKE_REQUIRED_LIBRARIES)
   663       list(APPEND EXTRA_LIBS m)
   664     endif()
   665 
   666     check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
   667     if(HAVE_LIBICONV)
   668       list(APPEND EXTRA_LIBS iconv)
   669       set(HAVE_ICONV 1)
   670     endif()
   671 
   672     if(NOT APPLE)
   673       check_include_file(alloca.h HAVE_ALLOCA_H)
   674       check_function_exists(alloca HAVE_ALLOCA)
   675     else()
   676       set(HAVE_ALLOCA_H 1)
   677       set(HAVE_ALLOCA 1)
   678     endif()
   679 
   680     check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
   681   endif()
   682 else()
   683   if(WINDOWS)
   684     set(HAVE_STDARG_H 1)
   685     set(HAVE_STDDEF_H 1)
   686   endif()
   687 endif()
   688 
   689 
   690 # Enable/disable various subsystems of the SDL library
   691 foreach(_SUB ${SDL_SUBSYSTEMS})
   692   string(TOUPPER ${_SUB} _OPT)
   693   if(NOT SDL_${_OPT})
   694     set(SDL_${_OPT}_DISABLED 1)
   695   endif()
   696 endforeach()
   697 if(SDL_JOYSTICK)
   698   file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
   699   set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   700 endif()
   701 if(SDL_HAPTIC)
   702   if(NOT SDL_JOYSTICK)
   703     # Haptic requires some private functions from the joystick subsystem.
   704     message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
   705   endif()
   706   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
   707   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   708 endif()
   709 if(SDL_POWER)
   710   file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
   711   set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   712 endif()
   713 # TODO: in configure.in, the test for LOADSO and SDL_DLOPEN is a bit weird:
   714 # if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
   715 # If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
   716 # SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
   717 
   718 # General SDL subsystem options, valid for all platforms
   719 if(SDL_AUDIO)
   720   # CheckDummyAudio/CheckDiskAudio - valid for all platforms
   721   if(DUMMYAUDIO)
   722     set(SDL_AUDIO_DRIVER_DUMMY 1)
   723     file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
   724     set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
   725     set(HAVE_DUMMYAUDIO TRUE)
   726   endif()
   727   if(DISKAUDIO)
   728     set(SDL_AUDIO_DRIVER_DISK 1)
   729     file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
   730     set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
   731     set(HAVE_DISKAUDIO TRUE)
   732   endif()
   733 endif()
   734 
   735 if(SDL_DLOPEN)
   736   # Relevant for Unix/Darwin only
   737   if(UNIX OR APPLE)
   738     CheckDLOPEN()
   739   endif()
   740 endif()
   741 
   742 if(SDL_VIDEO)
   743   if(VIDEO_DUMMY)
   744     set(SDL_VIDEO_DRIVER_DUMMY 1)
   745     file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
   746     set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
   747     set(HAVE_VIDEO_DUMMY TRUE)
   748     set(HAVE_SDL_VIDEO TRUE)
   749   endif()
   750 endif()
   751 
   752 if(ANDROID)
   753   file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
   754   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
   755   file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
   756   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MAIN_SOURCES})
   757   if(SDL_AUDIO)
   758     set(SDL_AUDIO_DRIVER_ANDROID 1)
   759     file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
   760     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES})
   761     set(HAVE_SDL_AUDIO TRUE)
   762   endif()
   763   if(SDL_FILESYSTEM)
   764     set(SDL_FILESYSTEM_ANDROID 1)
   765     file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c)
   766     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES})
   767     set(HAVE_SDL_FILESYSTEM TRUE)
   768   endif()
   769   if(SDL_JOYSTICK)
   770     set(SDL_JOYSTICK_ANDROID 1)
   771     file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c)
   772     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
   773     set(HAVE_SDL_JOYSTICK TRUE)
   774   endif()
   775   if(SDL_POWER)
   776     set(SDL_POWER_ANDROID 1)
   777     file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c)
   778     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES})
   779     set(HAVE_SDL_POWER TRUE)
   780   endif()
   781   if(SDL_VIDEO)
   782     set(SDL_VIDEO_DRIVER_ANDROID 1)
   783     file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c)
   784     set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES})
   785     set(HAVE_SDL_VIDEO TRUE)
   786 
   787     #enable gles
   788     if(VIDEO_OPENGLES)
   789       set(SDL_VIDEO_OPENGL_EGL 1)
   790       set(HAVE_VIDEO_OPENGLES TRUE)
   791       set(SDL_VIDEO_OPENGL_ES2 1)
   792       set(SDL_VIDEO_RENDER_OGL_ES2 1)
   793     endif()
   794   endif()
   795   list(APPEND EXTRA_LDFLAGS "-Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit")
   796 endif()
   797 
   798 # Platform-specific options and settings
   799 if(EMSCRIPTEN)
   800   # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
   801   # project. Uncomment at will for verbose cross-compiling -I/../ path info.
   802   add_definitions(-Wno-warn-absolute-paths)
   803   if(SDL_AUDIO)
   804     set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
   805     file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
   806     set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
   807     set(HAVE_SDL_AUDIO TRUE)
   808   endif()
   809   if(SDL_FILESYSTEM)
   810     set(SDL_FILESYSTEM_EMSCRIPTEN 1)
   811     file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
   812     set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
   813     set(HAVE_SDL_FILESYSTEM TRUE)
   814   endif()
   815   if(SDL_JOYSTICK)
   816     set(SDL_JOYSTICK_EMSCRIPTEN 1)
   817     file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
   818     set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
   819     set(HAVE_SDL_JOYSTICK TRUE)
   820   endif()
   821   if(SDL_POWER)
   822     set(SDL_POWER_EMSCRIPTEN 1)
   823     file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
   824     set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
   825     set(HAVE_SDL_POWER TRUE)
   826   endif()
   827   if(SDL_TIMERS)
   828     set(SDL_TIMER_UNIX 1)
   829     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   830     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   831     set(HAVE_SDL_TIMERS TRUE)
   832 
   833     if(CLOCK_GETTIME)
   834       set(HAVE_CLOCK_GETTIME 1)
   835     endif()
   836   endif()
   837   if(SDL_VIDEO)
   838     set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
   839     file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
   840     set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
   841     set(HAVE_SDL_VIDEO TRUE)
   842 
   843     #enable gles
   844     if(VIDEO_OPENGLES)
   845       set(SDL_VIDEO_OPENGL_EGL 1)
   846       set(HAVE_VIDEO_OPENGLES TRUE)
   847       set(SDL_VIDEO_OPENGL_ES2 1)
   848       set(SDL_VIDEO_RENDER_OGL_ES2 1)
   849     endif()
   850   endif()
   851 elseif(UNIX AND NOT APPLE)
   852   if(SDL_AUDIO)
   853     if(SYSV5 OR SOLARIS OR HPUX)
   854         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   855         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
   856         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
   857         set(HAVE_SDL_AUDIO TRUE)
   858     elseif(NETBSD OR OPENBSD)
   859         set(SDL_AUDIO_DRIVER_BSD 1)
   860         file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
   861         set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
   862         set(HAVE_SDL_AUDIO TRUE)
   863     elseif(AIX)
   864         set(SDL_AUDIO_DRIVER_PAUDIO 1)
   865         file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
   866         set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
   867         set(HAVE_SDL_AUDIO TRUE)
   868     endif()
   869     CheckOSS()
   870     CheckALSA()
   871     CheckPulseAudio()
   872     CheckESD()
   873     CheckARTS()
   874     CheckNAS()
   875     CheckSNDIO()
   876     CheckFusionSound()
   877     CheckLibSampleRate()
   878   endif()
   879 
   880   if(SDL_VIDEO)
   881     # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
   882     CheckRPI()
   883     CheckX11()
   884     CheckMir()
   885     CheckDirectFB()
   886     CheckOpenGLX11()
   887     CheckOpenGLESX11()
   888     CheckWayland()
   889     CheckVivante()
   890   endif()
   891 
   892   if(LINUX)
   893     check_c_source_compiles("
   894         #include <linux/input.h>
   895         #ifndef EVIOCGNAME
   896         #error EVIOCGNAME() ioctl not available
   897         #endif
   898         int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
   899 
   900     check_c_source_compiles("
   901         #include <linux/kd.h>
   902         #include <linux/keyboard.h>
   903 
   904         int main(int argc, char **argv) 
   905         {
   906             struct kbentry kbe;
   907             kbe.kb_table = KG_CTRL;
   908             ioctl(0, KDGKBENT, &kbe);
   909         }" HAVE_INPUT_KD)
   910 
   911     file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
   912     set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   913 
   914     if(HAVE_INPUT_EVENTS)
   915       set(SDL_INPUT_LINUXEV 1)
   916     endif()
   917 
   918     if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
   919       set(SDL_HAPTIC_LINUX 1)
   920       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
   921       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   922       set(HAVE_SDL_HAPTIC TRUE)
   923     endif()
   924 
   925     if(HAVE_INPUT_KD)
   926       set(SDL_INPUT_LINUXKD 1)
   927     endif()
   928 
   929     check_include_file("libudev.h" HAVE_LIBUDEV_H)
   930 
   931     if(PKG_CONFIG_FOUND)
   932       pkg_search_module(DBUS dbus-1 dbus)
   933       if(DBUS_FOUND)
   934         set(HAVE_DBUS_DBUS_H TRUE)
   935         include_directories(${DBUS_INCLUDE_DIRS})
   936         list(APPEND EXTRA_LIBS ${DBUS_LIBRARIES})
   937       endif()
   938 
   939       pkg_search_module(IBUS ibus-1.0 ibus)
   940       if(IBUS_FOUND)
   941         set(HAVE_IBUS_IBUS_H TRUE)
   942         include_directories(${IBUS_INCLUDE_DIRS})
   943         list(APPEND EXTRA_LIBS ${IBUS_LIBRARIES})
   944       endif()
   945     endif()
   946 
   947     check_include_file("fcitx/frontend.h" HAVE_FCITX_FRONTEND_H)
   948 
   949   endif()
   950 
   951   if(INPUT_TSLIB)
   952     check_c_source_compiles("
   953         #include \"tslib.h\"
   954         int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
   955     if(HAVE_INPUT_TSLIB)
   956       set(SDL_INPUT_TSLIB 1)
   957       list(APPEND EXTRA_LIBS ts)
   958     endif()
   959   endif()
   960 
   961   if(SDL_JOYSTICK)
   962     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
   963     if(LINUX AND NOT ANDROID)
   964       set(SDL_JOYSTICK_LINUX 1)
   965       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
   966       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   967       set(HAVE_SDL_JOYSTICK TRUE)
   968     endif()
   969   endif()
   970 
   971   CheckPTHREAD()
   972 
   973   if(CLOCK_GETTIME)
   974     check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
   975     if(FOUND_CLOCK_GETTIME)
   976       list(APPEND EXTRA_LIBS rt)
   977       set(HAVE_CLOCK_GETTIME 1)
   978     else()
   979       check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
   980       if(FOUND_CLOCK_GETTIME)
   981         set(HAVE_CLOCK_GETTIME 1)
   982       endif()
   983     endif()
   984   endif()
   985 
   986   check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
   987   if(HAVE_LINUX_VERSION_H)
   988     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   989   endif()
   990 
   991   if(SDL_POWER)
   992     if(LINUX)
   993       set(SDL_POWER_LINUX 1)
   994       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
   995       set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   996       set(HAVE_SDL_POWER TRUE)
   997     endif()
   998   endif()
   999 
  1000   if(SDL_FILESYSTEM)
  1001     set(SDL_FILESYSTEM_UNIX 1)
  1002     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
  1003     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1004     set(HAVE_SDL_FILESYSTEM TRUE)
  1005   endif()
  1006 
  1007   if(SDL_TIMERS)
  1008     set(SDL_TIMER_UNIX 1)
  1009     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1010     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1011     set(HAVE_SDL_TIMERS TRUE)
  1012   endif()
  1013 
  1014   if(RPATH)
  1015     set(SDL_RLD_FLAGS "")
  1016     if(BSDI OR FREEBSD OR LINUX OR NETBSD)
  1017       set(CMAKE_REQUIRED_FLAGS "-Wl,--enable-new-dtags")
  1018       check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS)
  1019       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1020       if(HAVE_ENABLE_NEW_DTAGS)
  1021         set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir} -Wl,--enable-new-dtags")
  1022       else()
  1023         set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
  1024       endif()
  1025     elseif(SOLARIS)
  1026       set(SDL_RLD_FLAGS "-R\${libdir}")
  1027     endif()
  1028     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  1029     set(HAVE_RPATH TRUE)
  1030   endif()
  1031 
  1032 elseif(WINDOWS)
  1033   find_program(WINDRES windres)
  1034 
  1035   check_c_source_compiles("
  1036     #include <windows.h>
  1037     int main(int argc, char **argv) { }" HAVE_WIN32_CC)
  1038 
  1039   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1040   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1041 
  1042   if(MSVC)
  1043     # Prevent codegen that would use the VC runtime libraries.
  1044     add_definitions(/GS-)
  1045     if(NOT ARCH_64)
  1046       add_definitions(/arch:SSE)
  1047     endif()
  1048   endif()
  1049 
  1050   # Check for DirectX
  1051   if(DIRECTX)
  1052     if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700)
  1053         set(USE_WINSDK_DIRECTX TRUE)
  1054     endif()
  1055     if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
  1056       if("$ENV{DXSDK_DIR}" STREQUAL "")
  1057         message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
  1058       endif()
  1059       set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
  1060     endif()
  1061 
  1062     if(HAVE_WIN32_CC)
  1063       # xinput.h may need windows.h, but doesn't include it itself.
  1064       check_c_source_compiles("
  1065         #include <windows.h>
  1066         #include <xinput.h>
  1067         int main(int argc, char **argv) { }" HAVE_XINPUT_H)
  1068     else()
  1069       check_include_file(xinput.h HAVE_XINPUT_H)
  1070     endif()
  1071 
  1072     check_include_file(d3d9.h HAVE_D3D_H)
  1073     check_include_file(d3d11_1.h HAVE_D3D11_H)
  1074     check_include_file(ddraw.h HAVE_DDRAW_H)
  1075     check_include_file(dsound.h HAVE_DSOUND_H)
  1076     check_include_file(dinput.h HAVE_DINPUT_H)
  1077     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
  1078     check_include_file(dxgi.h HAVE_DXGI_H)
  1079     if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
  1080       set(HAVE_DIRECTX TRUE)
  1081       if(NOT CMAKE_COMPILER_IS_MINGW AND NOT USE_WINSDK_DIRECTX)
  1082       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
  1083         link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
  1084         include_directories($ENV{DXSDK_DIR}\\Include)
  1085       endif()
  1086     endif()
  1087     set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
  1088   endif()
  1089 
  1090   if(SDL_AUDIO)
  1091     set(SDL_AUDIO_DRIVER_WINMM 1)
  1092     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
  1093     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
  1094     set(HAVE_SDL_AUDIO TRUE)
  1095 
  1096     if(HAVE_DSOUND_H)
  1097       set(SDL_AUDIO_DRIVER_DSOUND 1)
  1098       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
  1099       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
  1100     endif()
  1101 
  1102     if(HAVE_XAUDIO2_H)
  1103       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
  1104       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
  1105       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
  1106     endif()
  1107   endif()
  1108 
  1109   if(SDL_VIDEO)
  1110     # requires SDL_LOADSO on Windows (IME, DX, etc.)
  1111     if(NOT SDL_LOADSO)
  1112       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
  1113     endif()
  1114     set(SDL_VIDEO_DRIVER_WINDOWS 1)
  1115     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
  1116     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
  1117 
  1118     if(RENDER_D3D AND HAVE_D3D_H)
  1119       set(SDL_VIDEO_RENDER_D3D 1)
  1120       set(HAVE_RENDER_D3D TRUE)
  1121     endif()
  1122     if(RENDER_D3D AND HAVE_D3D11_H)
  1123       set(SDL_VIDEO_RENDER_D3D11 1)
  1124       set(HAVE_RENDER_D3D TRUE)
  1125     endif()
  1126     set(HAVE_SDL_VIDEO TRUE)
  1127   endif()
  1128 
  1129   if(SDL_THREADS)
  1130     set(SDL_THREAD_WINDOWS 1)
  1131     set(SOURCE_FILES ${SOURCE_FILES}
  1132       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
  1133       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
  1134       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
  1135       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
  1136       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
  1137     set(HAVE_SDL_THREADS TRUE)
  1138   endif()
  1139 
  1140   if(SDL_POWER)
  1141     set(SDL_POWER_WINDOWS 1)
  1142     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
  1143     set(HAVE_SDL_POWER TRUE)
  1144   endif()
  1145 
  1146   if(SDL_FILESYSTEM)
  1147     set(SDL_FILESYSTEM_WINDOWS 1)
  1148     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
  1149     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1150     set(HAVE_SDL_FILESYSTEM TRUE)
  1151   endif()
  1152 
  1153   # Libraries for Win32 native and MinGW
  1154   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
  1155 
  1156   # TODO: in configure.in the check for timers is set on
  1157   # cygwin | mingw32* - does this include mingw32CE?
  1158   if(SDL_TIMERS)
  1159     set(SDL_TIMER_WINDOWS 1)
  1160     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
  1161     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1162     set(HAVE_SDL_TIMERS TRUE)
  1163   endif()
  1164 
  1165   if(SDL_LOADSO)
  1166     set(SDL_LOADSO_WINDOWS 1)
  1167     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
  1168     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1169     set(HAVE_SDL_LOADSO TRUE)
  1170   endif()
  1171 
  1172   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1173   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1174 
  1175   if(SDL_VIDEO)
  1176     if(VIDEO_OPENGL)
  1177       set(SDL_VIDEO_OPENGL 1)
  1178       set(SDL_VIDEO_OPENGL_WGL 1)
  1179       set(SDL_VIDEO_RENDER_OGL 1)
  1180       set(HAVE_VIDEO_OPENGL TRUE)
  1181     endif()
  1182 
  1183     if(VIDEO_OPENGLES)
  1184       set(SDL_VIDEO_OPENGL_EGL 1)
  1185       set(SDL_VIDEO_OPENGL_ES2 1)
  1186       set(SDL_VIDEO_RENDER_OGL_ES2 1)
  1187       set(HAVE_VIDEO_OPENGLES TRUE)
  1188     endif()
  1189   endif()
  1190 
  1191   if(SDL_JOYSTICK)
  1192     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1193     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1194     if(HAVE_DINPUT_H)
  1195       set(SDL_JOYSTICK_DINPUT 1)
  1196       list(APPEND EXTRA_LIBS dinput8)
  1197       if(CMAKE_COMPILER_IS_MINGW)
  1198         list(APPEND EXTRA_LIBS dxerr8)
  1199       elseif (NOT USE_WINSDK_DIRECTX)
  1200         list(APPEND EXTRA_LIBS dxerr)
  1201       endif()
  1202     endif()
  1203     if(HAVE_XINPUT_H)
  1204       set(SDL_JOYSTICK_XINPUT 1)
  1205     endif()
  1206     if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
  1207       set(SDL_JOYSTICK_WINMM 1)
  1208     endif()
  1209     set(HAVE_SDL_JOYSTICK TRUE)
  1210 
  1211     if(SDL_HAPTIC)
  1212       if(HAVE_DINPUT_H OR HAVE_XINPUT_H)
  1213         file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1214         if(HAVE_DINPUT_H)
  1215           set(SDL_HAPTIC_DINPUT 1)
  1216         endif()
  1217         if(HAVE_XINPUT_H)
  1218           set(SDL_HAPTIC_XINPUT 1)
  1219         endif()
  1220       else()
  1221         file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1222         set(SDL_HAPTIC_DUMMY 1)
  1223       endif()
  1224       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1225       set(HAVE_SDL_HAPTIC TRUE)
  1226     endif()
  1227   endif()
  1228 
  1229   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
  1230   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
  1231   if(MINGW OR CYGWIN)
  1232     list(APPEND EXTRA_LIBS mingw32)
  1233     list(APPEND EXTRA_LDFLAGS "-mwindows")
  1234     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
  1235     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
  1236   endif()
  1237 elseif(APPLE)
  1238   # TODO: rework this for proper MacOS X, iOS and Darwin support
  1239 
  1240   # Requires the darwin file implementation
  1241   if(SDL_FILE)
  1242     file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m)
  1243     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
  1244     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
  1245     set(HAVE_SDL_FILE TRUE)
  1246     set(SDL_FRAMEWORK_COCOA 1)
  1247     set(SDL_FRAMEWORK_COREVIDEO 1)
  1248   else()
  1249     message_error("SDL_FILE must be enabled to build on MacOS X")
  1250   endif()
  1251 
  1252   if(SDL_AUDIO)
  1253     set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  1254     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.m)
  1255     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
  1256     set(HAVE_SDL_AUDIO TRUE)
  1257     set(SDL_FRAMEWORK_COREAUDIO 1)
  1258     set(SDL_FRAMEWORK_AUDIOTOOLBOX 1)
  1259   endif()
  1260 
  1261   if(SDL_JOYSTICK)
  1262     set(SDL_JOYSTICK_IOKIT 1)
  1263     if (IOS)
  1264       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m)
  1265     else()
  1266       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1267     endif()
  1268     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1269     set(HAVE_SDL_JOYSTICK TRUE)
  1270     set(SDL_FRAMEWORK_IOKIT 1)
  1271     set(SDL_FRAMEWORK_FF 1)
  1272   endif()
  1273 
  1274   if(SDL_HAPTIC)
  1275     set(SDL_HAPTIC_IOKIT 1)
  1276     if (IOS)
  1277       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/dummy/*.c)
  1278       set(SDL_HAPTIC_DUMMY 1)
  1279     else()
  1280       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  1281     endif()
  1282     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1283     set(HAVE_SDL_HAPTIC TRUE)
  1284     set(SDL_FRAMEWORK_IOKIT 1)
  1285     set(SDL_FRAMEWORK_FF 1)
  1286     if(NOT SDL_JOYSTICK)
  1287       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
  1288     endif()
  1289   endif()
  1290 
  1291   if(SDL_POWER)
  1292     set(SDL_POWER_MACOSX 1)
  1293     if (IOS)
  1294       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/uikit/*.m)
  1295     else()
  1296       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  1297     endif()
  1298     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  1299     set(HAVE_SDL_POWER TRUE)
  1300     set(SDL_FRAMEWORK_CARBON 1)
  1301     set(SDL_FRAMEWORK_IOKIT 1)
  1302   endif()
  1303 
  1304   if(SDL_TIMERS)
  1305     set(SDL_TIMER_UNIX 1)
  1306     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1307     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1308     set(HAVE_SDL_TIMERS TRUE)
  1309   endif(SDL_TIMERS)
  1310 
  1311   if(SDL_FILESYSTEM)
  1312     set(SDL_FILESYSTEM_COCOA 1)
  1313     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  1314     set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
  1315     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1316     set(HAVE_SDL_FILESYSTEM TRUE)
  1317   endif()
  1318 
  1319   # Actually load the frameworks at the end so we don't duplicate include.
  1320   if(SDL_FRAMEWORK_COREVIDEO)
  1321     find_library(COREVIDEO CoreVideo)
  1322     list(APPEND EXTRA_LIBS ${COREVIDEO})
  1323   endif()
  1324   if(SDL_FRAMEWORK_COCOA)
  1325     find_library(COCOA_LIBRARY Cocoa)
  1326     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  1327   endif()
  1328   if(SDL_FRAMEWORK_IOKIT)
  1329     find_library(IOKIT IOKit)
  1330     list(APPEND EXTRA_LIBS ${IOKIT})
  1331   endif()
  1332   if(SDL_FRAMEWORK_FF)
  1333     find_library(FORCEFEEDBACK ForceFeedback)
  1334     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  1335   endif()
  1336   if(SDL_FRAMEWORK_CARBON)
  1337     find_library(CARBON_LIBRARY Carbon)
  1338     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  1339   endif()
  1340   if(SDL_FRAMEWORK_COREAUDIO)
  1341     find_library(COREAUDIO CoreAudio)
  1342     list(APPEND EXTRA_LIBS ${COREAUDIO})
  1343   endif()
  1344   if(SDL_FRAMEWORK_AUDIOTOOLBOX)
  1345     find_library(AUDIOTOOLBOX AudioToolbox)
  1346     list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
  1347   endif()
  1348 
  1349   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1350   if(SDL_VIDEO)
  1351     if (IOS)
  1352       set(SDL_VIDEO_DRIVER_UIKIT 1)
  1353       file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
  1354       set(SOURCE_FILES ${SOURCE_FILES} ${UIKITVIDEO_SOURCES})
  1355     else()
  1356       CheckCOCOA()
  1357       if(VIDEO_OPENGL)
  1358         set(SDL_VIDEO_OPENGL 1)
  1359         set(SDL_VIDEO_OPENGL_CGL 1)
  1360         set(SDL_VIDEO_RENDER_OGL 1)
  1361         set(HAVE_VIDEO_OPENGL TRUE)
  1362       endif()
  1363     endif()
  1364   endif()
  1365 
  1366   CheckPTHREAD()
  1367 elseif(HAIKU)
  1368   if(SDL_VIDEO)
  1369     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1370     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1371     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1372     set(HAVE_SDL_VIDEO TRUE)
  1373 
  1374     set(SDL_FILESYSTEM_HAIKU 1)
  1375     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  1376     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1377     set(HAVE_SDL_FILESYSTEM TRUE)
  1378 
  1379     if(SDL_TIMERS)
  1380       set(SDL_TIMER_HAIKU 1)
  1381       file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  1382       set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1383       set(HAVE_SDL_TIMERS TRUE)
  1384     endif(SDL_TIMERS)
  1385 
  1386     if(VIDEO_OPENGL)
  1387       # TODO: Use FIND_PACKAGE(OpenGL) instead
  1388       set(SDL_VIDEO_OPENGL 1)
  1389       set(SDL_VIDEO_OPENGL_BGL 1)
  1390       set(SDL_VIDEO_RENDER_OGL 1)
  1391       list(APPEND EXTRA_LIBS GL)
  1392       set(HAVE_VIDEO_OPENGL TRUE)
  1393     endif()
  1394   endif()
  1395 
  1396   CheckPTHREAD()
  1397 endif()
  1398 
  1399 # Dummies
  1400 # configure.in does it differently:
  1401 # if not have X
  1402 #   if enable_X {  SDL_X_DISABLED = 1 }
  1403 #   [add dummy sources]
  1404 # so it always adds a dummy, without checking, if it was actually requested.
  1405 # This leads to missing internal references on building, since the
  1406 # src/X/*.c does not get included.
  1407 if(NOT HAVE_SDL_JOYSTICK)
  1408   set(SDL_JOYSTICK_DISABLED 1)
  1409   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1410 
  1411     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1412     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1413   endif()
  1414 endif()
  1415 if(NOT HAVE_SDL_HAPTIC)
  1416   set(SDL_HAPTIC_DISABLED 1)
  1417   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1418   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1419 endif()
  1420 if(NOT HAVE_SDL_LOADSO)
  1421   set(SDL_LOADSO_DISABLED 1)
  1422   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1423   set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1424 endif()
  1425 if(NOT HAVE_SDL_FILESYSTEM)
  1426   set(SDL_FILESYSTEM_DISABLED 1)
  1427   file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1428   set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1429 endif()
  1430 
  1431 # We always need to have threads and timers around
  1432 if(NOT HAVE_SDL_THREADS)
  1433   set(SDL_THREADS_DISABLED 1)
  1434   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1435   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1436 endif()
  1437 if(NOT HAVE_SDL_TIMERS)
  1438   set(SDL_TIMERS_DISABLED 1)
  1439   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1440   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1441 endif()
  1442 
  1443 if(NOT SDLMAIN_SOURCES)
  1444   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1445 endif()
  1446 
  1447 # Append the -MMD -MT flags
  1448 # if(DEPENDENCY_TRACKING)
  1449 #   if(COMPILER_IS_GNUCC)
  1450 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1451 #   endif()
  1452 # endif()
  1453 
  1454 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1455   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1456 
  1457 # Prepare the flags and remove duplicates
  1458 if(EXTRA_LDFLAGS)
  1459   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1460 endif()
  1461 if(EXTRA_LIBS)
  1462   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1463 endif()
  1464 if(EXTRA_CFLAGS)
  1465   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1466 endif()
  1467 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1468 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1469 
  1470 # Compat helpers for the configuration files
  1471 if(NOT WINDOWS OR CYGWIN)
  1472   # TODO: we need a Windows script, too
  1473   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1474 
  1475   set(prefix ${CMAKE_INSTALL_PREFIX})
  1476   set(exec_prefix "\${prefix}")
  1477   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1478   set(bindir "\${exec_prefix}/bin")
  1479   set(includedir "\${prefix}/include")
  1480   if(SDL_STATIC)
  1481     set(ENABLE_STATIC_TRUE "")
  1482     set(ENABLE_STATIC_FALSE "#")
  1483   else()
  1484     set(ENABLE_STATIC_TRUE "#")
  1485     set(ENABLE_STATIC_FALSE "")
  1486   endif()
  1487   if(SDL_SHARED)
  1488     set(ENABLE_SHARED_TRUE "")
  1489     set(ENABLE_SHARED_FALSE "#")
  1490   else()
  1491     set(ENABLE_SHARED_TRUE "#")
  1492     set(ENABLE_SHARED_FALSE "")
  1493   endif()
  1494 
  1495   # Clean up the different lists
  1496   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1497   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1498   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1499   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1500   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1501   listtostr(SDL_LIBS _SDL_LIBS)
  1502   set(SDL_LIBS ${_SDL_LIBS})
  1503 
  1504   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1505   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1506 
  1507   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1508     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1509   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1510     "${SDL2_BINARY_DIR}/sdl2-config")
  1511   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1512     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1513   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1514     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1515 endif()
  1516 
  1517 ##### Info output #####
  1518 message(STATUS "")
  1519 message(STATUS "SDL2 was configured with the following options:")
  1520 message(STATUS "")
  1521 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1522 message(STATUS "64-bit:   ${ARCH_64}")
  1523 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1524 message(STATUS "")
  1525 message(STATUS "Subsystems:")
  1526 foreach(_SUB ${SDL_SUBSYSTEMS})
  1527   string(TOUPPER ${_SUB} _OPT)
  1528   message_bool_option(${_SUB} SDL_${_OPT})
  1529 endforeach()
  1530 message(STATUS "")
  1531 message(STATUS "Options:")
  1532 list(SORT ALLOPTIONS)
  1533 foreach(_OPT ${ALLOPTIONS})
  1534   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1535   # Get the padding
  1536   string(LENGTH ${_OPT} _OPTLEN)
  1537   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1538   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1539   message_tested_option(${_OPT} ${_PADDING})
  1540 endforeach()
  1541 message(STATUS "")
  1542 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1543 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1544 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1545 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1546 message(STATUS "")
  1547 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1548 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1549 if(SDL_STATIC)
  1550     message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
  1551 endif()
  1552 message(STATUS "")
  1553 if(UNIX)
  1554   message(STATUS "If something was not detected, although the libraries")
  1555   message(STATUS "were installed, then make sure you have set the")
  1556   message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  1557   message(STATUS "")
  1558 endif()
  1559 
  1560 # Ensure that the extra cflags are used at compile time
  1561 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1562 
  1563 # Always build SDLmain
  1564 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1565 set(_INSTALL_LIBS "SDL2main")
  1566 
  1567 if(SDL_SHARED)
  1568   add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
  1569   if(UNIX)
  1570     set_target_properties(SDL2 PROPERTIES
  1571       VERSION ${LT_VERSION}
  1572       SOVERSION ${LT_REVISION}
  1573       OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1574   else()
  1575     set_target_properties(SDL2 PROPERTIES
  1576       VERSION ${SDL_VERSION}
  1577       SOVERSION ${LT_REVISION}
  1578       OUTPUT_NAME "SDL2")
  1579   endif()
  1580   if(MSVC)
  1581     # Don't try to link with the default set of libraries.
  1582     set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1583     set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1584     set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1585   endif()
  1586   set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1587   target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1588 endif()
  1589 
  1590 if(SDL_STATIC)
  1591   set (BUILD_SHARED_LIBS FALSE)
  1592   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1593   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1594   set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC})
  1595   if(MSVC)
  1596     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1597     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1598     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1599   endif()
  1600   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1601   # libraries - do we need to consider this?
  1602   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1603   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1604 endif()
  1605 
  1606 ##### Installation targets #####
  1607 install(TARGETS ${_INSTALL_LIBS}
  1608   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1609   ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
  1610   RUNTIME DESTINATION bin)
  1611 
  1612 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1613 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1614 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1615   get_filename_component(_INCNAME ${_FNAME} NAME)
  1616   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1617 endforeach()
  1618 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1619 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1620 
  1621 if(NOT (WINDOWS OR CYGWIN))
  1622   if(SDL_SHARED)
  1623     if (APPLE)
  1624         set(SOEXT "dylib")
  1625     else()
  1626         set(SOEXT "so")
  1627     endif()
  1628     install(CODE "
  1629       execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1630       \"libSDL2-2.0.${SOEXT}\" \"libSDL2.${SOEXT}\")")
  1631     install(FILES ${SDL2_BINARY_DIR}/libSDL2.${SOEXT} DESTINATION "lib${LIB_SUFFIX}")
  1632   endif()
  1633   if(FREEBSD)
  1634     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1635     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1636   else()
  1637     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1638       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1639   endif()
  1640   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1641   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1642   install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/aclocal")
  1643 endif()
  1644 
  1645 ##### Uninstall target #####
  1646 
  1647 configure_file(
  1648     "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  1649     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  1650     IMMEDIATE @ONLY)
  1651 
  1652 add_custom_target(uninstall
  1653     COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)