CMakeLists.txt
author Ryan C. Gordon
Fri, 20 Mar 2015 21:57:15 -0400
changeset 9414 669bf9fb901e
parent 9411 6810478a60e9
child 9431 a9c73f29a15e
permissions -rw-r--r--
Several corrections to the CMake project files (thanks, Ozkan!).

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