CMakeLists.txt
author David Ludwig <dludwig@pobox.com>
Wed, 25 Dec 2013 21:39:48 -0500
changeset 8563 c0e68f3b6bbb
parent 8032 e2096994e8b8
child 8056 abd9434c5d3e
permissions -rw-r--r--
WinRT: compiled the d3d11 renderer's shaders into SDL itself

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