CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Mon, 04 Jan 2016 22:58:38 -0500
changeset 10009 8c6b05b0a27e
parent 10004 8f2f519d1e61
child 10012 ed02c7a84612
permissions -rwxr-xr-x
Try to build with GCC's -Wdeclaration-after-statement.

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