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