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