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