CMakeLists.txt
author Gabriel Jacobo <gabomdq@gmail.com>
Tue, 13 May 2014 19:42:40 -0300
changeset 8774 3e2b3019a879
parent 8751 e8c61640668d
child 8842 f587255157cf
permissions -rw-r--r--
Fixes #2541, build failure with Wayland enabled, OpenGL ES disabled

Also includes an attempt at fixing building SDL on Ubuntu 13.10, which hopefully
won't break 14.04
     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 endif()
   338 
   339 if(ASSEMBLY)
   340   if(USE_GCC OR USE_CLANG)
   341     set(SDL_ASSEMBLY_ROUTINES 1)
   342     # TODO: Those all seem to be quite GCC specific - needs to be
   343     # reworked for better compiler support
   344     set(HAVE_ASSEMBLY TRUE)
   345     if(MMX)
   346       set(CMAKE_REQUIRED_FLAGS "-mmmx")
   347       check_c_source_compiles("
   348           #ifdef __MINGW32__
   349           #include <_mingw.h>
   350           #ifdef __MINGW64_VERSION_MAJOR
   351           #include <intrin.h>
   352           #else
   353           #include <mmintrin.h>
   354           #endif
   355           #else
   356           #include <mmintrin.h>
   357           #endif
   358           #ifndef __MMX__
   359           #error Assembler CPP flag not enabled
   360           #endif
   361           int main(int argc, char **argv) { }" HAVE_MMX)
   362       if(HAVE_MMX)
   363         list(APPEND EXTRA_CFLAGS "-mmmx")
   364       endif()
   365       set(CMAKE_REQUIRED_FLAGS)
   366     endif()
   367 
   368     if(3DNOW)
   369       set(CMAKE_REQUIRED_FLAGS "-m3dnow")
   370       check_c_source_compiles("
   371           #include <mm3dnow.h>
   372           #ifndef __3dNOW__
   373           #error Assembler CPP flag not enabled
   374           #endif
   375           int main(int argc, char **argv) {
   376             void *p = 0;
   377             _m_prefetch(p);
   378           }" HAVE_3DNOW)
   379       if(HAVE_3DNOW)
   380         list(APPEND EXTRA_CFLAGS "-m3dnow")
   381       endif()
   382       set(CMAKE_REQUIRED_FLAGS)
   383     endif()
   384 
   385     if(SSE)
   386       set(CMAKE_REQUIRED_FLAGS "-msse")
   387       check_c_source_compiles("
   388           #ifdef __MINGW32__
   389           #include <_mingw.h>
   390           #ifdef __MINGW64_VERSION_MAJOR
   391           #include <intrin.h>
   392           #else
   393           #include <xmmintrin.h>
   394           #endif
   395           #else
   396           #include <xmmintrin.h>
   397           #endif
   398           #ifndef __SSE__
   399           #error Assembler CPP flag not enabled
   400           #endif
   401           int main(int argc, char **argv) { }" HAVE_SSE)
   402       if(HAVE_SSE)
   403         list(APPEND EXTRA_CFLAGS "-msse")
   404       endif()
   405       set(CMAKE_REQUIRED_FLAGS)
   406     endif()
   407 
   408     if(SSE2)
   409       set(CMAKE_REQUIRED_FLAGS "-msse2")
   410       check_c_source_compiles("
   411           #ifdef __MINGW32__
   412           #include <_mingw.h>
   413           #ifdef __MINGW64_VERSION_MAJOR
   414           #include <intrin.h>
   415           #else
   416           #include <emmintrin.h>
   417           #endif
   418           #else
   419           #include <emmintrin.h>
   420           #endif
   421           #ifndef __SSE2__
   422           #error Assembler CPP flag not enabled
   423           #endif
   424           int main(int argc, char **argv) { }" HAVE_SSE2)
   425       if(HAVE_SSE2)
   426         list(APPEND EXTRA_CFLAGS "-msse2")
   427       endif()
   428       set(CMAKE_REQUIRED_FLAGS)
   429     endif()
   430 
   431     if(SSEMATH)
   432       if(SSE OR SSE2)
   433         if(USE_GCC)
   434           list(APPEND EXTRA_CFLAGS "-mfpmath=387")
   435         endif()
   436         set(HAVE_SSEMATH TRUE)
   437       endif()
   438     endif()
   439 
   440     if(ALTIVEC)
   441       set(CMAKE_REQUIRED_FLAGS "-maltivec")
   442       check_c_source_compiles("
   443           #include <altivec.h>
   444           vector unsigned int vzero() {
   445               return vec_splat_u32(0);
   446           }
   447           int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
   448       check_c_source_compiles("
   449           vector unsigned int vzero() {
   450               return vec_splat_u32(0);
   451           }
   452           int main(int argc, char **argv) { }" HAVE_ALTIVEC)
   453       set(CMAKE_REQUIRED_FLAGS)
   454       if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
   455         set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
   456         list(APPEND EXTRA_CFLAGS "-maltivec")
   457         set(SDL_ALTIVEC_BLITTERS 1)
   458         if(HAVE_ALTIVEC_H_HDR)
   459           set(HAVE_ALTIVEC_H 1)
   460         endif()
   461       endif()
   462     endif()
   463   elseif(MSVC_VERSION GREATER 1500)
   464     # TODO: SDL_cpuinfo.h needs to support the user's configuration wish
   465     # for MSVC - right now it is always activated
   466     if(NOT ARCH_64)
   467       set(HAVE_MMX TRUE)
   468       set(HAVE_3DNOW TRUE)
   469     endif()
   470     set(HAVE_SSE TRUE)
   471     set(HAVE_SSE2 TRUE)
   472     set(SDL_ASSEMBLY_ROUTINES 1)
   473   endif()
   474 # TODO:
   475 #else(ASSEMBLY)
   476 #  if(USE_GCC OR USE_CLANG)
   477 #    list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-mmx")
   478 #  endif()
   479 endif()
   480 
   481 # TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define
   482 # anything.
   483 if(LIBC)
   484   if(WINDOWS AND NOT MINGW)
   485     set(HAVE_LIBC TRUE)
   486     foreach(_HEADER stdio.h string.h ctype.h math.h)
   487       string(TOUPPER "HAVE_${_HEADER}" _UPPER)
   488       string(REPLACE "." "_" _HAVE_H ${_UPPER})
   489       set(${_HAVE_H} 1)
   490     endforeach()
   491     set(HAVE_SIGNAL_H 1)
   492     foreach(_FN
   493             malloc calloc realloc free qsort abs memset memcpy memmove memcmp
   494             strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
   495             _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp
   496             _stricmp _strnicmp sscanf atan atan2 acos asin ceil copysign cos
   497             cosf fabs floor log pow scalbn sin sinf sqrt)
   498       string(TOUPPER ${_FN} _UPPER)
   499       set(HAVE_${_UPPER} 1)
   500     endforeach()
   501     if(NOT CYGWIN AND NOT MINGW)
   502       set(HAVE_ALLOCA 1)
   503     endif()
   504     set(HAVE_M_PI 1)
   505     add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
   506     set(STDC_HEADERS 1)
   507   else(WINDOWS AND NOT MINGW)
   508     set(HAVE_LIBC TRUE)
   509     check_include_file(sys/types.h HAVE_SYS_TYPES_H)
   510     foreach(_HEADER
   511             stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h
   512             strings.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h)
   513       string(TOUPPER "HAVE_${_HEADER}" _UPPER)
   514       string(REPLACE "." "_" _HAVE_H ${_UPPER})
   515       check_include_file("${_HEADER}" ${_HAVE_H})
   516     endforeach()
   517 
   518     check_include_files("dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" STDC_HEADERS)
   519     check_type_size("size_t" SIZEOF_SIZE_T)
   520     check_symbol_exists(M_PI math.h HAVE_M_PI)
   521     # TODO: refine the mprotect check
   522     check_c_source_compiles("#include <sys/types.h>
   523                              #include <sys/mman.h>
   524                              int main() { }" HAVE_MPROTECT)
   525     foreach(_FN
   526             strtod malloc calloc realloc free getenv setenv putenv unsetenv
   527             qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
   528             strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa
   529             _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull
   530             atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp
   531             vsscanf vsnprintf fseeko fseeko64 sigaction setjmp
   532             nanosleep sysconf sysctlbyname
   533             )
   534       string(TOUPPER ${_FN} _UPPER)
   535       set(_HAVEVAR "HAVE_${_UPPER}")
   536       check_function_exists("${_FN}" ${_HAVEVAR})
   537     endforeach()
   538 
   539     check_library_exists(m pow "" HAVE_LIBM)
   540     if(HAVE_LIBM)
   541       set(CMAKE_REQUIRED_LIBRARIES m)
   542       foreach(_FN
   543               atan atan2 ceil copysign cos cosf fabs floor log pow scalbn sin
   544               sinf sqrt)
   545         string(TOUPPER ${_FN} _UPPER)
   546         set(_HAVEVAR "HAVE_${_UPPER}")
   547         check_function_exists("${_FN}" ${_HAVEVAR})
   548       endforeach()
   549       set(CMAKE_REQUIRED_LIBRARIES)
   550       list(APPEND EXTRA_LIBS m)
   551     endif()
   552 
   553     check_library_exists(iconv iconv_open "" HAVE_LIBICONV)
   554     if(HAVE_LIBICONV)
   555       list(APPEND EXTRA_LIBS iconv)
   556     endif()
   557 
   558     check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
   559   endif()
   560 else(LIBC)
   561   if(WINDOWS)
   562     set(HAVE_STDARG_H 1)
   563     set(HAVE_STDDEF_H 1)
   564   endif()
   565 endif()
   566 
   567 
   568 # Enable/disable various subsystems of the SDL library
   569 foreach(_SUB ${SDL_SUBSYSTEMS})
   570   string(TOUPPER ${_SUB} _OPT)
   571   if(NOT SDL_${_OPT})
   572     set(SDL_${_OPT}_DISABLED 1)
   573   endif()
   574 endforeach()
   575 if(SDL_JOYSTICK)
   576   file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/*.c)
   577   set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   578 endif()
   579 if(SDL_HAPTIC)
   580   if(NOT SDL_JOYSTICK)
   581     # Haptic requires some private functions from the joystick subsystem.
   582     message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled")
   583   endif()
   584   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/*.c)
   585   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   586 endif()
   587 if(SDL_POWER)
   588   file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/*.c)
   589   set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   590 endif()
   591 # TODO: in configure.in, the test for LOADSO and SDL_DLOPEN is a bit weird:
   592 # if LOADSO is not wanted, SDL_LOADSO_DISABLED is set
   593 # If however on Unix or APPLE dlopen() is detected via CheckDLOPEN(),
   594 # SDL_LOADSO_DISABLED will not be set, regardless of the LOADSO settings
   595 
   596 # General SDL subsystem options, valid for all platforms
   597 if(SDL_AUDIO)
   598   # CheckDummyAudio/CheckDiskAudio - valid for all platforms
   599   if(DUMMYAUDIO)
   600     set(SDL_AUDIO_DRIVER_DUMMY 1)
   601     file(GLOB DUMMYAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dummy/*.c)
   602     set(SOURCE_FILES ${SOURCE_FILES} ${DUMMYAUDIO_SOURCES})
   603     set(HAVE_DUMMYAUDIO TRUE)
   604   endif()
   605   if(DISKAUDIO)
   606     set(SDL_AUDIO_DRIVER_DISK 1)
   607     file(GLOB DISKAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/disk/*.c)
   608     set(SOURCE_FILES ${SOURCE_FILES} ${DISKAUDIO_SOURCES})
   609     set(HAVE_DISKAUDIO TRUE)
   610   endif()
   611 endif()
   612 
   613 if(SDL_DLOPEN)
   614   # Relevant for Unix/Darwin only
   615   if(UNIX OR APPLE)
   616     CheckDLOPEN()
   617   endif()
   618 endif()
   619 
   620 if(SDL_VIDEO)
   621   if(VIDEO_DUMMY)
   622     set(SDL_VIDEO_DRIVER_DUMMY 1)
   623     file(GLOB VIDEO_DUMMY_SOURCES ${SDL2_SOURCE_DIR}/src/video/dummy/*.c)
   624     set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_DUMMY_SOURCES})
   625     set(HAVE_VIDEO_DUMMY TRUE)
   626     set(HAVE_SDL_VIDEO TRUE)
   627   endif()
   628 endif()
   629 
   630 # Platform-specific options and settings
   631 if(UNIX AND NOT APPLE)
   632   if(SDL_AUDIO)
   633     if(SYSV5 OR SOLARIS OR HPUX)
   634         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   635         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
   636         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
   637         set(HAVE_SDL_AUDIO TRUE)
   638     elseif(NETBSD OR OPENBSD)
   639         set(SDL_AUDIO_DRIVER_BSD 1)
   640         file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
   641         set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
   642         set(HAVE_SDL_AUDIO TRUE)
   643     elseif(AIX)
   644         set(SDL_AUDIO_DRIVER_PAUDIO 1)
   645         file(GLOB AIX_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/paudio/*.c)
   646         set(SOURCE_FILES ${SOURCE_FILES} ${AIX_AUDIO_SOURCES})
   647         set(HAVE_SDL_AUDIO TRUE)
   648     endif()
   649     CheckOSS()
   650     CheckALSA()
   651     CheckPulseAudio()
   652     CheckESD()
   653     CheckARTS()
   654     CheckNAS()
   655     CheckSNDIO()
   656     CheckFusionSound()
   657   endif()
   658 
   659   if(SDL_VIDEO)
   660     CheckX11()
   661     CheckMir()
   662     CheckDirectFB()
   663     CheckOpenGLX11()
   664     CheckOpenGLESX11()
   665     CheckWayland()
   666   endif()
   667 
   668   if(LINUX)
   669     check_c_source_compiles("
   670         #include <linux/input.h>
   671         #ifndef EVIOCGNAME
   672         #error EVIOCGNAME() ioctl not available
   673         #endif
   674         int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
   675 
   676     check_c_source_compiles("
   677         #include <linux/kd.h>
   678         #include <linux/keyboard.h>
   679 
   680         int main(int argc, char **argv) 
   681         {
   682             struct kbentry kbe;
   683             kbe.kb_table = KG_CTRL;
   684             ioctl(0, KDGKBENT, &kbe);
   685         }" HAVE_INPUT_KD)
   686 
   687     file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/linux/*.c)
   688     set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   689 
   690     if(HAVE_INPUT_EVENTS)
   691       set(SDL_INPUT_LINUXEV 1)
   692     endif()
   693 
   694     if(SDL_HAPTIC AND HAVE_INPUT_EVENTS)
   695       set(SDL_HAPTIC_LINUX 1)
   696       file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/linux/*.c)
   697       set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   698       set(HAVE_SDL_HAPTIC TRUE)
   699     endif()
   700 
   701     if(HAVE_INPUT_KD)
   702       set(SDL_INPUT_LINUXKD 1)
   703     endif()
   704 
   705     check_include_file("libudev.h" HAVE_LIBUDEV_H)
   706 
   707     # !!! FIXME: this needs pkg-config to find the include path, I think.
   708     check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
   709   endif()
   710 
   711   if(INPUT_TSLIB)
   712     check_c_source_compiles("
   713         #include \"tslib.h\"
   714         int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
   715     if(HAVE_INPUT_TSLIB)
   716       set(SDL_INPUT_TSLIB 1)
   717       list(APPEND EXTRA_LIBS ts)
   718     endif()
   719   endif()
   720 
   721   if(SDL_JOYSTICK)
   722     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
   723     if(LINUX)
   724       set(SDL_JOYSTICK_LINUX 1)
   725       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
   726       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   727       set(HAVE_SDL_JOYSTICK TRUE)
   728     endif()
   729   endif()
   730 
   731   CheckPTHREAD()
   732 
   733   if(CLOCK_GETTIME)
   734     check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
   735     if(FOUND_CLOCK_GETTIME)
   736       list(APPEND EXTRA_LIBS rt)
   737       set(HAVE_CLOCK_GETTIME 1)
   738     else(FOUND_CLOCK_GETTIME)
   739       check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
   740       if(FOUND_CLOCK_GETTIME)
   741         set(HAVE_CLOCK_GETTIME 1)
   742       endif()
   743     endif()
   744   endif()
   745 
   746   check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
   747   if(HAVE_LINUX_VERSION_H)
   748     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   749   endif()
   750 
   751   if(SDL_POWER)
   752     if(LINUX)
   753       set(SDL_POWER_LINUX 1)
   754       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
   755       set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   756       set(HAVE_SDL_POWER TRUE)
   757     endif()
   758   endif()
   759 
   760   if(SDL_FILESYSTEM)
   761     set(SDL_FILESYSTEM_UNIX 1)
   762     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/unix/*.c)
   763     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   764     set(HAVE_SDL_FILESYSTEM TRUE)
   765   endif()
   766 
   767   if(SDL_TIMERS)
   768     set(SDL_TIMER_UNIX 1)
   769     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   770     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   771     set(HAVE_SDL_TIMERS TRUE)
   772   endif()
   773 
   774   if(RPATH)
   775     set(SDL_RLD_FLAGS "")
   776     if(BSDI OR FREEBSD OR LINUX OR NETBSD)
   777       set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
   778     elseif(SOLARIS)
   779       set(SDL_RLD_FLAGS "-R\${libdir}")
   780     endif()
   781     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
   782     set(HAVE_RPATH TRUE)
   783   endif()
   784 
   785 elseif(WINDOWS)
   786   find_program(WINDRES windres)
   787 
   788   check_c_source_compiles("
   789     #include <windows.h>
   790     int main(int argc, char **argv) { }" HAVE_WIN32_CC)
   791 
   792   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   793   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   794 
   795   # Check for DirectX
   796   if(DIRECTX)
   797     if("$ENV{DXSDK_DIR}" STREQUAL "")
   798       message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
   799     endif()
   800     set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
   801     check_include_file(d3d9.h HAVE_D3D_H)
   802     check_include_file(d3d11_1.h HAVE_D3D11_H)
   803     check_include_file(ddraw.h HAVE_DDRAW_H)
   804     check_include_file(dsound.h HAVE_DSOUND_H)
   805     check_include_file(dinput.h HAVE_DINPUT_H)
   806     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
   807     check_include_file(dxgi.h HAVE_DXGI_H)
   808     if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
   809       set(HAVE_DIRECTX TRUE)
   810       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   811       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   812       include_directories($ENV{DXSDK_DIR}\\Include)
   813     endif()
   814     set(CMAKE_REQUIRED_FLAGS)
   815   endif()
   816 
   817   if(SDL_AUDIO)
   818     set(SDL_AUDIO_DRIVER_WINMM 1)
   819     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   820     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
   821     set(HAVE_SDL_AUDIO TRUE)
   822 
   823     if(HAVE_DSOUND_H)
   824       set(SDL_AUDIO_DRIVER_DSOUND 1)
   825       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
   826       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
   827     endif()
   828 
   829     if(HAVE_XAUDIO2_H)
   830       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
   831       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
   832       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
   833     endif()
   834   endif()
   835 
   836   if(SDL_VIDEO)
   837     # requires SDL_LOADSO on Windows (IME, DX, etc.)
   838     if(NOT SDL_LOADSO)
   839       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
   840     endif()
   841     set(SDL_VIDEO_DRIVER_WINDOWS 1)
   842     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
   843     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
   844 
   845     if(RENDER_D3D AND HAVE_D3D_H)
   846       set(SDL_VIDEO_RENDER_D3D 1)
   847       set(HAVE_RENDER_D3D TRUE)
   848     endif()
   849     if(RENDER_D3D AND HAVE_D3D11_H)
   850       set(SDL_VIDEO_RENDER_D3D11 1)
   851       set(HAVE_RENDER_D3D TRUE)
   852     endif()
   853     set(HAVE_SDL_VIDEO TRUE)
   854   endif()
   855 
   856   if(SDL_THREADS)
   857     set(SDL_THREAD_WINDOWS 1)
   858     set(SOURCE_FILES ${SOURCE_FILES}
   859       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
   860       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
   861       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
   862       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
   863       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   864     set(HAVE_SDL_THREADS TRUE)
   865   endif()
   866 
   867   if(SDL_POWER)
   868     set(SDL_POWER_WINDOWS 1)
   869     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   870     set(HAVE_SDL_POWER TRUE)
   871   endif()
   872 
   873   if(SDL_FILESYSTEM)
   874     set(SDL_FILESYSTEM_WINDOWS 1)
   875     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
   876     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   877     set(HAVE_SDL_FILESYSTEM TRUE)
   878   endif()
   879 
   880   # Libraries for Win32 native and MinGW
   881   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   882 
   883   # TODO: in configure.in the check for timers is set on
   884   # cygwin | mingw32* - does this include mingw32CE?
   885   if(SDL_TIMERS)
   886     set(SDL_TIMER_WINDOWS 1)
   887     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   888     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   889     set(HAVE_SDL_TIMERS TRUE)
   890   endif()
   891 
   892   if(SDL_LOADSO)
   893     set(SDL_LOADSO_WINDOWS 1)
   894     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   895     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   896     set(HAVE_SDL_LOADSO TRUE)
   897   endif()
   898 
   899   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   900   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   901 
   902   if(SDL_VIDEO)
   903     if(VIDEO_OPENGL)
   904       set(SDL_VIDEO_OPENGL 1)
   905       set(SDL_VIDEO_OPENGL_WGL 1)
   906       set(SDL_VIDEO_RENDER_OGL 1)
   907       set(HAVE_VIDEO_OPENGL TRUE)
   908     endif()
   909   endif()
   910 
   911   if(SDL_JOYSTICK)
   912     if(HAVE_DINPUT_H)
   913       set(SDL_JOYSTICK_DINPUT 1)
   914       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_dxjoystick.c)
   915       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
   916     else()
   917       set(SDL_JOYSTICK_WINMM 1)
   918       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_mmjoystick.c)
   919     endif()
   920     set(HAVE_SDL_JOYSTICK TRUE)
   921   endif()
   922 
   923   if(SDL_HAPTIC AND HAVE_DINPUT_H)
   924     set(SDL_HAPTIC_DINPUT 1)
   925     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/haptic/windows/SDL_syshaptic.c)
   926     set(HAVE_SDL_HAPTIC TRUE)
   927   endif()
   928 
   929   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
   930   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
   931   if(MINGW OR CYGWIN)
   932     list(APPEND EXTRA_LIBS mingw32)
   933     list(APPEND EXTRA_LDFLAGS "-mwindows")
   934     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
   935     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
   936   endif()
   937 elseif(APPLE)
   938   # TODO: rework this for proper MacOS X, iOS and Darwin support
   939 
   940   # Requires the darwin file implementation
   941   if(SDL_FILE)
   942     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
   943     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
   944     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
   945     set(HAVE_SDL_FILE TRUE)
   946     set(SDL_FRAMEWORK_COCOA 1)
   947   else()
   948     message_error("SDL_FILE must be enabled to build on MacOS X")
   949   endif()
   950 
   951   if(SDL_AUDIO)
   952     set(MACOSX_COREAUDIO 1)
   953     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
   954     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
   955     set(HAVE_SDL_AUDIO TRUE)
   956     set(SDL_FRAMEWORK_COREAUDIO 1)
   957     set(SDL_FRAMEWORK_AUDIOUNIT 1)
   958   endif()
   959 
   960   if(SDL_JOYSTICK)
   961     set(SDL_JOYSTICK_IOKIT 1)
   962     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
   963     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   964     set(HAVE_SDL_JOYSTICK TRUE)
   965     set(SDL_FRAMEWORK_IOKIT 1)
   966     set(SDL_FRAMEWORK_FF 1)
   967   endif()
   968 
   969   if(SDL_HAPTIC)
   970     set(SDL_HAPTIC_IOKIT 1)
   971     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
   972     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   973     set(HAVE_SDL_HAPTIC TRUE)
   974     set(SDL_FRAMEWORK_IOKIT 1)
   975     set(SDL_FRAMEWORK_FF 1)
   976     if(NOT SDL_JOYSTICK)
   977       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
   978     endif()
   979   endif()
   980 
   981   if(SDL_POWER)
   982     set(SDL_POWER_MACOSX 1)
   983     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
   984     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   985     set(HAVE_SDL_POWER TRUE)
   986     set(SDL_FRAMEWORK_CARBON 1)
   987     set(SDL_FRAMEWORK_IOKIT 1)
   988   endif()
   989 
   990   if(SDL_TIMERS)
   991     set(SDL_TIMER_UNIX 1)
   992     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   993     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   994     set(HAVE_SDL_TIMERS TRUE)
   995   endif(SDL_TIMERS)
   996 
   997   if(SDL_FILESYSTEM)
   998     set(SDL_FILESYSTEM_COCOA 1)
   999     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
  1000     set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
  1001     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1002     set(HAVE_SDL_FILESYSTEM TRUE)
  1003   endif()
  1004 
  1005   # Actually load the frameworks at the end so we don't duplicate include.
  1006   if(SDL_FRAMEWORK_COCOA)
  1007     find_library(COCOA_LIBRARY Cocoa)
  1008     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  1009   endif()
  1010   if(SDL_FRAMEWORK_IOKIT)
  1011     find_library(IOKIT IOKit)
  1012     list(APPEND EXTRA_LIBS ${IOKIT})
  1013   endif()
  1014   if(SDL_FRAMEWORK_FF)
  1015     find_library(FORCEFEEDBACK ForceFeedback)
  1016     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  1017   endif()
  1018   if(SDL_FRAMEWORK_CARBON)
  1019     find_library(CARBON_LIBRARY Carbon)
  1020     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  1021   endif()
  1022   if(SDL_FRAMEWORK_COREAUDIO)
  1023     find_library(COREAUDIO CoreAudio)
  1024     list(APPEND EXTRA_LIBS ${COREAUDIO})
  1025   endif()
  1026   if(SDL_FRAMEWORK_AUDIOUNIT)
  1027     find_library(AUDIOUNIT AudioUnit)
  1028     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
  1029   endif()
  1030 
  1031   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1032   if(SDL_VIDEO)
  1033     CheckCOCOA()
  1034     if(VIDEO_OPENGL)
  1035       set(SDL_VIDEO_OPENGL 1)
  1036       set(SDL_VIDEO_OPENGL_CGL 1)
  1037       set(SDL_VIDEO_RENDER_OGL 1)
  1038       if(DARWIN)
  1039         find_library(OpenGL_LIBRARY OpenGL)
  1040         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
  1041       endif()
  1042       set(HAVE_VIDEO_OPENGL TRUE)
  1043     endif()
  1044   endif()
  1045 
  1046   CheckPTHREAD()
  1047 elseif(HAIKU)
  1048   if(SDL_VIDEO)
  1049     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1050     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1051     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1052     set(HAVE_SDL_VIDEO TRUE)
  1053 
  1054     set(SDL_FILESYSTEM_HAIKU 1)
  1055     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  1056     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1057     set(HAVE_SDL_FILESYSTEM TRUE)
  1058 
  1059     if(SDL_TIMERS)
  1060       set(SDL_TIMER_HAIKU 1)
  1061       file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  1062       set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1063       set(HAVE_SDL_TIMERS TRUE)
  1064     endif(SDL_TIMERS)
  1065 
  1066     if(VIDEO_OPENGL)
  1067       # TODO: Use FIND_PACKAGE(OpenGL) instead
  1068       set(SDL_VIDEO_OPENGL 1)
  1069       set(SDL_VIDEO_OPENGL_BGL 1)
  1070       set(SDL_VIDEO_RENDER_OGL 1)
  1071       list(APPEND EXTRA_LIBS GL)
  1072       set(HAVE_VIDEO_OPENGL TRUE)
  1073     endif()
  1074   endif()
  1075 
  1076   CheckPTHREAD()
  1077 endif()
  1078 
  1079 # Dummies
  1080 # configure.in does it differently:
  1081 # if not have X
  1082 #   if enable_X {  SDL_X_DISABLED = 1 }
  1083 #   [add dummy sources]
  1084 # so it always adds a dummy, without checking, if it was actually requested.
  1085 # This leads to missing internal references on building, since the
  1086 # src/X/*.c does not get included.
  1087 if(NOT HAVE_SDL_JOYSTICK)
  1088   set(SDL_JOYSTICK_DISABLED 1)
  1089   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1090 
  1091     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1092     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1093   endif()
  1094 endif()
  1095 if(NOT HAVE_SDL_HAPTIC)
  1096   set(SDL_HAPTIC_DISABLED 1)
  1097   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1098   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1099 endif()
  1100 if(NOT HAVE_SDL_LOADSO)
  1101   set(SDL_LOADSO_DISABLED 1)
  1102   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1103   set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1104 endif()
  1105 if(NOT HAVE_SDL_FILESYSTEM)
  1106   set(SDL_FILESYSTEM_DISABLED 1)
  1107   file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1108   set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1109 endif()
  1110 
  1111 # We always need to have threads and timers around
  1112 if(NOT HAVE_SDL_THREADS)
  1113   set(SDL_THREADS_DISABLED 1)
  1114   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1115   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1116 endif()
  1117 if(NOT HAVE_SDL_TIMERS)
  1118   set(SDL_TIMERS_DISABLED 1)
  1119   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1120   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1121 endif()
  1122 
  1123 if(NOT SDLMAIN_SOURCES)
  1124   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1125 endif()
  1126 
  1127 # Append the -MMD -MT flags
  1128 # if(DEPENDENCY_TRACKING)
  1129 #   if(COMPILER_IS_GNUCC)
  1130 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1131 #   endif()
  1132 # endif()
  1133 
  1134 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1135   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1136 
  1137 # Prepare the flags and remove duplicates
  1138 if(EXTRA_LDFLAGS)
  1139   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1140 endif()
  1141 if(EXTRA_LIBS)
  1142   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1143 endif()
  1144 if(EXTRA_CFLAGS)
  1145   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1146 endif()
  1147 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1148 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1149 
  1150 # Compat helpers for the configuration files
  1151 if(NOT WINDOWS OR CYGWIN)
  1152   # TODO: we need a Windows script, too
  1153   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1154 
  1155   set(prefix ${CMAKE_INSTALL_PREFIX})
  1156   set(exec_prefix "\${prefix}")
  1157   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1158   set(bindir "\${exec_prefix}/bin")
  1159   set(includedir "\${prefix}/include")
  1160   if(SDL_STATIC)
  1161     set(ENABLE_STATIC_TRUE "")
  1162     set(ENABLE_STATIC_FALSE "#")
  1163   else(SDL_STATIC)
  1164     set(ENABLE_STATIC_TRUE "#")
  1165     set(ENABLE_STATIC_FALSE "")
  1166   endif()
  1167   if(SDL_SHARED)
  1168     set(ENABLE_SHARED_TRUE "")
  1169     set(ENABLE_SHARED_FALSE "#")
  1170   else(SDL_SHARED)
  1171     set(ENABLE_SHARED_TRUE "#")
  1172     set(ENABLE_SHARED_FALSE "")
  1173   endif()
  1174 
  1175   # Clean up the different lists
  1176   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1177   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1178   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1179   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1180   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1181   listtostr(SDL_LIBS _SDL_LIBS)
  1182   set(SDL_LIBS ${_SDL_LIBS})
  1183 
  1184   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1185   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1186 
  1187   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1188     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1189   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1190     "${SDL2_BINARY_DIR}/sdl2-config")
  1191   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1192     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1193   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1194     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1195 endif()
  1196 
  1197 ##### Info output #####
  1198 message(STATUS "")
  1199 message(STATUS "SDL2 was configured with the following options:")
  1200 message(STATUS "")
  1201 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1202 message(STATUS "64-bit:   ${ARCH_64}")
  1203 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1204 message(STATUS "")
  1205 message(STATUS "Subsystems:")
  1206 foreach(_SUB ${SDL_SUBSYSTEMS})
  1207   string(TOUPPER ${_SUB} _OPT)
  1208   message_bool_option(${_SUB} SDL_${_OPT})
  1209 endforeach()
  1210 message(STATUS "")
  1211 message(STATUS "Options:")
  1212 list(SORT ALLOPTIONS)
  1213 foreach(_OPT ${ALLOPTIONS})
  1214   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1215   # Get the padding
  1216   string(LENGTH ${_OPT} _OPTLEN)
  1217   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1218   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1219   message_tested_option(${_OPT} ${_PADDING})
  1220 endforeach()
  1221 message(STATUS "")
  1222 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1223 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1224 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1225 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1226 message(STATUS "")
  1227 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1228 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1229 message(STATUS "")
  1230 if(UNIX)
  1231   message(STATUS "If something was not detected, although the libraries")
  1232   message(STATUS "were installed, then make sure you have set the")
  1233   message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  1234   message(STATUS "")
  1235 endif()
  1236 
  1237 # Ensure that the extra cflags are used at compile time
  1238 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1239 
  1240 # Always build SDLmain
  1241 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1242 set(_INSTALL_LIBS "SDL2main")
  1243 
  1244 if(SDL_SHARED)
  1245   add_library(SDL2 SHARED ${SOURCE_FILES})
  1246   if(UNIX)
  1247     set_target_properties(SDL2 PROPERTIES
  1248       VERSION ${LT_VERSION}
  1249       SOVERSION ${LT_REVISION}
  1250       OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1251   else(UNIX)
  1252     set_target_properties(SDL2 PROPERTIES
  1253       VERSION ${SDL_VERSION}
  1254       SOVERSION ${LT_REVISION}
  1255       OUTPUT_NAME "SDL2")
  1256   endif()
  1257  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1258  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1259 endif()
  1260 
  1261 if(SDL_STATIC)
  1262   set (BUILD_SHARED_LIBS FALSE)
  1263   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1264   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1265   if(MSVC)
  1266     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1267     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1268     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1269   endif()
  1270   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1271   # libraries - do we need to consider this?
  1272   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1273   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1274 endif()
  1275 
  1276 ##### Installation targets #####
  1277 install(TARGETS ${_INSTALL_LIBS}
  1278   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1279   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1280 
  1281 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1282 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1283 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1284   get_filename_component(_INCNAME ${_FNAME} NAME)
  1285   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1286 endforeach()
  1287 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1288 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1289 
  1290 if(NOT WINDOWS OR CYGWIN)
  1291   if(SDL_SHARED)
  1292     install(CODE "
  1293       execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1294       \"libSDL2-2.0.so\" \"libSDL2.so\")")
  1295     install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
  1296   endif()
  1297   if(FREEBSD)
  1298     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1299     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1300   else(FREEBSD)
  1301     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1302       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1303   endif()
  1304   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1305   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1306   install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "share/aclocal")
  1307 else()
  1308   install(TARGETS SDL2 RUNTIME DESTINATION bin)
  1309 endif()
  1310