CMakeLists.txt
author Sam Lantinga
Sat, 01 Oct 2016 15:11:18 -0700
changeset 10447 2e197b249d68
parent 10424 543367861d69
child 10458 b24c67bbb02f
permissions -rw-r--r--
Fixed bug 3078 - cmake: fix sdl2.m4 install location on cross hosts

Timo Gurr

On cross hosts running autotools for SDL2_gfx-1.0.1 fails to find sdl2.m4:

eautoreconf: running in /var/tmp/paludis/build/media-libs-SDL2_gfx-1.0.1/work/SDL2_gfx-1.0.1 ...
aclocal
aclocal-1.13: warning: autoconf input should be named 'configure.ac', not 'configure.in'
configure.in:128: warning: macro 'AM_PATH_SDL2' not found in library
libtoolize --copy --force --automake
aclocal
aclocal-1.13: warning: autoconf input should be named 'configure.ac', not 'configure.in'
configure.in:128: warning: macro 'AM_PATH_SDL2' not found in library
autoconf
configure.in:128: error: possibly undefined macro: AM_PATH_SDL2
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
* Failed Running autoconf !

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