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