CMakeLists.txt
author Gabriel Jacobo <gabomdq@gmail.com>
Sat, 14 Dec 2013 20:18:43 -0300
changeset 8062 4fc5f66d63cc
parent 8056 abd9434c5d3e
child 8089 de8b6fdf6544
permissions -rw-r--r--
Wayland support

Based on the original port to Wayland by: Joel Teichroeb, Benjamin Franzke, Scott Moreau, et al.

Additional changes in this commit, done by me:

* Wayland uses the common EGL framework
* EGL can now create a desktop OpenGL context
* testgl2 loads GL functions dynamically, no need to link to libGL anymore
* Assorted fixes to the Wayland backend

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