CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Sat, 13 Jul 2013 00:10:25 -0400
changeset 7427 c47b59bac287
parent 7426 e36a759d3bb1
child 7525 e5ae3502a25e
permissions -rw-r--r--
CMake project should install sdl2.m4.

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