CMakeLists.txt
author Alex Szpakowski <slime73@gmail.com>
Thu, 31 Dec 2015 15:26:40 -0400
changeset 9994 d3e4f7b44d4d
parent 9982 9145e51b15bb
child 10004 8f2f519d1e61
permissions -rwxr-xr-x
CMake: Fixed building for Windows with VS2015 (bug #3080).

- Don't try to link with the Visual C runtime.

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