CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Mon, 03 Feb 2014 11:59:17 -0500
changeset 8161 6c5d35c8b3dd
parent 8153 3e43c73ac79b
child 8194 aada7c5bd410
permissions -rw-r--r--
Temporarily default Wayland and Mir to disabled, for 2.0.2 release.

We'll flip the default back to enabled right after 2.0.2 is finalized, and
try to declare them stable and ready by 2.0.3.

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