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