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