CMakeLists.txt
author Sam Lantinga <slouken@libsdl.org>
Mon, 11 Nov 2013 22:43:05 -0800
changeset 7965 d3cbe8ecb1af
parent 7903 4d3e6191c807
child 7977 5272ae8fccd7
permissions -rw-r--r--
Fixed assertion when quickly toggling from fullscreen back to fullscreen:
"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'backgroundWindows not nil in enterFullScreenTransitionWithOptions:animated:activatingIt:'"

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