CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Mon, 10 Mar 2014 00:48:41 -0400
changeset 8589 65d0979cdf08
parent 8303 7ee46ffa9c24
child 8591 2228ae5a3ac6
permissions -rw-r--r--
Removed unused variable.
     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" ${UNIX_SYS})
   239 set_option(VIDEO_MIR           "Use Mir video driver" ${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(ddraw.h HAVE_DDRAW_H)
   803     check_include_file(dsound.h HAVE_DSOUND_H)
   804     check_include_file(dinput.h HAVE_DINPUT_H)
   805     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
   806     if(HAVE_D3D_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
   807       set(HAVE_DIRECTX TRUE)
   808       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   809       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   810       include_directories($ENV{DXSDK_DIR}\\Include)
   811     endif()
   812     set(CMAKE_REQUIRED_FLAGS)
   813   endif()
   814 
   815   if(SDL_AUDIO)
   816     set(SDL_AUDIO_DRIVER_WINMM 1)
   817     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   818     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
   819     set(HAVE_SDL_AUDIO TRUE)
   820 
   821     if(HAVE_DSOUND_H)
   822       set(SDL_AUDIO_DRIVER_DSOUND 1)
   823       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
   824       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
   825     endif()
   826 
   827     if(HAVE_XAUDIO2_H)
   828       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
   829       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
   830       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
   831     endif()
   832   endif()
   833 
   834   if(SDL_VIDEO)
   835     # requires SDL_LOADSO on Windows (IME, DX, etc.)
   836     if(NOT SDL_LOADSO)
   837       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
   838     endif()
   839     set(SDL_VIDEO_DRIVER_WINDOWS 1)
   840     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
   841     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
   842 
   843     if(RENDER_D3D AND HAVE_D3D_H)
   844       set(SDL_VIDEO_RENDER_D3D 1)
   845       set(HAVE_RENDER_D3D TRUE)
   846     endif()
   847     set(HAVE_SDL_VIDEO TRUE)
   848   endif()
   849 
   850   if(SDL_THREADS)
   851     set(SDL_THREAD_WINDOWS 1)
   852     set(SOURCE_FILES ${SOURCE_FILES}
   853       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
   854       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
   855       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
   856       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systls.c
   857       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   858     set(HAVE_SDL_THREADS TRUE)
   859   endif()
   860 
   861   if(SDL_POWER)
   862     set(SDL_POWER_WINDOWS 1)
   863     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   864     set(HAVE_SDL_POWER TRUE)
   865   endif()
   866 
   867   if(SDL_FILESYSTEM)
   868     set(SDL_FILESYSTEM_WINDOWS 1)
   869     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/windows/*.c)
   870     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   871     set(HAVE_SDL_FILESYSTEM TRUE)
   872   endif()
   873 
   874   # Libraries for Win32 native and MinGW
   875   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   876 
   877   # TODO: in configure.in the check for timers is set on
   878   # cygwin | mingw32* - does this include mingw32CE?
   879   if(SDL_TIMERS)
   880     set(SDL_TIMER_WINDOWS 1)
   881     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   882     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   883     set(HAVE_SDL_TIMERS TRUE)
   884   endif()
   885 
   886   if(SDL_LOADSO)
   887     set(SDL_LOADSO_WINDOWS 1)
   888     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   889     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   890     set(HAVE_SDL_LOADSO TRUE)
   891   endif()
   892 
   893   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   894   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   895 
   896   if(SDL_VIDEO)
   897     if(VIDEO_OPENGL)
   898       set(SDL_VIDEO_OPENGL 1)
   899       set(SDL_VIDEO_OPENGL_WGL 1)
   900       set(SDL_VIDEO_RENDER_OGL 1)
   901       set(HAVE_VIDEO_OPENGL TRUE)
   902     endif()
   903   endif()
   904 
   905   if(SDL_JOYSTICK)
   906     if(HAVE_DINPUT_H)
   907       set(SDL_JOYSTICK_DINPUT 1)
   908       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_dxjoystick.c)
   909       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
   910     else()
   911       set(SDL_JOYSTICK_WINMM 1)
   912       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_mmjoystick.c)
   913     endif()
   914     set(HAVE_SDL_JOYSTICK TRUE)
   915   endif()
   916 
   917   if(SDL_HAPTIC AND HAVE_DINPUT_H)
   918     set(SDL_HAPTIC_DINPUT 1)
   919     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/haptic/windows/SDL_syshaptic.c)
   920     set(HAVE_SDL_HAPTIC TRUE)
   921   endif()
   922 
   923   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
   924   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
   925   if(MINGW OR CYGWIN)
   926     list(APPEND EXTRA_LIBS mingw32)
   927     list(APPEND EXTRA_LDFLAGS "-mwindows")
   928     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
   929     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
   930   endif()
   931 elseif(APPLE)
   932   # TODO: rework this for proper MacOS X, iOS and Darwin support
   933 
   934   # Requires the darwin file implementation
   935   if(SDL_FILE)
   936     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
   937     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
   938     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
   939     set(HAVE_SDL_FILE TRUE)
   940     set(SDL_FRAMEWORK_COCOA 1)
   941   else()
   942     message_error("SDL_FILE must be enabled to build on MacOS X")
   943   endif()
   944 
   945   if(SDL_AUDIO)
   946     set(MACOSX_COREAUDIO 1)
   947     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
   948     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
   949     set(HAVE_SDL_AUDIO TRUE)
   950     set(SDL_FRAMEWORK_COREAUDIO 1)
   951     set(SDL_FRAMEWORK_AUDIOUNIT 1)
   952   endif()
   953 
   954   if(SDL_JOYSTICK)
   955     set(SDL_JOYSTICK_IOKIT 1)
   956     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
   957     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   958     set(HAVE_SDL_JOYSTICK TRUE)
   959     set(SDL_FRAMEWORK_IOKIT 1)
   960     set(SDL_FRAMEWORK_FF 1)
   961   endif()
   962 
   963   if(SDL_HAPTIC)
   964     set(SDL_HAPTIC_IOKIT 1)
   965     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
   966     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   967     set(HAVE_SDL_HAPTIC TRUE)
   968     set(SDL_FRAMEWORK_IOKIT 1)
   969     set(SDL_FRAMEWORK_FF 1)
   970     if(NOT SDL_JOYSTICK)
   971       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
   972     endif()
   973   endif()
   974 
   975   if(SDL_POWER)
   976     set(SDL_POWER_MACOSX 1)
   977     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
   978     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   979     set(HAVE_SDL_POWER TRUE)
   980     set(SDL_FRAMEWORK_CARBON 1)
   981     set(SDL_FRAMEWORK_IOKIT 1)
   982   endif()
   983 
   984   if(SDL_TIMERS)
   985     set(SDL_TIMER_UNIX 1)
   986     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   987     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   988     set(HAVE_SDL_TIMERS TRUE)
   989   endif(SDL_TIMERS)
   990 
   991   if(SDL_FILESYSTEM)
   992     set(SDL_FILESYSTEM_COCOA 1)
   993     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/cocoa/*.m)
   994     set_source_files_properties(${FILESYSTEM_SOURCES} PROPERTIES LANGUAGE C)
   995     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
   996     set(HAVE_SDL_FILESYSTEM TRUE)
   997   endif()
   998 
   999   # Actually load the frameworks at the end so we don't duplicate include.
  1000   if(SDL_FRAMEWORK_COCOA)
  1001     find_library(COCOA_LIBRARY Cocoa)
  1002     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
  1003   endif()
  1004   if(SDL_FRAMEWORK_IOKIT)
  1005     find_library(IOKIT IOKit)
  1006     list(APPEND EXTRA_LIBS ${IOKIT})
  1007   endif()
  1008   if(SDL_FRAMEWORK_FF)
  1009     find_library(FORCEFEEDBACK ForceFeedback)
  1010     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
  1011   endif()
  1012   if(SDL_FRAMEWORK_CARBON)
  1013     find_library(CARBON_LIBRARY Carbon)
  1014     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
  1015   endif()
  1016   if(SDL_FRAMEWORK_COREAUDIO)
  1017     find_library(COREAUDIO CoreAudio)
  1018     list(APPEND EXTRA_LIBS ${COREAUDIO})
  1019   endif()
  1020   if(SDL_FRAMEWORK_AUDIOUNIT)
  1021     find_library(AUDIOUNIT AudioUnit)
  1022     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
  1023   endif()
  1024 
  1025   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
  1026   if(SDL_VIDEO)
  1027     CheckCOCOA()
  1028     if(VIDEO_OPENGL)
  1029       set(SDL_VIDEO_OPENGL 1)
  1030       set(SDL_VIDEO_OPENGL_CGL 1)
  1031       set(SDL_VIDEO_RENDER_OGL 1)
  1032       if(DARWIN)
  1033         find_library(OpenGL_LIBRARY OpenGL)
  1034         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
  1035       endif()
  1036       set(HAVE_VIDEO_OPENGL TRUE)
  1037     endif()
  1038   endif()
  1039 
  1040   CheckPTHREAD()
  1041 elseif(HAIKU)
  1042   if(SDL_VIDEO)
  1043     set(SDL_VIDEO_DRIVER_HAIKU 1)
  1044     file(GLOB HAIKUVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/haiku/*.c)
  1045     set(SOURCE_FILES ${SOURCE_FILES} ${HAIKUVIDEO_SOURCES})
  1046     set(HAVE_SDL_VIDEO TRUE)
  1047 
  1048     set(SDL_FILESYSTEM_HAIKU 1)
  1049     file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/haiku/*.cc)
  1050     set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1051     set(HAVE_SDL_FILESYSTEM TRUE)
  1052 
  1053     if(SDL_TIMERS)
  1054       set(SDL_TIMER_HAIKU 1)
  1055       file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/haiku/*.c)
  1056       set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1057       set(HAVE_SDL_TIMERS TRUE)
  1058     endif(SDL_TIMERS)
  1059 
  1060     if(VIDEO_OPENGL)
  1061       # TODO: Use FIND_PACKAGE(OpenGL) instead
  1062       set(SDL_VIDEO_OPENGL 1)
  1063       set(SDL_VIDEO_OPENGL_BGL 1)
  1064       set(SDL_VIDEO_RENDER_OGL 1)
  1065       list(APPEND EXTRA_LIBS GL)
  1066       set(HAVE_VIDEO_OPENGL TRUE)
  1067     endif()
  1068   endif()
  1069 
  1070   CheckPTHREAD()
  1071 endif()
  1072 
  1073 # Dummies
  1074 # configure.in does it differently:
  1075 # if not have X
  1076 #   if enable_X {  SDL_X_DISABLED = 1 }
  1077 #   [add dummy sources]
  1078 # so it always adds a dummy, without checking, if it was actually requested.
  1079 # This leads to missing internal references on building, since the
  1080 # src/X/*.c does not get included.
  1081 if(NOT HAVE_SDL_JOYSTICK)
  1082   set(SDL_JOYSTICK_DISABLED 1)
  1083   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
  1084 
  1085     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
  1086     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1087   endif()
  1088 endif()
  1089 if(NOT HAVE_SDL_HAPTIC)
  1090   set(SDL_HAPTIC_DISABLED 1)
  1091   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
  1092   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
  1093 endif()
  1094 if(NOT HAVE_SDL_LOADSO)
  1095   set(SDL_LOADSO_DISABLED 1)
  1096   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1097   set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
  1098 endif()
  1099 if(NOT HAVE_SDL_FILESYSTEM)
  1100   set(SDL_FILESYSTEM_DISABLED 1)
  1101   file(GLOB FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/dummy/*.c)
  1102   set(SOURCE_FILES ${SOURCE_FILES} ${FILESYSTEM_SOURCES})
  1103 endif()
  1104 
  1105 # We always need to have threads and timers around
  1106 if(NOT HAVE_SDL_THREADS)
  1107   set(SDL_THREADS_DISABLED 1)
  1108   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1109   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1110 endif()
  1111 if(NOT HAVE_SDL_TIMERS)
  1112   set(SDL_TIMERS_DISABLED 1)
  1113   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1114   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1115 endif()
  1116 
  1117 if(NOT SDLMAIN_SOURCES)
  1118   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1119 endif()
  1120 
  1121 # Append the -MMD -MT flags
  1122 # if(DEPENDENCY_TRACKING)
  1123 #   if(COMPILER_IS_GNUCC)
  1124 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1125 #   endif()
  1126 # endif()
  1127 
  1128 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1129   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1130 
  1131 # Prepare the flags and remove duplicates
  1132 if(EXTRA_LDFLAGS)
  1133   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1134 endif()
  1135 if(EXTRA_LIBS)
  1136   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1137 endif()
  1138 if(EXTRA_CFLAGS)
  1139   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1140 endif()
  1141 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1142 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1143 
  1144 # Compat helpers for the configuration files
  1145 if(NOT WINDOWS OR CYGWIN)
  1146   # TODO: we need a Windows script, too
  1147   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1148 
  1149   set(prefix ${CMAKE_INSTALL_PREFIX})
  1150   set(exec_prefix "\${prefix}")
  1151   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1152   set(bindir "\${exec_prefix}/bin")
  1153   set(includedir "\${prefix}/include")
  1154   if(SDL_STATIC)
  1155     set(ENABLE_STATIC_TRUE "")
  1156     set(ENABLE_STATIC_FALSE "#")
  1157   else(SDL_STATIC)
  1158     set(ENABLE_STATIC_TRUE "#")
  1159     set(ENABLE_STATIC_FALSE "")
  1160   endif()
  1161   if(SDL_SHARED)
  1162     set(ENABLE_SHARED_TRUE "")
  1163     set(ENABLE_SHARED_FALSE "#")
  1164   else(SDL_SHARED)
  1165     set(ENABLE_SHARED_TRUE "#")
  1166     set(ENABLE_SHARED_FALSE "")
  1167   endif()
  1168 
  1169   # Clean up the different lists
  1170   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1171   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1172   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1173   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1174   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1175   listtostr(SDL_LIBS _SDL_LIBS)
  1176   set(SDL_LIBS ${_SDL_LIBS})
  1177 
  1178   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1179   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1180 
  1181   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1182     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1183   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1184     "${SDL2_BINARY_DIR}/sdl2-config")
  1185   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1186     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1187   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1188     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1189 endif()
  1190 
  1191 ##### Info output #####
  1192 message(STATUS "")
  1193 message(STATUS "SDL2 was configured with the following options:")
  1194 message(STATUS "")
  1195 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1196 message(STATUS "64-bit:   ${ARCH_64}")
  1197 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1198 message(STATUS "")
  1199 message(STATUS "Subsystems:")
  1200 foreach(_SUB ${SDL_SUBSYSTEMS})
  1201   string(TOUPPER ${_SUB} _OPT)
  1202   message_bool_option(${_SUB} SDL_${_OPT})
  1203 endforeach()
  1204 message(STATUS "")
  1205 message(STATUS "Options:")
  1206 list(SORT ALLOPTIONS)
  1207 foreach(_OPT ${ALLOPTIONS})
  1208   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1209   # Get the padding
  1210   string(LENGTH ${_OPT} _OPTLEN)
  1211   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1212   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1213   message_tested_option(${_OPT} ${_PADDING})
  1214 endforeach()
  1215 message(STATUS "")
  1216 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1217 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1218 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1219 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1220 message(STATUS "")
  1221 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1222 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1223 message(STATUS "")
  1224 if(UNIX)
  1225   message(STATUS "If something was not detected, although the libraries")
  1226   message(STATUS "were installed, then make sure you have set the")
  1227   message(STATUS "CFLAGS and LDFLAGS environment variables correctly.")
  1228   message(STATUS "")
  1229 endif()
  1230 
  1231 # Ensure that the extra cflags are used at compile time
  1232 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1233 
  1234 # Always build SDLmain
  1235 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1236 set(_INSTALL_LIBS "SDL2main")
  1237 
  1238 if(SDL_SHARED)
  1239   add_library(SDL2 SHARED ${SOURCE_FILES})
  1240   if(UNIX)
  1241     set_target_properties(SDL2 PROPERTIES
  1242       VERSION ${LT_VERSION}
  1243       SOVERSION ${LT_REVISION}
  1244       OUTPUT_NAME "SDL2-${LT_RELEASE}")
  1245   else(UNIX)
  1246     set_target_properties(SDL2 PROPERTIES
  1247       VERSION ${SDL_VERSION}
  1248       SOVERSION ${LT_REVISION}
  1249       OUTPUT_NAME "SDL2")
  1250   endif()
  1251  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1252  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1253 endif()
  1254 
  1255 if(SDL_STATIC)
  1256   set (BUILD_SHARED_LIBS FALSE)
  1257   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1258   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1259   if(MSVC)
  1260     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
  1261     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
  1262     set_target_properties(SDL2-static PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
  1263   endif()
  1264   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1265   # libraries - do we need to consider this?
  1266   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1267   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1268 endif()
  1269 
  1270 ##### Installation targets #####
  1271 install(TARGETS ${_INSTALL_LIBS}
  1272   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1273   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1274 
  1275 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1276 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1277 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1278   get_filename_component(_INCNAME ${_FNAME} NAME)
  1279   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1280 endforeach()
  1281 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1282 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1283 
  1284 if(NOT WINDOWS OR CYGWIN)
  1285   if(SDL_SHARED)
  1286     install(CODE "
  1287       execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  1288       \"libSDL2-2.0.so\" \"libSDL2.so\")")
  1289     install(FILES ${SDL2_BINARY_DIR}/libSDL2.so DESTINATION "lib${LIB_SUFFIX}")
  1290   endif()
  1291   if(FREEBSD)
  1292     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1293     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1294   else(FREEBSD)
  1295     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1296       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1297   endif()
  1298   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1299   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1300   install(FILES "${SDL2_SOURCE_DIR}/sdl2.m4" DESTINATION "share/aclocal")
  1301 else()
  1302   install(TARGETS SDL2 RUNTIME DESTINATION bin)
  1303 endif()
  1304