CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Fri, 20 Mar 2015 10:35:42 -0400
changeset 9409 9df20f292907
parent 9408 93ba64cb5e16
child 9411 6810478a60e9
permissions -rw-r--r--
CMake project files no longer force you to link against Wayland or Mir libs.
     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)
   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     endif()
   612 
   613     check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
   614   endif()
   615 else()
   616   if(WINDOWS)
   617     set(HAVE_STDARG_H 1)
   618     set(HAVE_STDDEF_H 1)
   619   endif()
   620 endif()
   621 
   622 
   623 # Enable/disable various subsystems of the SDL library
   624 foreach(_SUB ${SDL_SUBSYSTEMS})
   625   string(TOUPPER ${_SUB} _OPT)
   626   if(NOT SDL_${_OPT})
   627     set(SDL_${_OPT}_DISABLED 1)
   628   endif()
   629 endforeach()
   630 if(SDL_JOYSTICK)
   631   file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
   632   set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   633 endif()
   634 if(SDL_HAPTIC)
   635   if(NOT SDL_JOYSTICK)
   636     # Haptic requires some private functions from the joystick subsystem.
   637     message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
   638   endif()
   639   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
   640   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   641 endif()
   642 if(SDL_POWER)
   643   file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
   644   set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   645 endif()
   646 # TODO: in configure.in, the test for LOADSO and SDL_DLOPEN is a bit weird:
   647 # if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
   648 # If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
   649 # SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
   650 
   651 # General SDL subsystem options, valid for all platforms
   652 if(SDL_AUDIO)
   653   # CheckDummyAudio/CheckDiskAudio - valid for all platforms
   654   if(DUMMYAUDIO)
   655     set(SDL_AUDIO_DRIVER_DUMMY 1)
   656     file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
   657     set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
   658     set(HAVE_DUMMYAUDIO TRUE)
   659   endif()
   660   if(DISKAUDIO)
   661     set(SDL_AUDIO_DRIVER_DISK 1)
   662     file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
   663     set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
   664     set(HAVE_DISKAUDIO TRUE)
   665   endif()
   666 endif()
   667 
   668 if(SDL_DLOPEN)
   669   # Relevant for Unix/Darwin only
   670   if(UNIX OR APPLE)
   671     CheckDLOPEN()
   672   endif()
   673 endif()
   674 
   675 if(SDL_VIDEO)
   676   if(VIDEO_DUMMY)
   677     set(SDL_VIDEO_DRIVER_DUMMY 1)
   678     file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
   679     set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
   680     set(HAVE_VIDEO_DUMMY TRUE)
   681     set(HAVE_SDL_VIDEO TRUE)
   682   endif()
   683 endif()
   684 
   685 # Platform-specific options and settings
   686 if(EMSCRIPTEN)
   687   # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
   688   # project. Uncomment at will for verbose cross-compiling -I/../ path info.
   689   add_definitions(-Wno-warn-absolute-paths)
   690   if(SDL_AUDIO)
   691     set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
   692     file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
   693     set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
   694     set(HAVE_SDL_AUDIO TRUE)
   695   endif()
   696   if(SDL_FILESYSTEM)
   697     set(SDL_FILESYSTEM_EMSCRIPTEN 1)
   698     file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
   699     set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
   700     set(HAVE_SDL_FILESYSTEM TRUE)
   701   endif()
   702   if(SDL_JOYSTICK)
   703     set(SDL_JOYSTICK_EMSCRIPTEN 1)
   704     file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
   705     set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
   706     set(HAVE_SDL_JOYSTICK TRUE)
   707   endif()
   708   if(SDL_POWER)
   709     set(SDL_POWER_EMSCRIPTEN 1)
   710     file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
   711     set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
   712     set(HAVE_SDL_POWER TRUE)
   713   endif()
   714   if(SDL_VIDEO)
   715     set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
   716     file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
   717     set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
   718     set(HAVE_SDL_VIDEO TRUE)
   719 
   720     #enable gles
   721     if(VIDEO_OPENGLES)
   722       set(SDL_VIDEO_OPENGL_EGL 1)
   723       set(HAVE_VIDEO_OPENGLES TRUE)
   724       set(SDL_VIDEO_OPENGL_ES2 1)
   725       set(SDL_VIDEO_RENDER_OGL_ES2 1)
   726     endif()
   727   endif()
   728 elseif(UNIX AND NOT APPLE)
   729   if(SDL_AUDIO)
   730     if(SYSV5 OR SOLARIS OR HPUX)
   731         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   732         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
   733         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
   734         set(HAVE_SDL_AUDIO TRUE)
   735     elseif(NETBSD OR OPENBSD)
   736         set(SDL_AUDIO_DRIVER_BSD 1)
   737         file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
   738         set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
   739         set(HAVE_SDL_AUDIO TRUE)
   740     elseif(AIX)
   741         set(SDL_AUDIO_DRIVER_PAUDIO 1)
   742         file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
   743         set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
   744         set(HAVE_SDL_AUDIO TRUE)
   745     endif()
   746     CheckOSS()
   747     CheckALSA()
   748     CheckPulseAudio()
   749     CheckESD()
   750     CheckARTS()
   751     CheckNAS()
   752     CheckSNDIO()
   753     CheckFusionSound()
   754   endif()
   755 
   756   if(SDL_VIDEO)
   757     # Need to check for Raspberry PI first and add platform specific compiler flags, otherwise the test for GLES fails!
   758     CheckRPI()
   759     CheckX11()
   760     CheckMir()
   761     CheckDirectFB()
   762     CheckOpenGLX11()
   763     CheckOpenGLESX11()
   764     CheckWayland()
   765     CheckVivante()
   766   endif()
   767 
   768   if(LINUX)
   769     check_c_source_compiles("
   770         #include <linux/input.h>
   771         #ifndef EVIOCGNAME
   772         #error EVIOCGNAME() ioctl not available
   773         #endif
   774         int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
   775 
   776     check_c_source_compiles("
   777         #include <linux/kd.h>
   778         #include <linux/keyboard.h>
   779 
   780         int main(int argc, char **argv) 
   781         {
   782             struct kbentry kbe;
   783             kbe.kb_table = KG_CTRL;
   784             ioctl(0, KDGKBENT, &kbe);
   785         }" HAVE_INPUT_KD)
   786 
   787     file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
   788     set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   789 
   790     if(HAVE_INPUT_EVENTS)
   791       set(SDL_INPUT_LINUXEV 1)
   792     endif()
   793 
   794     if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
   795       set(SDL_HAPTIC_LINUX 1)
   796       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
   797       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   798       set(HAVE_SDL_HAPTIC TRUE)
   799     endif()
   800 
   801     if(HAVE_INPUT_KD)
   802       set(SDL_INPUT_LINUXKD 1)
   803     endif()
   804 
   805     check_include_file("libudev.h" HAVE_LIBUDEV_H)
   806 
   807     # !!! FIXME: this needs pkg-config to find the include path, I think.
   808     check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
   809   endif()
   810 
   811   if(INPUT_TSLIB)
   812     check_c_source_compiles("
   813         #include \"tslib.h\"
   814         int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
   815     if(HAVE_INPUT_TSLIB)
   816       set(SDL_INPUT_TSLIB 1)
   817       list(APPEND EXTRA_LIBS ts)
   818     endif()
   819   endif()
   820 
   821   if(SDL_JOYSTICK)
   822     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
   823     if(LINUX)
   824       set(SDL_JOYSTICK_LINUX 1)
   825       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
   826       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   827       set(HAVE_SDL_JOYSTICK TRUE)
   828     endif()
   829   endif()
   830 
   831   CheckPTHREAD()
   832 
   833   if(CLOCK_GETTIME)
   834     check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
   835     if(FOUND_CLOCK_GETTIME)
   836       list(APPEND EXTRA_LIBS rt)
   837       set(HAVE_CLOCK_GETTIME 1)
   838     else()
   839       check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
   840       if(FOUND_CLOCK_GETTIME)
   841         set(HAVE_CLOCK_GETTIME 1)
   842       endif()
   843     endif()
   844   endif()
   845 
   846   check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
   847   if(HAVE_LINUX_VERSION_H)
   848     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   849   endif()
   850 
   851   if(SDL_POWER)
   852     if(LINUX)
   853       set(SDL_POWER_LINUX 1)
   854       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
   855       set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   856       set(HAVE_SDL_POWER TRUE)
   857     endif()
   858   endif()
   859 
   860   if(SDL_FILESYSTEM)
   861     set(SDL_FILESYSTEM_UNIX 1)
   862     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
   863     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   864     set(HAVE_SDL_FILESYSTEM TRUE)
   865   endif()
   866 
   867   if(SDL_TIMERS)
   868     set(SDL_TIMER_UNIX 1)
   869     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   870     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   871     set(HAVE_SDL_TIMERS TRUE)
   872   endif()
   873 
   874   if(RPATH)
   875     set(SDL_RLD_FLAGS "")
   876     if(BSDI OR FREEBSD OR LINUX OR NETBSD)
   877       set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
   878     elseif(SOLARIS)
   879       set(SDL_RLD_FLAGS "-R\${libdir}")
   880     endif()
   881     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
   882     set(HAVE_RPATH TRUE)
   883   endif()
   884 
   885 elseif(WINDOWS)
   886   find_program(WINDRES windres)
   887 
   888   check_c_source_compiles("
   889     #include <windows.h>
   890     int main(int argc, char **argv) { }" HAVE_WIN32_CC)
   891 
   892   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   893   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   894 
   895   # Check for DirectX
   896   if(DIRECTX)
   897     if("$ENV{DXSDK_DIR}" STREQUAL "")
   898       message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
   899     endif()
   900     set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
   901     check_include_file(d3d9.h HAVE_D3D_H)
   902     check_include_file(d3d11_1.h HAVE_D3D11_H)
   903     check_include_file(ddraw.h HAVE_DDRAW_H)
   904     check_include_file(dsound.h HAVE_DSOUND_H)
   905     check_include_file(dinput.h HAVE_DINPUT_H)
   906     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
   907     check_include_file(xinput.h HAVE_XINPUT_H)
   908     check_include_file(dxgi.h HAVE_DXGI_H)
   909     if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
   910       set(HAVE_DIRECTX TRUE)
   911       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   912       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   913       include_directories($ENV{DXSDK_DIR}\\Include)
   914     endif()
   915     set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   916   endif()
   917 
   918   if(SDL_AUDIO)
   919     set(SDL_AUDIO_DRIVER_WINMM 1)
   920     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   921     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
   922     set(HAVE_SDL_AUDIO TRUE)
   923 
   924     if(HAVE_DSOUND_H)
   925       set(SDL_AUDIO_DRIVER_DSOUND 1)
   926       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
   927       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
   928     endif()
   929 
   930     if(HAVE_XAUDIO2_H)
   931       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
   932       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
   933       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
   934     endif()
   935   endif()
   936 
   937   if(SDL_VIDEO)
   938     # requires SDL_LOADSO on Windows (IME, DX, etc.)
   939     if(NOT SDL_LOADSO)
   940       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
   941     endif()
   942     set(SDL_VIDEO_DRIVER_WINDOWS 1)
   943     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
   944     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
   945 
   946     if(RENDER_D3D AND HAVE_D3D_H)
   947       set(SDL_VIDEO_RENDER_D3D 1)
   948       set(HAVE_RENDER_D3D TRUE)
   949     endif()
   950     if(RENDER_D3D AND HAVE_D3D11_H)
   951       set(SDL_VIDEO_RENDER_D3D11 1)
   952       set(HAVE_RENDER_D3D TRUE)
   953     endif()
   954     set(HAVE_SDL_VIDEO TRUE)
   955   endif()
   956 
   957   if(SDL_THREADS)
   958     set(SDL_THREAD_WINDOWS 1)
   959     set(SOURCE_FILES ${SOURCE_FILES}
   960       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
   961       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
   962       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
   963       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
   964       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   965     set(HAVE_SDL_THREADS TRUE)
   966   endif()
   967 
   968   if(SDL_POWER)
   969     set(SDL_POWER_WINDOWS 1)
   970     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   971     set(HAVE_SDL_POWER TRUE)
   972   endif()
   973 
   974   if(SDL_FILESYSTEM)
   975     set(SDL_FILESYSTEM_WINDOWS 1)
   976     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
   977     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   978     set(HAVE_SDL_FILESYSTEM TRUE)
   979   endif()
   980 
   981   # Libraries for Win32 native and MinGW
   982   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   983 
   984   # TODO: in configure.in the check for timers is set on
   985   # cygwin | mingw32* - does this include mingw32CE?
   986   if(SDL_TIMERS)
   987     set(SDL_TIMER_WINDOWS 1)
   988     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   989     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   990     set(HAVE_SDL_TIMERS TRUE)
   991   endif()
   992 
   993   if(SDL_LOADSO)
   994     set(SDL_LOADSO_WINDOWS 1)
   995     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   996     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   997     set(HAVE_SDL_LOADSO TRUE)
   998   endif()
   999 
  1000   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
  1001   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
  1002 
  1003   if(SDL_VIDEO)
  1004     if(VIDEO_OPENGL)
  1005       set(SDL_VIDEO_OPENGL 1)
  1006       set(SDL_VIDEO_OPENGL_WGL 1)
  1007       set(SDL_VIDEO_RENDER_OGL 1)
  1008       set(HAVE_VIDEO_OPENGL TRUE)
  1009     endif()
  1010   endif()
  1011 
  1012   if(SDL_JOYSTICK)
  1013     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/windows/*.c)
  1014     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1015     if(HAVE_DINPUT_H)
  1016       set(SDL_JOYSTICK_DINPUT 1)
  1017       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
  1018     endif()
  1019     if(HAVE_XINPUT_H)
  1020       set(SDL_JOYSTICK_XINPUT 1)
  1021     endif()
  1022     if(NOT HAVE_DINPUT_H AND NOT HAVE_XINPUT_H)
  1023       set(SDL_JOYSTICK_WINMM 1)
  1024     endif()
  1025     set(HAVE_SDL_JOYSTICK TRUE)
  1026 
  1027     if(SDL_HAPTIC)
  1028       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/windows/*.c)
  1029       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1030       if(HAVE_DINPUT_H)
  1031         set(SDL_HAPTIC_DINPUT 1)
  1032       endif()
  1033       if(HAVE_XINPUT_H)
  1034         set(SDL_HAPTIC_XINPUT 1)
  1035       endif()
  1036       set(HAVE_SDL_HAPTIC TRUE)
  1037     endif()
  1038   endif()
  1039 
  1040   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
  1041   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
  1042   if(MINGW OR CYGWIN)
  1043     list(APPEND EXTRA_LIBS mingw32)
  1044     list(APPEND EXTRA_LDFLAGS "-mwindows")
  1045     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
  1046     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
  1047   endif()
  1048 elseif(APPLE)
  1049   # TODO: rework this for proper MacOS X, iOS and Darwin support
  1050 
  1051   # Requires the darwin file implementation
  1052   if(SDL_FILE)
  1053     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
  1054     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
  1055     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
  1056     set(HAVE_SDL_FILE TRUE)
  1057     set(SDL_FRAMEWORK_COCOA 1)
  1058     set(SDL_FRAMEWORK_COREVIDEO 1)
  1059   else()
  1060     message_error("SDL_FILE must be enabled to build on MacOS X")
  1061   endif()
  1062 
  1063   if(SDL_AUDIO)
  1064     set(SDL_AUDIO_DRIVER_COREAUDIO 1)
  1065     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
  1066     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
  1067     set(HAVE_SDL_AUDIO TRUE)
  1068     set(SDL_FRAMEWORK_COREAUDIO 1)
  1069     set(SDL_FRAMEWORK_AUDIOUNIT 1)
  1070   endif()
  1071 
  1072   if(SDL_JOYSTICK)
  1073     set(SDL_JOYSTICK_IOKIT 1)
  1074     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
  1075     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1076     set(HAVE_SDL_JOYSTICK TRUE)
  1077     set(SDL_FRAMEWORK_IOKIT 1)
  1078     set(SDL_FRAMEWORK_FF 1)
  1079   endif()
  1080 
  1081   if(SDL_HAPTIC)
  1082     set(SDL_HAPTIC_IOKIT 1)
  1083     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
  1084     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1085     set(HAVE_SDL_HAPTIC TRUE)
  1086     set(SDL_FRAMEWORK_IOKIT 1)
  1087     set(SDL_FRAMEWORK_FF 1)
  1088     if(NOT SDL_JOYSTICK)
  1089       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
  1090     endif()
  1091   endif()
  1092 
  1093   if(SDL_POWER)
  1094     set(SDL_POWER_MACOSX 1)
  1095     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
  1096     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
  1097     set(HAVE_SDL_POWER TRUE)
  1098     set(SDL_FRAMEWORK_CARBON 1)
  1099     set(SDL_FRAMEWORK_IOKIT 1)
  1100   endif()
  1101 
  1102   if(SDL_TIMERS)
  1103     set(SDL_TIMER_UNIX 1)
  1104     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
  1105     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1106     set(HAVE_SDL_TIMERS TRUE)
  1107   endif(SDL_TIMERS)
  1108 
  1109   if(SDL_FILESYSTEM)
  1110     set(SDL_FILESYSTEM_COCOA 1)
  1111     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  1112     set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
  1113     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1114     set(HAVE_SDL_FILESYSTEM TRUE)
  1115   endif()
  1116 
  1117   # Actually load the frameworks at the end so we don't duplicate include.
  1118   if(SDL_FRAMEWORK_COREVIDEO)
  1119     find_library(COREVIDEO CoreVideo)
  1120     list(APPEND EXTRA_LIBS ${COREVIDEO})
  1121   endif()
  1122   if(SDL_FRAMEWORK_COCOA)
  1123     find_library(COCOA_LIBRARY Cocoa)
  1124     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  1125   endif()
  1126   if(SDL_FRAMEWORK_IOKIT)
  1127     find_library(IOKIT IOKit)
  1128     list(APPEND EXTRA_LIBS ${IOKIT})
  1129   endif()
  1130   if(SDL_FRAMEWORK_FF)
  1131     find_library(FORCEFEEDBACK ForceFeedback)
  1132     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  1133   endif()
  1134   if(SDL_FRAMEWORK_CARBON)
  1135     find_library(CARBON_LIBRARY Carbon)
  1136     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  1137   endif()
  1138   if(SDL_FRAMEWORK_COREAUDIO)
  1139     find_library(COREAUDIO CoreAudio)
  1140     list(APPEND EXTRA_LIBS ${COREAUDIO})
  1141   endif()
  1142   if(SDL_FRAMEWORK_AUDIOUNIT)
  1143     find_library(AUDIOUNIT AudioUnit)
  1144     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
  1145   endif()
  1146 
  1147   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1148   if(SDL_VIDEO)
  1149     CheckCOCOA()
  1150     if(VIDEO_OPENGL)
  1151       set(SDL_VIDEO_OPENGL 1)
  1152       set(SDL_VIDEO_OPENGL_CGL 1)
  1153       set(SDL_VIDEO_RENDER_OGL 1)
  1154       if(DARWIN)
  1155         find_library(OpenGL_LIBRARY OpenGL)
  1156         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
  1157       endif()
  1158       set(HAVE_VIDEO_OPENGL TRUE)
  1159     endif()
  1160   endif()
  1161 
  1162   CheckPTHREAD()
  1163 elseif(HAIKU)
  1164   if(SDL_VIDEO)
  1165     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1166     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1167     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1168     set(HAVE_SDL_VIDEO TRUE)
  1169 
  1170     set(SDL_FILESYSTEM_HAIKU 1)
  1171     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  1172     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1173     set(HAVE_SDL_FILESYSTEM TRUE)
  1174 
  1175     if(SDL_TIMERS)
  1176       set(SDL_TIMER_HAIKU 1)
  1177       file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  1178       set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1179       set(HAVE_SDL_TIMERS TRUE)
  1180     endif(SDL_TIMERS)
  1181 
  1182     if(VIDEO_OPENGL)
  1183       # TODO: Use FIND_PACKAGE(OpenGL) instead
  1184       set(SDL_VIDEO_OPENGL 1)
  1185       set(SDL_VIDEO_OPENGL_BGL 1)
  1186       set(SDL_VIDEO_RENDER_OGL 1)
  1187       list(APPEND EXTRA_LIBS GL)
  1188       set(HAVE_VIDEO_OPENGL TRUE)
  1189     endif()
  1190   endif()
  1191 
  1192   CheckPTHREAD()
  1193 endif()
  1194 
  1195 # Dummies
  1196 # configure.in does it differently:
  1197 # if not have X
  1198 #   if enable_X {  SDL_X_DISABLED = 1 }
  1199 #   [add dummy sources]
  1200 # so it always adds a dummy, without checking, if it was actually requested.
  1201 # This leads to missing internal references on building, since the
  1202 # src/X/*.c does not get included.
  1203 if(NOT HAVE_SDL_JOYSTICK)
  1204   set(SDL_JOYSTICK_DISABLED 1)
  1205   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1206 
  1207     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1208     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1209   endif()
  1210 endif()
  1211 if(NOT HAVE_SDL_HAPTIC)
  1212   set(SDL_HAPTIC_DISABLED 1)
  1213   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1214   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1215 endif()
  1216 if(NOT HAVE_SDL_LOADSO)
  1217   set(SDL_LOADSO_DISABLED 1)
  1218   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1219   set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1220 endif()
  1221 if(NOT HAVE_SDL_FILESYSTEM)
  1222   set(SDL_FILESYSTEM_DISABLED 1)
  1223   file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1224   set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1225 endif()
  1226 
  1227 # We always need to have threads and timers around
  1228 if(NOT HAVE_SDL_THREADS)
  1229   set(SDL_THREADS_DISABLED 1)
  1230   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1231   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1232 endif()
  1233 if(NOT HAVE_SDL_TIMERS)
  1234   set(SDL_TIMERS_DISABLED 1)
  1235   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1236   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1237 endif()
  1238 
  1239 if(NOT SDLMAIN_SOURCES)
  1240   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1241 endif()
  1242 
  1243 # Append the -MMD -MT flags
  1244 # if(DEPENDENCY_TRACKING)
  1245 #   if(COMPILER_IS_GNUCC)
  1246 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1247 #   endif()
  1248 # endif()
  1249 
  1250 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1251   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1252 
  1253 # Prepare the flags and remove duplicates
  1254 if(EXTRA_LDFLAGS)
  1255   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1256 endif()
  1257 if(EXTRA_LIBS)
  1258   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1259 endif()
  1260 if(EXTRA_CFLAGS)
  1261   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1262 endif()
  1263 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1264 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1265 
  1266 # Compat helpers for the configuration files
  1267 if(NOT WINDOWS OR CYGWIN)
  1268   # TODO: we need a Windows script, too
  1269   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1270 
  1271   set(prefix ${CMAKE_INSTALL_PREFIX})
  1272   set(exec_prefix "\${prefix}")
  1273   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1274   set(bindir "\${exec_prefix}/bin")
  1275   set(includedir "\${prefix}/include")
  1276   if(SDL_STATIC)
  1277     set(ENABLE_STATIC_TRUE "")
  1278     set(ENABLE_STATIC_FALSE "#")
  1279   else()
  1280     set(ENABLE_STATIC_TRUE "#")
  1281     set(ENABLE_STATIC_FALSE "")
  1282   endif()
  1283   if(SDL_SHARED)
  1284     set(ENABLE_SHARED_TRUE "")
  1285     set(ENABLE_SHARED_FALSE "#")
  1286   else()
  1287     set(ENABLE_SHARED_TRUE "#")
  1288     set(ENABLE_SHARED_FALSE "")
  1289   endif()
  1290 
  1291   # Clean up the different lists
  1292   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1293   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1294   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1295   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1296   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1297   listtostr(SDL_LIBS _SDL_LIBS)
  1298   set(SDL_LIBS ${_SDL_LIBS})
  1299 
  1300   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1301   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1302 
  1303   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1304     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1305   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1306     "${SDL2_BINARY_DIR}/sdl2-config")
  1307   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1308     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1309   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1310     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1311 endif()
  1312 
  1313 ##### Info output #####
  1314 message(STATUS "")
  1315 message(STATUS "SDL2 was configured with the following options:")
  1316 message(STATUS "")
  1317 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1318 message(STATUS "64-bit:   ${ARCH_64}")
  1319 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1320 message(STATUS "")
  1321 message(STATUS "Subsystems:")
  1322 foreach(_SUB ${SDL_SUBSYSTEMS})
  1323   string(TOUPPER ${_SUB} _OPT)
  1324   message_bool_option(${_SUB} SDL_${_OPT})
  1325 endforeach()
  1326 message(STATUS "")
  1327 message(STATUS "Options:")
  1328 list(SORT ALLOPTIONS)
  1329 foreach(_OPT ${ALLOPTIONS})
  1330   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1331   # Get the padding
  1332   string(LENGTH ${_OPT} _OPTLEN)
  1333   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1334   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1335   message_tested_option(${_OPT} ${_PADDING})
  1336 endforeach()
  1337 message(STATUS "")
  1338 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1339 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1340 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1341 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1342 message(STATUS "")
  1343 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1344 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1345 message(STATUS "")
  1346 if(UNIX)
  1347   message(STATUS "If something was not detected, although the libraries")
  1348   message(STATUS "were installed, then make sure you have set the")
  1349   message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  1350   message(STATUS "")
  1351 endif()
  1352 
  1353 # Ensure that the extra cflags are used at compile time
  1354 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1355 
  1356 # Always build SDLmain
  1357 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1358 set(_INSTALL_LIBS "SDL2main")
  1359 
  1360 if(SDL_SHARED)
  1361   add_library(SDL2 SHARED ${SOURCE_FILES})
  1362   if(UNIX)
  1363     set_target_properties(SDL2 PROPERTIES
  1364       VERSION ${LT_VERSION}
  1365       SOVERSION ${LT_REVISION}
  1366       OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1367   else()
  1368     set_target_properties(SDL2 PROPERTIES
  1369       VERSION ${SDL_VERSION}
  1370       SOVERSION ${LT_REVISION}
  1371       OUTPUT_NAME "SDL2")
  1372   endif()
  1373  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1374  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1375 endif()
  1376 
  1377 if(SDL_STATIC)
  1378   set (BUILD_SHARED_LIBS FALSE)
  1379   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1380   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1381   if(MSVC)
  1382     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1383     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1384     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1385   endif()
  1386   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1387   # libraries - do we need to consider this?
  1388   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1389   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1390 endif()
  1391 
  1392 ##### Installation targets #####
  1393 install(TARGETS ${_INSTALL_LIBS}
  1394   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1395   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1396 
  1397 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1398 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1399 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1400   get_filename_component(_INCNAME ${_FNAME} NAME)
  1401   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1402 endforeach()
  1403 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1404 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1405 
  1406 if(NOT WINDOWS OR CYGWIN)
  1407   if(SDL_SHARED)
  1408     install(CODE "
  1409       execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1410       \"libSDL2-2.0.so\" \"libSDL2.so\")")
  1411     install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
  1412   endif()
  1413   if(FREEBSD)
  1414     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1415     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1416   else()
  1417     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1418       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1419   endif()
  1420   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1421   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1422   install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "share/aclocal")
  1423 else()
  1424   if(SDL_SHARED)
  1425     install(TARGETS SDL2 RUNTIME DESTINATION bin)
  1426   endif()
  1427 endif()
  1428 
  1429 ##### Uninstall target #####
  1430 
  1431 configure_file(
  1432     "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  1433     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  1434     IMMEDIATE @ONLY)
  1435 
  1436 add_custom_target(uninstall
  1437     COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)