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