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