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