CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Thu, 18 Dec 2014 00:19:52 -0500
changeset 9278 8900afb78a19
parent 9277 f0bd40782fc7
child 9279 e1d1b6479a14
permissions -rw-r--r--
Initial merge of Emscripten port!

With this commit, you can compile SDL2 with Emscripten
( http://emscripten.org/ ), and make your SDL-based C/C++ program
into a web app.

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