CMakeLists.txt
author Sam Lantinga <slouken@libsdl.org>
Sun, 26 May 2013 13:06:54 -0700
changeset 7229 2636ad0a52e4
parent 6774 ad8522052ce6
child 7367 d6eabafa8776
permissions -rw-r--r--
Updated VisualC.html for SDL 2.0
     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 
   652     check_include_file("libudev.h" HAVE_LIBUDEV_H)
   653 
   654     # !!! FIXME: this needs pkg-config to find the include path, I think.
   655     check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
   656   endif(LINUX)
   657 
   658   if(INPUT_TSLIB)
   659     check_c_source_compiles("
   660         #include \"tslib.h\"
   661         int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
   662     if(HAVE_INPUT_TSLIB)
   663       set(SDL_INPUT_TSLIB 1)
   664       list(APPEND EXTRA_LIBS ts)
   665     endif(HAVE_INPUT_TSLIB)
   666   endif(INPUT_TSLIB)
   667 
   668   if(SDL_JOYSTICK)
   669     CheckUSBHID()   # seems to be BSD specific - limit the test to BSD only?
   670     if(LINUX)
   671       set(SDL_JOYSTICK_LINUX 1)
   672       file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c)
   673       set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   674       set(HAVE_SDL_JOYSTICK TRUE)
   675     endif(LINUX)
   676   endif(SDL_JOYSTICK)
   677 
   678   CheckPTHREAD()
   679 
   680   if(CLOCK_GETTIME)
   681     check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME)
   682     if(FOUND_CLOCK_GETTIME)
   683       list(APPEND EXTRA_LIBS rt)
   684       set(HAVE_CLOCK_GETTIME 1)
   685     else(FOUND_CLOCK_GETTIME)
   686       check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
   687       if(FOUND_CLOCK_GETTIME)
   688         set(HAVE_CLOCK_GETTIME 1)
   689       endif(FOUND_CLOCK_GETTIME)
   690     endif(HAVE_CLOCK_GETTIME)
   691   endif(CLOCK_GETTIME)
   692 
   693   check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
   694   if(HAVE_LINUX_VERSION_H)
   695     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
   696   endif(HAVE_LINUX_VERSION_H)
   697 
   698   if(SDL_POWER)
   699     if(LINUX)
   700       set(SDL_POWER_LINUX 1)
   701       file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
   702       set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   703       set(HAVE_SDL_POWER TRUE)
   704     endif(LINUX)
   705   endif(SDL_POWER)
   706 
   707   if(SDL_TIMERS)
   708     set(SDL_TIMER_UNIX 1)
   709     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
   710     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   711     set(HAVE_SDL_TIMERS TRUE)
   712   endif(SDL_TIMERS)
   713 
   714   if(RPATH)
   715     set(SDL_RLD_FLAGS "")
   716     if(BSDI OR FREEBSD OR LINUX OR NETBSD)
   717       set(SDL_RLD_FLAGS "-Wl,-rpath,\${libdir}")
   718     elseif(SOLARIS)
   719       set(SDL_RLD_FLAGS "-R\${libdir}")
   720     endif()
   721     set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
   722     set(HAVE_RPATH TRUE)
   723   endif(RPATH)
   724 
   725 elseif(WINDOWS)
   726   find_program(WINDRES windres)
   727 
   728   check_c_source_compiles("
   729     #include <windows.h>
   730     int main(int argc, char **argv) { }" HAVE_WIN32_CC)
   731 
   732   file(GLOB WIN_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   733   set(SOURCE_FILES ${SOURCE_FILES} ${WIN_SOURCES})
   734 
   735   # Check for DirectX
   736   if(DIRECTX)
   737     if("$ENV{DXSDK_DIR}" STREQUAL "")
   738       message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set")
   739     endif("$ENV{DXSDK_DIR}" STREQUAL "")
   740     set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
   741     check_include_file(d3d9.h HAVE_D3D_H)
   742     check_include_file(ddraw.h HAVE_DDRAW_H)
   743     check_include_file(dsound.h HAVE_DSOUND_H)
   744     check_include_file(dinput.h HAVE_DINPUT_H)
   745     check_include_file(xaudio2.h HAVE_XAUDIO2_H)
   746     if(HAVE_D3D_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H OR HAVE_XAUDIO2_H)
   747       set(HAVE_DIRECTX TRUE)
   748       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   749       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   750       include_directories($ENV{DXSDK_DIR}\\Include)
   751     endif()
   752     set(CMAKE_REQUIRED_FLAGS)
   753   endif(DIRECTX)
   754 
   755   if(SDL_AUDIO)
   756     set(SDL_AUDIO_DRIVER_WINMM 1)
   757     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   758     set(SOURCE_FILES ${SOURCE_FILES} ${WINMM_AUDIO_SOURCES})
   759     set(HAVE_SDL_AUDIO TRUE)
   760 
   761     if(HAVE_DSOUND_H)
   762       set(SDL_AUDIO_DRIVER_DSOUND 1)
   763       file(GLOB DSOUND_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/directsound/*.c)
   764       set(SOURCE_FILES ${SOURCE_FILES} ${DSOUND_AUDIO_SOURCES})
   765     endif(HAVE_DSOUND_H)
   766 
   767     if(HAVE_XAUDIO2_H)
   768       set(SDL_AUDIO_DRIVER_XAUDIO2 1)
   769       file(GLOB XAUDIO2_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/xaudio2/*.c)
   770       set(SOURCE_FILES ${SOURCE_FILES} ${XAUDIO2_AUDIO_SOURCES})
   771     endif(HAVE_XAUDIO2_H)
   772   endif(SDL_AUDIO)
   773 
   774   if(SDL_VIDEO)
   775     # requires SDL_LOADSO on Windows (IME, DX, etc.)
   776     if(NOT SDL_LOADSO)
   777       message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled")
   778     endif(NOT SDL_LOADSO)
   779     set(SDL_VIDEO_DRIVER_WINDOWS 1)
   780     file(GLOB WIN_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/windows/*.c)
   781     set(SOURCE_FILES ${SOURCE_FILES} ${WIN_VIDEO_SOURCES})
   782 
   783     if(RENDER_D3D AND HAVE_D3D_H)
   784       set(SDL_VIDEO_RENDER_D3D 1)
   785       set(HAVE_RENDER_D3D TRUE)
   786     endif(RENDER_D3D AND HAVE_D3D_H)
   787     set(HAVE_SDL_VIDEO TRUE)
   788   endif(SDL_VIDEO)
   789 
   790   if(SDL_THREADS)
   791     set(SDL_THREAD_WINDOWS 1)
   792     set(SOURCE_FILES ${SOURCE_FILES}
   793       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c
   794       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_syssem.c
   795       ${SDL2_SOURCE_DIR}/src/thread/windows/SDL_systhread.c
   796       ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syscond.c)
   797     set(HAVE_SDL_THREADS TRUE)
   798   endif(SDL_THREADS)
   799 
   800   if(SDL_POWER)
   801     set(SDL_POWER_WINDOWS 1)
   802     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/power/windows/SDL_syspower.c)
   803     set(HAVE_SDL_POWER TRUE)
   804   endif(SDL_POWER)
   805 
   806   # Libraries for Win32 native and MinGW
   807   list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
   808 
   809   # TODO: in configure.in the check for timers is set on
   810   # cygwin | mingw32* - does this include mingw32CE?
   811   if(SDL_TIMERS)
   812     set(SDL_TIMER_WINDOWS 1)
   813     file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/windows/*.c)
   814     set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
   815     set(HAVE_SDL_TIMERS TRUE)
   816   endif(SDL_TIMERS)
   817 
   818   if(SDL_LOADSO)
   819     set(SDL_LOADSO_WINDOWS 1)
   820     file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/windows/*.c)
   821     set(SOURCE_FILES ${SOURCE_FILES} ${LOADSO_SOURCES})
   822     set(HAVE_SDL_LOADSO TRUE)
   823   endif(SDL_LOADSO)
   824 
   825   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   826   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
   827 
   828   if(SDL_VIDEO)
   829     if(VIDEO_OPENGL)
   830       set(SDL_VIDEO_OPENGL 1)
   831       set(SDL_VIDEO_OPENGL_WGL 1)
   832       set(SDL_VIDEO_RENDER_OGL 1)
   833       set(HAVE_VIDEO_OPENGL TRUE)
   834     endif(VIDEO_OPENGL)
   835   endif(SDL_VIDEO)
   836 
   837   if(SDL_JOYSTICK)
   838     if(HAVE_DINPUT_H)
   839       set(SDL_JOYSTICK_DINPUT 1)
   840       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_dxjoystick.c)
   841       list(APPEND EXTRA_LIBS dinput8 dxguid dxerr)
   842     else()
   843       set(SDL_JOYSTICK_WINMM 1)
   844       set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/joystick/windows/SDL_mmjoystick.c)
   845     endif(HAVE_DINPUT_H)
   846     set(HAVE_SDL_JOYSTICK TRUE)
   847   endif(SDL_JOYSTICK)
   848 
   849   if(SDL_HAPTIC AND HAVE_DINPUT_H)
   850     set(SDL_HAPTIC_DINPUT 1)
   851     set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/haptic/windows/SDL_syshaptic.c)
   852     set(HAVE_SDL_HAPTIC TRUE)
   853   endif(SDL_HAPTIC AND HAVE_DINPUT_H)
   854 
   855   file(GLOB VERSION_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.rc)
   856   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/windows/*.c)
   857   if(MINGW OR CYGWIN)
   858     list(APPEND EXTRA_LIBS mingw32)
   859     list(APPEND EXTRA_LDFLAGS "-mwindows")
   860     set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main")
   861     list(APPEND SDL_LIBS "-lmingw32" "-lSDL2main" "-mwindows")
   862   endif(MINGW OR CYGWIN)
   863 elseif(APPLE)
   864   # TODO: rework this for proper MacOS X, iOS and Darwin support
   865 
   866   # Requires the darwin file implementation
   867   if(SDL_FILE)
   868     file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m)
   869     set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES})
   870     set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C)
   871     set(HAVE_SDL_FILE TRUE)
   872     set(SDL_FRAMEWORK_COCOA 1)
   873   else()
   874     message_error("SDL_FILE must be enabled to build on MacOS X")
   875   endif()
   876 
   877   if(SDL_AUDIO)
   878     set(MACOSX_COREAUDIO 1)
   879     file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/coreaudio/*.c)
   880     set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
   881     set(HAVE_SDL_AUDIO TRUE)
   882     set(SDL_FRAMEWORK_COREAUDIO 1)
   883     set(SDL_FRAMEWORK_AUDIOUNIT 1)
   884   endif()
   885 
   886   if(SDL_JOYSTICK)
   887     set(SDL_JOYSTICK_IOKIT 1)
   888     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/darwin/*.c)
   889     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   890     set(HAVE_SDL_JOYSTICK TRUE)
   891     set(SDL_FRAMEWORK_IOKIT 1)
   892     set(SDL_FRAMEWORK_FF 1)
   893   endif()
   894 
   895   if(SDL_HAPTIC)
   896     set(SDL_HAPTIC_IOKIT 1)
   897     file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/darwin/*.c)
   898     set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   899     set(HAVE_SDL_HAPTIC TRUE)
   900     set(SDL_FRAMEWORK_IOKIT 1)
   901     set(SDL_FRAMEWORK_FF 1)
   902     if(NOT SDL_JOYSTICK)
   903       message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK to be enabled")
   904     endif()
   905   endif()
   906 
   907   if(SDL_POWER)
   908     set(SDL_POWER_MACOSX 1)
   909     file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/macosx/*.c)
   910     set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
   911     set(HAVE_SDL_POWER TRUE)
   912     set(SDL_FRAMEWORK_CARBON 1)
   913     set(SDL_FRAMEWORK_IOKIT 1)
   914   endif()
   915 
   916   # Actually load the frameworks at the end so we don't duplicate include.
   917   if(SDL_FRAMEWORK_COCOA)
   918     find_library(COCOA_LIBRARY Cocoa)
   919     list(APPEND EXTRA_LIBS ${COCOA_LIBRARY})
   920   endif()
   921   if(SDL_FRAMEWORK_IOKIT)
   922     find_library(IOKIT IOKit)
   923     list(APPEND EXTRA_LIBS ${IOKIT})
   924   endif()
   925   if(SDL_FRAMEWORK_FF)
   926     find_library(FORCEFEEDBACK ForceFeedback)
   927     list(APPEND EXTRA_LIBS ${FORCEFEEDBACK})
   928   endif()
   929   if(SDL_FRAMEWORK_CARBON)
   930     find_library(CARBON_LIBRARY Carbon)
   931     list(APPEND EXTRA_LIBS ${CARBON_LIBRARY})
   932   endif()
   933   if(SDL_FRAMEWORK_COREAUDIO)
   934     find_library(COREAUDIO CoreAudio)
   935     list(APPEND EXTRA_LIBS ${COREAUDIO})
   936   endif()
   937   if(SDL_FRAMEWORK_AUDIOUNIT)
   938     find_library(AUDIOUNIT AudioUnit)
   939     list(APPEND EXTRA_LIBS ${AUDIOUNIT})
   940   endif()
   941 
   942   # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
   943   if(SDL_VIDEO)
   944     CheckCOCOA()
   945     if(VIDEO_OPENGL)
   946       set(SDL_VIDEO_OPENGL 1)
   947       set(SDL_VIDEO_OPENGL_CGL 1)
   948       set(SDL_VIDEO_RENDER_OGL 1)
   949       if(DARWIN)
   950         find_library(OpenGL_LIBRARY OpenGL)
   951         list(APPEND EXTRA_LIBRARIES ${OpenGL_LIBRARY})
   952       endif(DARWIN)
   953       set(HAVE_VIDEO_OPENGL TRUE)
   954     endif(VIDEO_OPENGL)
   955   endif(SDL_VIDEO)
   956 
   957   CheckPTHREAD()
   958 elseif(BEOS)
   959   if(SDL_VIDEO)
   960     set(SDL_VIDEO_DRIVER_BWINDOW 1)
   961     file(GLOB BWINDOW_SOURCES ${SDL2_SOURCE_DIR}/src/video/bwindow/*.c)
   962     set(SOURCE_FILES ${SOURCE_FILES} ${BWINDOW_SOURCES})
   963     set(HAVE_SDL_VIDEO TRUE)
   964 
   965     if(VIDEO_OPENGL)
   966       # TODO: Use FIND_PACKAGE(OpenGL) instead
   967       set(SDL_VIDEO_OPENGL 1)
   968       set(SDL_VIDEO_OPENGL_BGL 1)
   969       set(SDL_VIDEO_RENDER_OGL 1)
   970       list(APPEND EXTRA_LIBS GL)
   971       set(HAVE_VIDEO_OPENGL TRUE)
   972     endif(VIDEO_OPENGL)
   973   endif(SDL_VIDEO)
   974 endif()
   975 
   976 # Dummies
   977 # configure.in does it differently:
   978 # if not have X
   979 #   if enable_X {  SDL_X_DISABLED = 1 }
   980 #   [add dummy sources]
   981 # so it always adds a dummy, without checking, if it was actually requested.
   982 # This leads to missing internal references on building, since the
   983 # src/X/*.c does not get included.
   984 if(NOT HAVE_SDL_JOYSTICK)
   985   set(SDL_JOYSTICK_DISABLED 1)
   986   if(SDL_JOYSTICK AND NOT APPLE) # results in unresolved symbols on OSX
   987 
   988     file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/dummy/*.c)
   989     set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
   990   endif()
   991 endif(NOT HAVE_SDL_JOYSTICK)
   992 if(NOT HAVE_SDL_HAPTIC)
   993   set(SDL_HAPTIC_DISABLED 1)
   994   file(GLOB HAPTIC_SOURCES ${SDL2_SOURCE_DIR}/src/haptic/dummy/*.c)
   995   set(SOURCE_FILES ${SOURCE_FILES} ${HAPTIC_SOURCES})
   996 endif(NOT HAVE_SDL_HAPTIC)
   997 if(NOT HAVE_SDL_LOADSO)
   998   set(SDL_LOADSO_DISABLED 1)
   999   file(GLOB LOADSO_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dummy/*.c)
  1000   set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
  1001 endif(NOT HAVE_SDL_LOADSO)
  1002 
  1003 # We always need to have threads and timers around
  1004 if(NOT HAVE_SDL_THREADS)
  1005   set(SDL_THREADS_DISABLED 1)
  1006   file(GLOB THREADS_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/*.c)
  1007   set(SOURCE_FILES ${SOURCE_FILES} ${THREADS_SOURCES})
  1008 endif(NOT HAVE_SDL_THREADS)
  1009 if(NOT HAVE_SDL_TIMERS)
  1010   set(SDL_TIMERS_DISABLED 1)
  1011   file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/dummy/*.c)
  1012   set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
  1013 endif(NOT HAVE_SDL_TIMERS)
  1014 
  1015 if(NOT SDLMAIN_SOURCES)
  1016   file(GLOB SDLMAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/dummy/*.c)
  1017 endif(NOT SDLMAIN_SOURCES)
  1018 
  1019 # Append the -MMD -MT flags
  1020 # if(DEPENDENCY_TRACKING)
  1021 #   if(COMPILER_IS_GNUCC)
  1022 #     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MMD -MT \$@")
  1023 #   endif(COMPILER_IS_GNUCC)
  1024 # endif(DEPENDENCY_TRACKING)
  1025 
  1026 configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
  1027   "${SDL2_BINARY_DIR}/include/SDL_config.h")
  1028 
  1029 # Prepare the flags and remove duplicates
  1030 if(EXTRA_LDFLAGS)
  1031   list(REMOVE_DUPLICATES EXTRA_LDFLAGS)
  1032 endif(EXTRA_LDFLAGS)
  1033 if(EXTRA_LIBS)
  1034   list(REMOVE_DUPLICATES EXTRA_LIBS)
  1035 endif(EXTRA_LIBS)
  1036 if(EXTRA_CFLAGS)
  1037   list(REMOVE_DUPLICATES EXTRA_CFLAGS)
  1038 endif(EXTRA_CFLAGS)
  1039 listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS)
  1040 set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
  1041 
  1042 # Compat helpers for the configuration files
  1043 if(NOT WINDOWS OR CYGWIN)
  1044   # TODO: we need a Windows script, too
  1045   execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
  1046 
  1047   set(prefix ${CMAKE_INSTALL_PREFIX})
  1048   set(exec_prefix "\${prefix}")
  1049   set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
  1050   set(bindir "\${exec_prefix}/bin")
  1051   set(includedir "\${prefix}/include")
  1052   if(SDL_STATIC)
  1053     set(ENABLE_STATIC_TRUE "")
  1054     set(ENABLE_STATIC_FALSE "#")
  1055   else(SDL_STATIC)
  1056     set(ENABLE_STATIC_TRUE "#")
  1057     set(ENABLE_STATIC_FALSE "")
  1058   endif(SDL_STATIC)
  1059   if(SDL_SHARED)
  1060     set(ENABLE_SHARED_TRUE "")
  1061     set(ENABLE_SHARED_FALSE "#")
  1062   else(SDL_SHARED)
  1063     set(ENABLE_SHARED_TRUE "#")
  1064     set(ENABLE_SHARED_FALSE "")
  1065   endif(SDL_SHARED)
  1066 
  1067   # Clean up the different lists
  1068   listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
  1069   set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
  1070   list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
  1071   listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
  1072   set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})
  1073   listtostr(SDL_LIBS _SDL_LIBS)
  1074   set(SDL_LIBS ${_SDL_LIBS})
  1075 
  1076   # MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
  1077   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
  1078 
  1079   configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
  1080     "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
  1081   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1082     "${SDL2_BINARY_DIR}/sdl2-config")
  1083   configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
  1084     "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
  1085   configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
  1086     "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
  1087 endif(NOT WINDOWS OR CYGWIN)
  1088 
  1089 ##### Info output #####
  1090 message(STATUS "")
  1091 message(STATUS "SDL2 was configured with the following options:")
  1092 message(STATUS "")
  1093 message(STATUS "Platform: ${CMAKE_SYSTEM}")
  1094 message(STATUS "64-bit:   ${ARCH_64}")
  1095 message(STATUS "Compiler: ${CMAKE_C_COMPILER}")
  1096 message(STATUS "")
  1097 message(STATUS "Subsystems:")
  1098 foreach(_SUB ${SDL_SUBSYSTEMS})
  1099   string(TOUPPER ${_SUB} _OPT)
  1100   message_bool_option(${_SUB} SDL_${_OPT})
  1101 endforeach()
  1102 message(STATUS "")
  1103 message(STATUS "Options:")
  1104 list(SORT ALLOPTIONS)
  1105 foreach(_OPT ${ALLOPTIONS})
  1106   # Longest option is VIDEO_X11_XSCREENSAVER = 22 characters
  1107   # Get the padding
  1108   string(LENGTH ${_OPT} _OPTLEN)
  1109   math(EXPR _PADLEN "23 - ${_OPTLEN}")
  1110   string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING)
  1111   message_tested_option(${_OPT} ${_PADDING})
  1112 endforeach()
  1113 message(STATUS "")
  1114 message(STATUS " CFLAGS:        ${CMAKE_C_FLAGS}")
  1115 message(STATUS " EXTRA_CFLAGS:  ${EXTRA_CFLAGS}")
  1116 message(STATUS " EXTRA_LDFLAGS: ${EXTRA_LDFLAGS}")
  1117 message(STATUS " EXTRA_LIBS:    ${EXTRA_LIBS}")
  1118 message(STATUS "")
  1119 message(STATUS " Build Shared Library: ${SDL_SHARED}")
  1120 message(STATUS " Build Static Library: ${SDL_STATIC}")
  1121 message(STATUS "")
  1122 if(UNIX)
  1123   message(STATUS "Something was not detected, although your are sure that it")
  1124   message(STATUS "has been properly installed? Then make sure, you have set")
  1125   message(STATUS "the CFLAGS and LDFLAGS environment variables correctly.")
  1126   message(STATUS "")
  1127 endif(UNIX)
  1128 
  1129 # Ensure that the extra cflags are used at compile time
  1130 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
  1131 
  1132 # Always build SDLmain
  1133 add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
  1134 set(_INSTALL_LIBS "SDL2main")
  1135 
  1136 if(SDL_SHARED)
  1137   add_library(SDL2 SHARED ${SOURCE_FILES})
  1138   set_target_properties(SDL2 PROPERTIES
  1139     VERSION ${SDL_VERSION}
  1140     SOVERSION ${LT_CURRENT})
  1141  set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
  1142  target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1143 endif(SDL_SHARED)
  1144 
  1145 if(SDL_STATIC)
  1146   add_library(SDL2-static STATIC ${SOURCE_FILES})
  1147   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
  1148   # TODO: Win32 platforms keep the same suffix .lib for import and static
  1149   # libraries - do we need to consider this?
  1150   set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
  1151   target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
  1152 endif(SDL_STATIC)
  1153 
  1154 ##### Installation targets #####
  1155 install(TARGETS ${_INSTALL_LIBS}
  1156   LIBRARY DESTINATION "lib${LIB_SUFFIX}"
  1157   ARCHIVE DESTINATION "lib${LIB_SUFFIX}")
  1158 
  1159 file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
  1160 file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
  1161 foreach(_FNAME ${BIN_INCLUDE_FILES})
  1162   get_filename_component(_INCNAME ${_FNAME} NAME)
  1163   list(REMOVE_ITEM INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/${_INCNAME})
  1164 endforeach()
  1165 list(APPEND INCLUDE_FILES ${BIN_INCLUDE_FILES})
  1166 install(FILES ${INCLUDE_FILES} DESTINATION include/SDL2)
  1167 
  1168 if(NOT WINDOWS OR CYGWIN)
  1169   if(FREEBSD)
  1170     # FreeBSD uses ${PREFIX}/libdata/pkgconfig
  1171     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
  1172   else(FREEBSD)
  1173     install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
  1174       DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
  1175   endif(FREEBSD)
  1176   install(PROGRAMS ${SDL2_BINARY_DIR}/sdl2-config DESTINATION bin)
  1177   # TODO: what about the .spec file? Is it only needed for RPM creation?
  1178 endif(NOT WINDOWS OR CYGWIN)