CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Wed, 10 Jul 2013 23:43:35 -0400
changeset 7395 c1b80390a820
parent 7367 d6eabafa8776
child 7426 e36a759d3bb1
permissions -rw-r--r--
Added src/thread/windows/SDL_systls.c to CMakeLists.txt (thanks, Charles!).

Fixes Bugzilla #1955.
     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/windows/SDL_systls.c
   799       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   800     set(HAVE_SDL_THREADS TRUE)
   801   endif(SDL_THREADS)
   802 
   803   if(SDL_POWER)
   804     set(SDL_POWER_WINDOWS 1)
   805     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   806     set(HAVE_SDL_POWER TRUE)
   807   endif(SDL_POWER)
   808 
   809   # Libraries for Win32 native and MinGW
   810   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   811 
   812   # TODO: in configure.in the check for timers is set on
   813   # cygwin | mingw32* - does this include mingw32CE?
   814   if(SDL_TIMERS)
   815     set(SDL_TIMER_WINDOWS 1)
   816     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   817     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   818     set(HAVE_SDL_TIMERS TRUE)
   819   endif(SDL_TIMERS)
   820 
   821   if(SDL_LOADSO)
   822     set(SDL_LOADSO_WINDOWS 1)
   823     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   824     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   825     set(HAVE_SDL_LOADSO TRUE)
   826   endif(SDL_LOADSO)
   827 
   828   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   829   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   830 
   831   if(SDL_VIDEO)
   832     if(VIDEO_OPENGL)
   833       set(SDL_VIDEO_OPENGL 1)
   834       set(SDL_VIDEO_OPENGL_WGL 1)
   835       set(SDL_VIDEO_RENDER_OGL 1)
   836       set(HAVE_VIDEO_OPENGL TRUE)
   837     endif(VIDEO_OPENGL)
   838   endif(SDL_VIDEO)
   839 
   840   if(SDL_JOYSTICK)
   841     if(HAVE_DINPUT_H)
   842       set(SDL_JOYSTICK_DINPUT 1)
   843       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_dxjoystick.c)
   844       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
   845     else()
   846       set(SDL_JOYSTICK_WINMM 1)
   847       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_mmjoystick.c)
   848     endif(HAVE_DINPUT_H)
   849     set(HAVE_SDL_JOYSTICK TRUE)
   850   endif(SDL_JOYSTICK)
   851 
   852   if(SDL_HAPTIC AND HAVE_DINPUT_H)
   853     set(SDL_HAPTIC_DINPUT 1)
   854     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/haptic/windows/SDL_syshaptic.c)
   855     set(HAVE_SDL_HAPTIC TRUE)
   856   endif(SDL_HAPTIC AND HAVE_DINPUT_H)
   857 
   858   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
   859   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
   860   if(MINGW OR CYGWIN)
   861     list(APPEND EXTRA_LIBS mingw32)
   862     list(APPEND EXTRA_LDFLAGS "-mwindows")
   863     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
   864     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
   865   endif(MINGW OR CYGWIN)
   866 elseif(APPLE)
   867   # TODO: rework this for proper MacOS X, iOS and Darwin support
   868 
   869   # Requires the darwin file implementation
   870   if(SDL_FILE)
   871     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
   872     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
   873     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
   874     set(HAVE_SDL_FILE TRUE)
   875     set(SDL_FRAMEWORK_COCOA 1)
   876   else()
   877     message_error("SDL_FILE must be enabled to build on MacOS X")
   878   endif()
   879 
   880   if(SDL_AUDIO)
   881     set(MACOSX_COREAUDIO 1)
   882     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
   883     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
   884     set(HAVE_SDL_AUDIO TRUE)
   885     set(SDL_FRAMEWORK_COREAUDIO 1)
   886     set(SDL_FRAMEWORK_AUDIOUNIT 1)
   887   endif()
   888 
   889   if(SDL_JOYSTICK)
   890     set(SDL_JOYSTICK_IOKIT 1)
   891     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
   892     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   893     set(HAVE_SDL_JOYSTICK TRUE)
   894     set(SDL_FRAMEWORK_IOKIT 1)
   895     set(SDL_FRAMEWORK_FF 1)
   896   endif()
   897 
   898   if(SDL_HAPTIC)
   899     set(SDL_HAPTIC_IOKIT 1)
   900     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
   901     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   902     set(HAVE_SDL_HAPTIC TRUE)
   903     set(SDL_FRAMEWORK_IOKIT 1)
   904     set(SDL_FRAMEWORK_FF 1)
   905     if(NOT SDL_JOYSTICK)
   906       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
   907     endif()
   908   endif()
   909 
   910   if(SDL_POWER)
   911     set(SDL_POWER_MACOSX 1)
   912     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
   913     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   914     set(HAVE_SDL_POWER TRUE)
   915     set(SDL_FRAMEWORK_CARBON 1)
   916     set(SDL_FRAMEWORK_IOKIT 1)
   917   endif()
   918 
   919   # Actually load the frameworks at the end so we don't duplicate include.
   920   if(SDL_FRAMEWORK_COCOA)
   921     find_library(COCOA_LIBRARY Cocoa)
   922     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
   923   endif()
   924   if(SDL_FRAMEWORK_IOKIT)
   925     find_library(IOKIT IOKit)
   926     list(APPEND EXTRA_LIBS ${IOKIT})
   927   endif()
   928   if(SDL_FRAMEWORK_FF)
   929     find_library(FORCEFEEDBACK ForceFeedback)
   930     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
   931   endif()
   932   if(SDL_FRAMEWORK_CARBON)
   933     find_library(CARBON_LIBRARY Carbon)
   934     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
   935   endif()
   936   if(SDL_FRAMEWORK_COREAUDIO)
   937     find_library(COREAUDIO CoreAudio)
   938     list(APPEND EXTRA_LIBS ${COREAUDIO})
   939   endif()
   940   if(SDL_FRAMEWORK_AUDIOUNIT)
   941     find_library(AUDIOUNIT AudioUnit)
   942     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
   943   endif()
   944 
   945   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
   946   if(SDL_VIDEO)
   947     CheckCOCOA()
   948     if(VIDEO_OPENGL)
   949       set(SDL_VIDEO_OPENGL 1)
   950       set(SDL_VIDEO_OPENGL_CGL 1)
   951       set(SDL_VIDEO_RENDER_OGL 1)
   952       if(DARWIN)
   953         find_library(OpenGL_LIBRARY OpenGL)
   954         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
   955       endif(DARWIN)
   956       set(HAVE_VIDEO_OPENGL TRUE)
   957     endif(VIDEO_OPENGL)
   958   endif(SDL_VIDEO)
   959 
   960   CheckPTHREAD()
   961 elseif(BEOS)
   962   if(SDL_VIDEO)
   963     set(SDL_VIDEO_DRIVER_BWINDOW 1)
   964     file(GLOB BWINDOW_SOURCES ${SDL2_SOURCE_DIR}/src/video/bwindow/*.c)
   965     set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
   966     set(HAVE_SDL_VIDEO TRUE)
   967 
   968     if(VIDEO_OPENGL)
   969       # TODO: Use FIND_PACKAGE(OpenGL) instead
   970       set(SDL_VIDEO_OPENGL 1)
   971       set(SDL_VIDEO_OPENGL_BGL 1)
   972       set(SDL_VIDEO_RENDER_OGL 1)
   973       list(APPEND EXTRA_LIBS GL)
   974       set(HAVE_VIDEO_OPENGL TRUE)
   975     endif(VIDEO_OPENGL)
   976   endif(SDL_VIDEO)
   977 endif()
   978 
   979 # Dummies
   980 # configure.in does it differently:
   981 # if not have X
   982 #   if enable_X {  SDL_X_DISABLED = 1 }
   983 #   [add dummy sources]
   984 # so it always adds a dummy, without checking, if it was actually requested.
   985 # This leads to missing internal references on building, since the
   986 # src/X/*.c does not get included.
   987 if(NOT HAVE_SDL_JOYSTICK)
   988   set(SDL_JOYSTICK_DISABLED 1)
   989   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
   990 
   991     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
   992     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   993   endif()
   994 endif(NOT HAVE_SDL_JOYSTICK)
   995 if(NOT HAVE_SDL_HAPTIC)
   996   set(SDL_HAPTIC_DISABLED 1)
   997   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
   998   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   999 endif(NOT HAVE_SDL_HAPTIC)
  1000 if(NOT HAVE_SDL_LOADSO)
  1001   set(SDL_LOADSO_DISABLED 1)
  1002   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1003   set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1004 endif(NOT HAVE_SDL_LOADSO)
  1005 
  1006 # We always need to have threads and timers around
  1007 if(NOT HAVE_SDL_THREADS)
  1008   set(SDL_THREADS_DISABLED 1)
  1009   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1010   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1011 endif(NOT HAVE_SDL_THREADS)
  1012 if(NOT HAVE_SDL_TIMERS)
  1013   set(SDL_TIMERS_DISABLED 1)
  1014   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1015   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1016 endif(NOT HAVE_SDL_TIMERS)
  1017 
  1018 if(NOT SDLMAIN_SOURCES)
  1019   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1020 endif(NOT SDLMAIN_SOURCES)
  1021 
  1022 # Append the -MMD -MT flags
  1023 # if(DEPENDENCY_TRACKING)
  1024 #   if(COMPILER_IS_GNUCC)
  1025 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1026 #   endif(COMPILER_IS_GNUCC)
  1027 # endif(DEPENDENCY_TRACKING)
  1028 
  1029 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1030   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1031 
  1032 # Prepare the flags and remove duplicates
  1033 if(EXTRA_LDFLAGS)
  1034   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1035 endif(EXTRA_LDFLAGS)
  1036 if(EXTRA_LIBS)
  1037   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1038 endif(EXTRA_LIBS)
  1039 if(EXTRA_CFLAGS)
  1040   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1041 endif(EXTRA_CFLAGS)
  1042 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1043 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1044 
  1045 # Compat helpers for the configuration files
  1046 if(NOT WINDOWS OR CYGWIN)
  1047   # TODO: we need a Windows script, too
  1048   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1049 
  1050   set(prefix ${CMAKE_INSTALL_PREFIX})
  1051   set(exec_prefix "\${prefix}")
  1052   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1053   set(bindir "\${exec_prefix}/bin")
  1054   set(includedir "\${prefix}/include")
  1055   if(SDL_STATIC)
  1056     set(ENABLE_STATIC_TRUE "")
  1057     set(ENABLE_STATIC_FALSE "#")
  1058   else(SDL_STATIC)
  1059     set(ENABLE_STATIC_TRUE "#")
  1060     set(ENABLE_STATIC_FALSE "")
  1061   endif(SDL_STATIC)
  1062   if(SDL_SHARED)
  1063     set(ENABLE_SHARED_TRUE "")
  1064     set(ENABLE_SHARED_FALSE "#")
  1065   else(SDL_SHARED)
  1066     set(ENABLE_SHARED_TRUE "#")
  1067     set(ENABLE_SHARED_FALSE "")
  1068   endif(SDL_SHARED)
  1069 
  1070   # Clean up the different lists
  1071   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1072   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1073   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1074   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1075   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1076   listtostr(SDL_LIBS _SDL_LIBS)
  1077   set(SDL_LIBS ${_SDL_LIBS})
  1078 
  1079   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1080   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1081 
  1082   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1083     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1084   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1085     "${SDL2_BINARY_DIR}/sdl2-config")
  1086   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1087     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1088   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1089     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1090 endif(NOT WINDOWS OR CYGWIN)
  1091 
  1092 ##### Info output #####
  1093 message(STATUS "")
  1094 message(STATUS "SDL2 was configured with the following options:")
  1095 message(STATUS "")
  1096 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1097 message(STATUS "64-bit:   ${ARCH_64}")
  1098 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1099 message(STATUS "")
  1100 message(STATUS "Subsystems:")
  1101 foreach(_SUB ${SDL_SUBSYSTEMS})
  1102   string(TOUPPER ${_SUB} _OPT)
  1103   message_bool_option(${_SUB} SDL_${_OPT})
  1104 endforeach()
  1105 message(STATUS "")
  1106 message(STATUS "Options:")
  1107 list(SORT ALLOPTIONS)
  1108 foreach(_OPT ${ALLOPTIONS})
  1109   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1110   # Get the padding
  1111   string(LENGTH ${_OPT} _OPTLEN)
  1112   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1113   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1114   message_tested_option(${_OPT} ${_PADDING})
  1115 endforeach()
  1116 message(STATUS "")
  1117 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1118 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1119 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1120 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1121 message(STATUS "")
  1122 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1123 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1124 message(STATUS "")
  1125 if(UNIX)
  1126   message(STATUS "Something was not detected, although your are sure that it")
  1127   message(STATUS "has been properly installed? Then make sure, you have set")
  1128   message(STATUS "the CFLAGS and LDFLAGS environment variables correctly.")
  1129   message(STATUS "")
  1130 endif(UNIX)
  1131 
  1132 # Ensure that the extra cflags are used at compile time
  1133 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1134 
  1135 # Always build SDLmain
  1136 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1137 set(_INSTALL_LIBS "SDL2main")
  1138 
  1139 if(SDL_SHARED)
  1140   add_library(SDL2 SHARED ${SOURCE_FILES})
  1141   set_target_properties(SDL2 PROPERTIES
  1142     VERSION ${SDL_VERSION}
  1143     SOVERSION ${LT_CURRENT})
  1144  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1145  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1146 endif(SDL_SHARED)
  1147 
  1148 if(SDL_STATIC)
  1149   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1150   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1151   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1152   # libraries - do we need to consider this?
  1153   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1154   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1155 endif(SDL_STATIC)
  1156 
  1157 ##### Installation targets #####
  1158 install(TARGETS ${_INSTALL_LIBS}
  1159   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1160   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1161 
  1162 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1163 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1164 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1165   get_filename_component(_INCNAME ${_FNAME} NAME)
  1166   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1167 endforeach()
  1168 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1169 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1170 
  1171 if(NOT WINDOWS OR CYGWIN)
  1172   if(FREEBSD)
  1173     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1174     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1175   else(FREEBSD)
  1176     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1177       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1178   endif(FREEBSD)
  1179   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1180   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1181 endif(NOT WINDOWS OR CYGWIN)