CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Tue, 20 Aug 2013 19:57:11 -0400
changeset 7667 be1cc6f55840
parent 7666 603fb699946c
child 7803 97a1127629fb
permissions -rw-r--r--
Added SDL_GetBasePath() and SDL_GetPrefPath() in new filesystem module.
     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 0)
    33 set(SDL_INTERFACE_AGE 0)
    34 set(SDL_BINARY_AGE 0)
    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     if(HAVE_INPUT_EVENTS)
   652       set(SDL_INPUT_LINUXEV 1)
   653     endif(HAVE_INPUT_EVENTS)
   654 
   655     if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
   656       set(SDL_HAPTIC_LINUX 1)
   657       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
   658       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   659       set(HAVE_SDL_HAPTIC TRUE)
   660     endif(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
   661 
   662     check_include_file("libudev.h" HAVE_LIBUDEV_H)
   663 
   664     # !!! FIXME: this needs pkg-config to find the include path, I think.
   665     check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
   666   endif(LINUX)
   667 
   668   if(INPUT_TSLIB)
   669     check_c_source_compiles("
   670         #include \"tslib.h\"
   671         int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
   672     if(HAVE_INPUT_TSLIB)
   673       set(SDL_INPUT_TSLIB 1)
   674       list(APPEND EXTRA_LIBS ts)
   675     endif(HAVE_INPUT_TSLIB)
   676   endif(INPUT_TSLIB)
   677 
   678   if(SDL_JOYSTICK)
   679     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
   680     if(LINUX)
   681       set(SDL_JOYSTICK_LINUX 1)
   682       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
   683       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   684       set(HAVE_SDL_JOYSTICK TRUE)
   685     endif(LINUX)
   686   endif(SDL_JOYSTICK)
   687 
   688   CheckPTHREAD()
   689 
   690   if(CLOCK_GETTIME)
   691     check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
   692     if(FOUND_CLOCK_GETTIME)
   693       list(APPEND EXTRA_LIBS rt)
   694       set(HAVE_CLOCK_GETTIME 1)
   695     else(FOUND_CLOCK_GETTIME)
   696       check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
   697       if(FOUND_CLOCK_GETTIME)
   698         set(HAVE_CLOCK_GETTIME 1)
   699       endif(FOUND_CLOCK_GETTIME)
   700     endif(HAVE_CLOCK_GETTIME)
   701   endif(CLOCK_GETTIME)
   702 
   703   check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
   704   if(HAVE_LINUX_VERSION_H)
   705     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   706   endif(HAVE_LINUX_VERSION_H)
   707 
   708   if(SDL_POWER)
   709     if(LINUX)
   710       set(SDL_POWER_LINUX 1)
   711       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
   712       set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   713       set(HAVE_SDL_POWER TRUE)
   714     endif(LINUX)
   715   endif(SDL_POWER)
   716 
   717   if(SDL_FILESYSTEM)
   718     set(SDL_FILESYSTEM_UNIX 1)
   719     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/unix/*.c)
   720     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   721     set(HAVE_SDL_FILESYSTEM TRUE)
   722   endif(SDL_FILESYSTEM)
   723 
   724   if(SDL_TIMERS)
   725     set(SDL_TIMER_UNIX 1)
   726     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   727     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   728     set(HAVE_SDL_TIMERS TRUE)
   729   endif(SDL_TIMERS)
   730 
   731   if(RPATH)
   732     set(SDL_RLD_FLAGS "")
   733     if(BSDI OR FREEBSD OR LINUX OR NETBSD)
   734       set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
   735     elseif(SOLARIS)
   736       set(SDL_RLD_FLAGS "-R\${libdir}")
   737     endif()
   738     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
   739     set(HAVE_RPATH TRUE)
   740   endif(RPATH)
   741 
   742 elseif(WINDOWS)
   743   find_program(WINDRES windres)
   744 
   745   check_c_source_compiles("
   746     #include <windows.h>
   747     int main(int argc, char **argv) { }" HAVE_WIN32_CC)
   748 
   749   file(GLOB WIN_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   750   set(SOURCE_FILES ${SOURCE_FILES} ${WIN_SOURCES})
   751 
   752   # Check for DirectX
   753   if(DIRECTX)
   754     if("$ENV{DXSDK_DIR}" STREQUAL "")
   755       message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
   756     endif("$ENV{DXSDK_DIR}" STREQUAL "")
   757     set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
   758     check_include_file(d3d9.h HAVE_D3D_H)
   759     check_include_file(ddraw.h HAVE_DDRAW_H)
   760     check_include_file(dsound.h HAVE_DSOUND_H)
   761     check_include_file(dinput.h HAVE_DINPUT_H)
   762     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
   763     if(HAVE_D3D_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
   764       set(HAVE_DIRECTX TRUE)
   765       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   766       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   767       include_directories($ENV{DXSDK_DIR}\\Include)
   768     endif()
   769     set(CMAKE_REQUIRED_FLAGS)
   770   endif(DIRECTX)
   771 
   772   if(SDL_AUDIO)
   773     set(SDL_AUDIO_DRIVER_WINMM 1)
   774     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   775     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
   776     set(HAVE_SDL_AUDIO TRUE)
   777 
   778     if(HAVE_DSOUND_H)
   779       set(SDL_AUDIO_DRIVER_DSOUND 1)
   780       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
   781       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
   782     endif(HAVE_DSOUND_H)
   783 
   784     if(HAVE_XAUDIO2_H)
   785       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
   786       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
   787       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
   788     endif(HAVE_XAUDIO2_H)
   789   endif(SDL_AUDIO)
   790 
   791   if(SDL_VIDEO)
   792     # requires SDL_LOADSO on Windows (IME, DX, etc.)
   793     if(NOT SDL_LOADSO)
   794       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
   795     endif(NOT SDL_LOADSO)
   796     set(SDL_VIDEO_DRIVER_WINDOWS 1)
   797     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
   798     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
   799 
   800     if(RENDER_D3D AND HAVE_D3D_H)
   801       set(SDL_VIDEO_RENDER_D3D 1)
   802       set(HAVE_RENDER_D3D TRUE)
   803     endif(RENDER_D3D AND HAVE_D3D_H)
   804     set(HAVE_SDL_VIDEO TRUE)
   805   endif(SDL_VIDEO)
   806 
   807   if(SDL_THREADS)
   808     set(SDL_THREAD_WINDOWS 1)
   809     set(SOURCE_FILES ${SOURCE_FILES}
   810       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
   811       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
   812       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
   813       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
   814       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   815     set(HAVE_SDL_THREADS TRUE)
   816   endif(SDL_THREADS)
   817 
   818   if(SDL_POWER)
   819     set(SDL_POWER_WINDOWS 1)
   820     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   821     set(HAVE_SDL_POWER TRUE)
   822   endif(SDL_POWER)
   823 
   824   if(SDL_FILESYSTEM)
   825     set(SDL_FILESYSTEM_WINDOWS 1)
   826     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesytem/windows/*.c)
   827     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   828     set(HAVE_SDL_FILESYSTEM TRUE)
   829   endif(SDL_FILESYSTEM)
   830 
   831   # Libraries for Win32 native and MinGW
   832   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   833 
   834   # TODO: in configure.in the check for timers is set on
   835   # cygwin | mingw32* - does this include mingw32CE?
   836   if(SDL_TIMERS)
   837     set(SDL_TIMER_WINDOWS 1)
   838     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   839     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   840     set(HAVE_SDL_TIMERS TRUE)
   841   endif(SDL_TIMERS)
   842 
   843   if(SDL_LOADSO)
   844     set(SDL_LOADSO_WINDOWS 1)
   845     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   846     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   847     set(HAVE_SDL_LOADSO TRUE)
   848   endif(SDL_LOADSO)
   849 
   850   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   851   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   852 
   853   if(SDL_VIDEO)
   854     if(VIDEO_OPENGL)
   855       set(SDL_VIDEO_OPENGL 1)
   856       set(SDL_VIDEO_OPENGL_WGL 1)
   857       set(SDL_VIDEO_RENDER_OGL 1)
   858       set(HAVE_VIDEO_OPENGL TRUE)
   859     endif(VIDEO_OPENGL)
   860   endif(SDL_VIDEO)
   861 
   862   if(SDL_JOYSTICK)
   863     if(HAVE_DINPUT_H)
   864       set(SDL_JOYSTICK_DINPUT 1)
   865       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_dxjoystick.c)
   866       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
   867     else()
   868       set(SDL_JOYSTICK_WINMM 1)
   869       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_mmjoystick.c)
   870     endif(HAVE_DINPUT_H)
   871     set(HAVE_SDL_JOYSTICK TRUE)
   872   endif(SDL_JOYSTICK)
   873 
   874   if(SDL_HAPTIC AND HAVE_DINPUT_H)
   875     set(SDL_HAPTIC_DINPUT 1)
   876     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/haptic/windows/SDL_syshaptic.c)
   877     set(HAVE_SDL_HAPTIC TRUE)
   878   endif(SDL_HAPTIC AND HAVE_DINPUT_H)
   879 
   880   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
   881   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
   882   if(MINGW OR CYGWIN)
   883     list(APPEND EXTRA_LIBS mingw32)
   884     list(APPEND EXTRA_LDFLAGS "-mwindows")
   885     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
   886     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
   887   endif(MINGW OR CYGWIN)
   888 elseif(APPLE)
   889   # TODO: rework this for proper MacOS X, iOS and Darwin support
   890 
   891   # Requires the darwin file implementation
   892   if(SDL_FILE)
   893     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
   894     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
   895     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
   896     set(HAVE_SDL_FILE TRUE)
   897     set(SDL_FRAMEWORK_COCOA 1)
   898   else()
   899     message_error("SDL_FILE must be enabled to build on MacOS X")
   900   endif()
   901 
   902   if(SDL_AUDIO)
   903     set(MACOSX_COREAUDIO 1)
   904     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
   905     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
   906     set(HAVE_SDL_AUDIO TRUE)
   907     set(SDL_FRAMEWORK_COREAUDIO 1)
   908     set(SDL_FRAMEWORK_AUDIOUNIT 1)
   909   endif()
   910 
   911   if(SDL_JOYSTICK)
   912     set(SDL_JOYSTICK_IOKIT 1)
   913     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
   914     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   915     set(HAVE_SDL_JOYSTICK TRUE)
   916     set(SDL_FRAMEWORK_IOKIT 1)
   917     set(SDL_FRAMEWORK_FF 1)
   918   endif()
   919 
   920   if(SDL_HAPTIC)
   921     set(SDL_HAPTIC_IOKIT 1)
   922     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
   923     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   924     set(HAVE_SDL_HAPTIC TRUE)
   925     set(SDL_FRAMEWORK_IOKIT 1)
   926     set(SDL_FRAMEWORK_FF 1)
   927     if(NOT SDL_JOYSTICK)
   928       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
   929     endif()
   930   endif()
   931 
   932   if(SDL_POWER)
   933     set(SDL_POWER_MACOSX 1)
   934     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
   935     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   936     set(HAVE_SDL_POWER TRUE)
   937     set(SDL_FRAMEWORK_CARBON 1)
   938     set(SDL_FRAMEWORK_IOKIT 1)
   939   endif()
   940 
   941   if(SDL_FILESYSTEM)
   942     set(SDL_FILESYSTEM_COCOA 1)
   943     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
   944     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   945     set(HAVE_SDL_FILESYSTEM TRUE)
   946   endif()
   947 
   948   # Actually load the frameworks at the end so we don't duplicate include.
   949   if(SDL_FRAMEWORK_COCOA)
   950     find_library(COCOA_LIBRARY Cocoa)
   951     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
   952   endif()
   953   if(SDL_FRAMEWORK_IOKIT)
   954     find_library(IOKIT IOKit)
   955     list(APPEND EXTRA_LIBS ${IOKIT})
   956   endif()
   957   if(SDL_FRAMEWORK_FF)
   958     find_library(FORCEFEEDBACK ForceFeedback)
   959     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
   960   endif()
   961   if(SDL_FRAMEWORK_CARBON)
   962     find_library(CARBON_LIBRARY Carbon)
   963     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
   964   endif()
   965   if(SDL_FRAMEWORK_COREAUDIO)
   966     find_library(COREAUDIO CoreAudio)
   967     list(APPEND EXTRA_LIBS ${COREAUDIO})
   968   endif()
   969   if(SDL_FRAMEWORK_AUDIOUNIT)
   970     find_library(AUDIOUNIT AudioUnit)
   971     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
   972   endif()
   973 
   974   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
   975   if(SDL_VIDEO)
   976     CheckCOCOA()
   977     if(VIDEO_OPENGL)
   978       set(SDL_VIDEO_OPENGL 1)
   979       set(SDL_VIDEO_OPENGL_CGL 1)
   980       set(SDL_VIDEO_RENDER_OGL 1)
   981       if(DARWIN)
   982         find_library(OpenGL_LIBRARY OpenGL)
   983         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
   984       endif(DARWIN)
   985       set(HAVE_VIDEO_OPENGL TRUE)
   986     endif(VIDEO_OPENGL)
   987   endif(SDL_VIDEO)
   988 
   989   CheckPTHREAD()
   990 elseif(BEOS)
   991   if(SDL_VIDEO)
   992     set(SDL_VIDEO_DRIVER_BWINDOW 1)
   993     file(GLOB BWINDOW_SOURCES ${SDL2_SOURCE_DIR}/src/video/bwindow/*.c)
   994     set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
   995     set(HAVE_SDL_VIDEO TRUE)
   996 
   997     set(SDL_FILESYSTEM_BEOS 1)
   998     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/beos/*.cc)
   999     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1000     set(HAVE_SDL_FILESYSTEM TRUE)
  1001 
  1002     if(VIDEO_OPENGL)
  1003       # TODO: Use FIND_PACKAGE(OpenGL) instead
  1004       set(SDL_VIDEO_OPENGL 1)
  1005       set(SDL_VIDEO_OPENGL_BGL 1)
  1006       set(SDL_VIDEO_RENDER_OGL 1)
  1007       list(APPEND EXTRA_LIBS GL)
  1008       set(HAVE_VIDEO_OPENGL TRUE)
  1009     endif(VIDEO_OPENGL)
  1010   endif(SDL_VIDEO)
  1011 endif()
  1012 
  1013 # Dummies
  1014 # configure.in does it differently:
  1015 # if not have X
  1016 #   if enable_X {  SDL_X_DISABLED = 1 }
  1017 #   [add dummy sources]
  1018 # so it always adds a dummy, without checking, if it was actually requested.
  1019 # This leads to missing internal references on building, since the
  1020 # src/X/*.c does not get included.
  1021 if(NOT HAVE_SDL_JOYSTICK)
  1022   set(SDL_JOYSTICK_DISABLED 1)
  1023   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1024 
  1025     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1026     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1027   endif()
  1028 endif(NOT HAVE_SDL_JOYSTICK)
  1029 if(NOT HAVE_SDL_HAPTIC)
  1030   set(SDL_HAPTIC_DISABLED 1)
  1031   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1032   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1033 endif(NOT HAVE_SDL_HAPTIC)
  1034 if(NOT HAVE_SDL_LOADSO)
  1035   set(SDL_LOADSO_DISABLED 1)
  1036   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1037   set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1038 endif(NOT HAVE_SDL_LOADSO)
  1039 if(NOT HAVE_SDL_FILESYSTEM)
  1040   set(SDL_FILESYSTEM_DISABLED 1)
  1041   file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1042   set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1043 endif(NOT HAVE_SDL_FILESYSTEM)
  1044 
  1045 # We always need to have threads and timers around
  1046 if(NOT HAVE_SDL_THREADS)
  1047   set(SDL_THREADS_DISABLED 1)
  1048   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1049   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1050 endif(NOT HAVE_SDL_THREADS)
  1051 if(NOT HAVE_SDL_TIMERS)
  1052   set(SDL_TIMERS_DISABLED 1)
  1053   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1054   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1055 endif(NOT HAVE_SDL_TIMERS)
  1056 
  1057 if(NOT SDLMAIN_SOURCES)
  1058   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1059 endif(NOT SDLMAIN_SOURCES)
  1060 
  1061 # Append the -MMD -MT flags
  1062 # if(DEPENDENCY_TRACKING)
  1063 #   if(COMPILER_IS_GNUCC)
  1064 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1065 #   endif(COMPILER_IS_GNUCC)
  1066 # endif(DEPENDENCY_TRACKING)
  1067 
  1068 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1069   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1070 
  1071 # Prepare the flags and remove duplicates
  1072 if(EXTRA_LDFLAGS)
  1073   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1074 endif(EXTRA_LDFLAGS)
  1075 if(EXTRA_LIBS)
  1076   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1077 endif(EXTRA_LIBS)
  1078 if(EXTRA_CFLAGS)
  1079   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1080 endif(EXTRA_CFLAGS)
  1081 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1082 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1083 
  1084 # Compat helpers for the configuration files
  1085 if(NOT WINDOWS OR CYGWIN)
  1086   # TODO: we need a Windows script, too
  1087   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1088 
  1089   set(prefix ${CMAKE_INSTALL_PREFIX})
  1090   set(exec_prefix "\${prefix}")
  1091   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1092   set(bindir "\${exec_prefix}/bin")
  1093   set(includedir "\${prefix}/include")
  1094   if(SDL_STATIC)
  1095     set(ENABLE_STATIC_TRUE "")
  1096     set(ENABLE_STATIC_FALSE "#")
  1097   else(SDL_STATIC)
  1098     set(ENABLE_STATIC_TRUE "#")
  1099     set(ENABLE_STATIC_FALSE "")
  1100   endif(SDL_STATIC)
  1101   if(SDL_SHARED)
  1102     set(ENABLE_SHARED_TRUE "")
  1103     set(ENABLE_SHARED_FALSE "#")
  1104   else(SDL_SHARED)
  1105     set(ENABLE_SHARED_TRUE "#")
  1106     set(ENABLE_SHARED_FALSE "")
  1107   endif(SDL_SHARED)
  1108 
  1109   # Clean up the different lists
  1110   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1111   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1112   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1113   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1114   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1115   listtostr(SDL_LIBS _SDL_LIBS)
  1116   set(SDL_LIBS ${_SDL_LIBS})
  1117 
  1118   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1119   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1120 
  1121   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1122     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1123   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1124     "${SDL2_BINARY_DIR}/sdl2-config")
  1125   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1126     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1127   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1128     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1129 endif(NOT WINDOWS OR CYGWIN)
  1130 
  1131 ##### Info output #####
  1132 message(STATUS "")
  1133 message(STATUS "SDL2 was configured with the following options:")
  1134 message(STATUS "")
  1135 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1136 message(STATUS "64-bit:   ${ARCH_64}")
  1137 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1138 message(STATUS "")
  1139 message(STATUS "Subsystems:")
  1140 foreach(_SUB ${SDL_SUBSYSTEMS})
  1141   string(TOUPPER ${_SUB} _OPT)
  1142   message_bool_option(${_SUB} SDL_${_OPT})
  1143 endforeach()
  1144 message(STATUS "")
  1145 message(STATUS "Options:")
  1146 list(SORT ALLOPTIONS)
  1147 foreach(_OPT ${ALLOPTIONS})
  1148   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1149   # Get the padding
  1150   string(LENGTH ${_OPT} _OPTLEN)
  1151   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1152   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1153   message_tested_option(${_OPT} ${_PADDING})
  1154 endforeach()
  1155 message(STATUS "")
  1156 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1157 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1158 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1159 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1160 message(STATUS "")
  1161 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1162 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1163 message(STATUS "")
  1164 if(UNIX)
  1165   message(STATUS "Something was not detected, although your are sure that it")
  1166   message(STATUS "has been properly installed? Then make sure, you have set")
  1167   message(STATUS "the CFLAGS and LDFLAGS environment variables correctly.")
  1168   message(STATUS "")
  1169 endif(UNIX)
  1170 
  1171 # Ensure that the extra cflags are used at compile time
  1172 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1173 
  1174 # Always build SDLmain
  1175 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1176 set(_INSTALL_LIBS "SDL2main")
  1177 
  1178 if(SDL_SHARED)
  1179   add_library(SDL2 SHARED ${SOURCE_FILES})
  1180   if(UNIX)
  1181     set_target_properties(SDL2 PROPERTIES
  1182       VERSION ${LT_VERSION}
  1183       SOVERSION ${LT_CURRENT}
  1184       OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1185   else(UNIX)
  1186     set_target_properties(SDL2 PROPERTIES
  1187       VERSION ${SDL_VERSION}
  1188       SOVERSION ${LT_CURRENT}
  1189       OUTPUT_NAME "SDL2")
  1190   endif(UNIX)
  1191  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1192  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1193 endif(SDL_SHARED)
  1194 
  1195 if(SDL_STATIC)
  1196   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1197   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1198   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1199   # libraries - do we need to consider this?
  1200   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1201   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1202 endif(SDL_STATIC)
  1203 
  1204 ##### Installation targets #####
  1205 install(TARGETS ${_INSTALL_LIBS}
  1206   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1207   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1208 
  1209 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1210 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1211 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1212   get_filename_component(_INCNAME ${_FNAME} NAME)
  1213   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1214 endforeach()
  1215 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1216 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1217 
  1218 if(SDL_SHARED)
  1219   install(CODE "
  1220     execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1221     \"libSDL2-2.0.so\" \"libSDL2.so\")")
  1222   install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
  1223 endif(SDL_SHARED)
  1224 
  1225 if(NOT WINDOWS OR CYGWIN)
  1226   if(FREEBSD)
  1227     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1228     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1229   else(FREEBSD)
  1230     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1231       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1232   endif(FREEBSD)
  1233   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1234   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1235   install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "share/aclocal")
  1236 endif(NOT WINDOWS OR CYGWIN)