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