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