CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Tue, 11 Dec 2012 11:07:48 -0500
changeset 6729 fdaeea9e7567
parent 6674 45a21e50ba5e
child 6734 7fdaee2be782
permissions -rw-r--r--
Removed old Linux joystick API (/dev/js*).

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