CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Wed, 24 May 2017 19:56:59 -0400
changeset 11028 25cd7fe50180
parent 10907 e64cf9261cc7
child 11070 61401688628e
permissions -rw-r--r--
audio: rename bsd target to netbsd.

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