cmake/sdlchecks.cmake
author Gabriel Jacobo <gabomdq@gmail.com>
Fri, 19 Apr 2013 13:25:39 -0300
changeset 7078 a2bddc1fb02f
parent 6674 45a21e50ba5e
child 7182 1089a8a701c3
permissions -rw-r--r--
Fixes bug #1709, pthread tests fixes for CMake (Thanks Scott Percival!)
     1 macro(CheckDLOPEN)
     2   check_function_exists(dlopen HAVE_DLOPEN)
     3   if(NOT HAVE_DLOPEN)
     4     foreach(_LIBNAME dl tdl)
     5       check_library_exists("${_LIBNAME}" "dlopen" "" DLOPEN_LIB)
     6       if(DLOPEN_LIB)
     7         list(APPEND EXTRA_LIBS ${_LIBNAME})
     8         set(_DLLIB ${_LIBNAME})
     9         set(HAVE_DLOPEN TRUE)
    10         break()
    11       endif(DLOPEN_LIB)
    12     endforeach()
    13   endif()
    14 
    15   if(HAVE_DLOPEN)
    16     if(_DLLIB)
    17       set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
    18     endif()
    19     check_c_source_compiles("
    20        #include <dlfcn.h>
    21        #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 1020
    22        #error Use dlcompat for Mac OS X 10.2 compatibility
    23        #endif
    24        int main(int argc, char **argv) {}" HAVE_DLOPEN)
    25     set(CMAKE_REQUIRED_LIBRARIES)
    26   endif()
    27 
    28   if (HAVE_DLOPEN)
    29     set(SDL_LOADSO_DLOPEN 1)
    30     set(HAVE_SDL_DLOPEN TRUE)
    31     file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
    32     set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
    33     set(HAVE_SDL_LOADSO TRUE)
    34   endif()
    35 endmacro(CheckDLOPEN)
    36 
    37 # Requires:
    38 # - n/a
    39 macro(CheckOSS)
    40   if(OSS)
    41     set(OSS_HEADER_FILE "sys/soundcard.h")
    42     check_c_source_compiles("
    43         #include <sys/soundcard.h>
    44         int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
    45     if(NOT OSS_FOUND)
    46       set(OSS_HEADER_FILE "soundcard.h")
    47       check_c_source_compiles("
    48           #include <soundcard.h>
    49           int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
    50     endif(NOT OSS_FOUND)
    51 
    52     if(OSS_FOUND)
    53       set(HAVE_OSS TRUE)
    54       file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
    55       if(OSS_HEADER_FILE STREQUAL "soundcard.h")
    56         set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
    57       endif(OSS_HEADER_FILE STREQUAL "soundcard.h")
    58       set(SDL_AUDIO_DRIVER_OSS 1)
    59       set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
    60       if(NETBSD OR OPENBSD)
    61         list(APPEND EXTRA_LIBS ossaudio)
    62       endif(NETBSD OR OPENBSD)
    63       set(HAVE_SDL_AUDIO TRUE)
    64     endif(OSS_FOUND)
    65   endif(OSS)
    66 endmacro(CheckOSS)
    67 
    68 # Requires:
    69 # - n/a
    70 # Optional:
    71 # - ALSA_SHARED opt
    72 # - HAVE_DLOPEN opt
    73 macro(CheckALSA)
    74   if(ALSA)
    75     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H)
    76     if(HAVE_ASOUNDLIB_H)
    77       CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
    78       set(HAVE_ALSA TRUE)
    79       file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
    80       set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
    81       set(SDL_AUDIO_DRIVER_ALSA 1)
    82       if(ALSA_SHARED)
    83         if(NOT HAVE_DLOPEN)
    84           message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
    85         else()
    86           find_library(_ALSA_LIB asound)
    87           get_filename_component(F_ALSA_LIB ${_ALSA_LIB} NAME)
    88           set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${F_ALSA_LIB}\"")
    89           set(HAVE_ALSA_SHARED TRUE)
    90         endif(NOT HAVE_DLOPEN)
    91       else(ALSA_SHARED)
    92         list(APPEND EXTRA_LIBS asound)
    93       endif(ALSA_SHARED)
    94       set(HAVE_SDL_AUDIO TRUE)
    95     endif(HAVE_ASOUNDLIB_H)
    96   endif(ALSA)
    97 endmacro(CheckALSA)
    98 
    99 # Requires:
   100 # - PkgCheckModules
   101 # Optional:
   102 # - PULSEAUDIO_SHARED opt
   103 # - HAVE_DLOPEN opt
   104 macro(CheckPulseAudio)
   105   if(PULSEAUDIO)
   106     pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
   107     if(PKG_PULSEAUDIO_FOUND)
   108       set(HAVE_PULSEAUDIO TRUE)
   109       file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
   110       set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
   111       set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
   112       list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
   113       if(PULSEAUDIO_SHARED)
   114         if(NOT HAVE_DLOPEN)
   115           message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
   116         else()
   117           find_library(D_PULSE_LIB pulse-simple)
   118           get_filename_component(F_PULSE_LIB ${D_PULSE_LIB} NAME)
   119           set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${F_PULSE_LIB}\"")
   120           set(HAVE_PULSEAUDIO_SHARED TRUE)
   121         endif(NOT HAVE_DLOPEN)
   122       else(PULSEAUDIO_SHARED)
   123         list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
   124       endif(PULSEAUDIO_SHARED)
   125       set(HAVE_SDL_AUDIO TRUE)
   126     endif(PKG_PULSEAUDIO_FOUND)
   127   endif(PULSEAUDIO)
   128 endmacro(CheckPulseAudio)
   129 
   130 # Requires:
   131 # - PkgCheckModules
   132 # Optional:
   133 # - ESD_SHARED opt
   134 # - HAVE_DLOPEN opt
   135 macro(CheckESD)
   136   if(ESD)
   137     pkg_check_modules(PKG_ESD esound)
   138     if(PKG_ESD_FOUND)
   139       set(HAVE_ESD TRUE)
   140       file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
   141       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
   142       set(SDL_AUDIO_DRIVER_ESD 1)
   143       list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
   144       if(ESD_SHARED)
   145         if(NOT HAVE_DLOPEN)
   146           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
   147         else()
   148           find_library(D_ESD_LIB esd)
   149           get_filename_component(F_ESD_LIB ${D_ESD_LIB} NAME)
   150           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${F_ESD_LIB}\"")
   151           set(HAVE_ESD_SHARED TRUE)
   152         endif(NOT HAVE_DLOPEN)
   153       else(ESD_SHARED)
   154         list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   155       endif(ESD_SHARED)
   156       set(HAVE_SDL_AUDIO TRUE)
   157     endif(PKG_ESD_FOUND)
   158   endif(ESD)
   159 endmacro(CheckESD)
   160 
   161 # Requires:
   162 # - n/a
   163 # Optional:
   164 # - ARTS_SHARED opt
   165 # - HAVE_DLOPEN opt
   166 macro(CheckARTS)
   167   if(ARTS)
   168     find_program(ARTS_CONFIG arts-config)
   169     if(ARTS_CONFIG)
   170       execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
   171         OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   172       list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
   173       execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
   174         OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
   175       file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
   176       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
   177       set(SDL_AUDIO_DRIVER_ARTS 1)
   178       set(HAVE_ARTS TRUE)
   179       if(ARTS_SHARED)
   180         if(NOT HAVE_DLOPEN)
   181           message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
   182         else()
   183           # TODO
   184           find_library(D_ARTS_LIB artsc)
   185           get_filename_component(F_ARTS_LIB ${D_ARTS_LIB} NAME)
   186           set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${F_ARTS_LIB}\"")
   187           set(HAVE_ARTS_SHARED TRUE)
   188         endif(NOT HAVE_DLOPEN)
   189       else(ARTS_SHARED)
   190         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   191       endif(ARTS_SHARED)
   192       set(HAVE_SDL_AUDIO TRUE)
   193     endif(ARTS_CONFIG)
   194   endif(ARTS)
   195 endmacro(CheckARTS)
   196 
   197 # Requires:
   198 # - n/a
   199 # Optional:
   200 # - NAS_SHARED opt
   201 # - HAVE_DLOPEN opt
   202 macro(CheckNAS)
   203   if(NAS)
   204     # TODO: set include paths properly, so the NAS headers are found
   205     check_include_file(audio/audiolib.h HAVE_NAS_H)
   206     find_library(D_NAS_LIB audio)
   207     if(HAVE_NAS_H AND D_NAS_LIB)
   208       set(HAVE_NAS TRUE)
   209       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
   210       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
   211       set(SDL_AUDIO_DRIVER_NAS 1)
   212       if(NAS_SHARED)
   213         if(NOT HAVE_DLOPEN)
   214           message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
   215         else()
   216           get_filename_component(F_NAS_LIB ${D_NAS_LIB} NAME)
   217           set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${F_NAS_LIB}\"")
   218           set(HAVE_NAS_SHARED TRUE)
   219         endif(NOT HAVE_DLOPEN)
   220       else(NAS_SHARED)
   221         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   222       endif(NAS_SHARED)
   223       set(HAVE_SDL_AUDIO TRUE)
   224     endif(HAVE_NAS_H AND D_NAS_LIB)
   225   endif(NAS)
   226 endmacro(CheckNAS)
   227 
   228 # Requires:
   229 # - PkgCheckModules
   230 # Optional:
   231 # - FUSIONSOUND_SHARED opt
   232 # - HAVE_DLOPEN opt
   233 macro(CheckFusionSound)
   234   if(FUSIONSOUND)
   235     pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
   236     if(PKG_FUSIONSOUND_FOUND)
   237       set(HAVE_FUSIONSOUND TRUE)
   238       file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
   239       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
   240       set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
   241       list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
   242       if(FUSIONSOUND_SHARED)
   243         if(NOT HAVE_DLOPEN)
   244           message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
   245         else()
   246           find_library(D_FUSIONSOUND_LIB fusionsound)
   247           get_filename_component(F_FUSIONSOUND_LIB ${D_FUSIONSOUND_LIB} NAME)
   248           set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${F_FUSIONSOUND_LIB}\"")
   249           set(HAVE_FUSIONSOUND_SHARED TRUE)
   250         endif(NOT HAVE_DLOPEN)
   251       else(FUSIONSOUND_SHARED)
   252         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   253       endif(FUSIONSOUND_SHARED)
   254       set(HAVE_SDL_AUDIO TRUE)
   255     endif(PKG_FUSIONSOUND_FOUND)
   256   endif(FUSIONSOUND)
   257 endmacro(CheckFusionSound)
   258 
   259 # Requires:
   260 # - n/a
   261 # Optional:
   262 # - X11_SHARED opt
   263 # - HAVE_DLOPEN opt
   264 macro(CheckX11)
   265   if(VIDEO_X11)
   266     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   267       string(TOUPPER ${_LIB} _LNAME)
   268       find_library(${_LNAME}_LIB ${_LIB})
   269       if(${_LNAME}_LIB)
   270         # reduce the library name for shared linking
   271         get_filename_component(_TMP ${${_LNAME}_LIB} NAME)
   272         set(${_LNAME}_LIB ${_TMP})
   273       endif()
   274     endforeach()
   275 
   276     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   277     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   278     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   279     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   280     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   281     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   282     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   283     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   284 
   285     if(X11_LIB)
   286       set(HAVE_VIDEO_X11 TRUE)
   287       set(HAVE_SDL_VIDEO TRUE)
   288 
   289       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   290       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   291       set(SDL_VIDEO_DRIVER_X11 1)
   292 
   293       if(HAVE_GCC_FVISIBILITY)
   294         set(X11_SYMBOLS_PRIVATE TRUE)
   295       else()
   296         set(X11_SYMBOLS_PRIVATE FALSE)
   297       endif(HAVE_GCC_FVISIBILITY)
   298 
   299       if(APPLE)
   300         set(X11_SHARED OFF)
   301         set(X11_SYMBOLS_PRIVATE TRUE)
   302       endif(APPLE)
   303 
   304       check_function_exists("shmat" HAVE_SHMAT)
   305       if(NOT HAVE_SHMAT)
   306         check_library_exists(ipc shmat "" HAVE_SHMAT)
   307         if(HAVE_SHMAT)
   308           list(APPEND EXTRA_LIBS ipc)
   309         endif(HAVE_SHMAT)
   310         if(NOT HAVE_SHMAT)
   311           add_definitions(-DNO_SHARED_MEMORY)
   312         endif(NOT HAVE_SHMAT)
   313       endif(NOT HAVE_SHMAT)
   314 
   315       if(X11_SHARED)
   316         if(NOT HAVE_DLOPEN)
   317           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   318           set(HAVE_X11_SHARED FALSE)
   319           if(X11_SYMBOLS_PRIVATE)
   320             message_warn("You must have gcc4 (-fvisibility=hidden) for dynamic X11 loading")
   321             set(HAVE_X11_SHARED TRUE)
   322           endif(X11_SYMBOLS_PRIVATE)
   323         else(NOT HAVE_DLOPEN)
   324           set(HAVE_X11_SHARED TRUE)
   325         endif()
   326         if(HAVE_X11_SHARED)
   327           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB}\"")
   328           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB}\"")
   329         else(HAVE_X11_SHARED)
   330           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   331         endif(HAVE_X11_SHARED)
   332       endif(X11_SHARED)
   333 
   334       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   335       check_c_source_compiles("
   336           #include <X11/Xlib.h>
   337           #include <X11/Xproto.h>
   338           #include <X11/extensions/Xext.h>
   339           #include <X11/extensions/extutil.h>
   340           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   341           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   342       if(HAVE_CONST_XEXT_ADDDISPLAY)
   343         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   344       endif(HAVE_CONST_XEXT_ADDDISPLAY)
   345 
   346       check_c_source_compiles("
   347           #include <X11/Xlib.h>
   348           int main(int argc, char **argv) {
   349             Display *display;
   350             XEvent event;
   351             XGenericEventCookie *cookie = &event.xcookie;
   352             XNextEvent(display, &event);
   353             XGetEventData(display, cookie);
   354             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   355       if(HAVE_XGENERICEVENT)
   356         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   357       endif(HAVE_XGENERICEVENT)
   358 
   359       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   360 
   361       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   362         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   363         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   364           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB}\"")
   365         else(HAVE_X11_SHARED AND XCURSOR_LIB)
   366           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   367         endif(HAVE_X11_SHARED AND XCURSOR_LIB)
   368         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   369       endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   370 
   371       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   372         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   373         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   374           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB}\"")
   375         else(HAVE_X11_SHARED AND XINERAMA_LIB)
   376           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   377         endif(HAVE_X11_SHARED AND XINERAMA_LIB)
   378         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   379       endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   380 
   381       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   382         set(HAVE_VIDEO_X11_XINPUT TRUE)
   383         if(HAVE_X11_SHARED AND XI_LIB)
   384           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB}\"")
   385         else(HAVE_X11_SHARED AND XI_LIB)
   386           list(APPEND EXTRA_LIBS ${XI_LIB})
   387         endif(HAVE_X11_SHARED AND XI_LIB)
   388         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   389 
   390         # Check for multitouch
   391         check_c_source_compiles("
   392             #include <X11/Xlib.h>
   393             #include <X11/Xproto.h>
   394             #include <X11/extensions/XInput2.h>
   395             int event_type = XI_TouchBegin;
   396             XITouchClassInfo *t;
   397             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   398             {
   399               return (Status)0;
   400             }
   401             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   402         if(HAVE_XINPUT2_MULTITOUCH)
   403           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   404         endif(HAVE_XINPUT2_MULTITOUCH)
   405       endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   406 
   407       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   408         if(HAVE_X11_SHARED AND XRANDR_LIB)
   409           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB}\"")
   410         else(HAVE_X11_SHARED AND XRANDR_LIB)
   411           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   412         endif(HAVE_X11_SHARED AND XRANDR_LIB)
   413         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   414         set(HAVE_VIDEO_X11_XRANDR TRUE)
   415       endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   416 
   417       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   418         if(HAVE_X11_SHARED AND XSS_LIB)
   419           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB}\"")
   420         else(HAVE_X11_SHARED AND XSS_LIB)
   421           list(APPEND EXTRA_LIBS ${XSS_LIB})
   422         endif(HAVE_X11_SHARED AND XSS_LIB)
   423         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   424         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   425       endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   426 
   427       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   428         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   429         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   430       endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   431 
   432       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   433         if(HAVE_X11_SHARED AND XF86VMODE_LIB)
   434           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XF86VMODE_LIB}\"")
   435         else(HAVE_X11_SHARED AND XF86VMODE_LIB)
   436           list(APPEND EXTRA_LIBS ${XF86VMODE_LIB})
   437         endif(HAVE_X11_SHARED AND XF86VMODE_LIB)
   438         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   439         set(HAVE_VIDEO_X11_XVM TRUE)
   440       endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   441 
   442       set(CMAKE_REQUIRED_LIBRARIES)
   443     endif(X11_LIB)
   444   endif(VIDEO_X11)
   445 endmacro(CheckX11)
   446 
   447 # Requires:
   448 # - n/a
   449 #
   450 macro(CheckCOCOA)
   451   if(VIDEO_COCOA)
   452     check_c_source_compiles("
   453         #import <Cocoa/Cocoa.h>
   454         int main (int argc, char** argv) {}" HAVE_VIDEO_COCOA)
   455     if(HAVE_VIDEO_COCOA)
   456       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   457       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   458       set(SDL_VIDEO_DRIVER_COCOA 1)
   459       set(HAVE_SDL_VIDEO TRUE)
   460     endif(HAVE_VIDEO_COCOA)
   461   endif(VIDEO_COCOA)
   462 endmacro(CheckCOCOA)
   463 
   464 # Requires:
   465 # - PkgCheckModules
   466 # Optional:
   467 # - DIRECTFB_SHARED opt
   468 # - HAVE_DLOPEN opt
   469 macro(CheckDirectFB)
   470   if(VIDEO_DIRECTFB)
   471     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   472     if(PKG_DIRECTFB_FOUND)
   473       set(HAVE_VIDEO_DIRECTFB TRUE)
   474       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   475       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   476       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   477       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   478       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   479       if(DIRECTFB_SHARED)
   480         if(NOT HAVE_DLOPEN)
   481           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   482         else()
   483           find_library(D_DIRECTFB_LIB directfb)
   484           get_filename_component(F_DIRECTFB_LIB ${D_DIRECTFB_LIB} NAME)
   485           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${F_DIRECTFB_LIB}\"")
   486           set(HAVE_DIRECTFB_SHARED TRUE)
   487         endif(NOT HAVE_DLOPEN)
   488       else(DIRECTFB_SHARED)
   489         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   490       endif(DIRECTFB_SHARED)
   491       set(HAVE_SDL_VIDEO TRUE)
   492     endif(PKG_DIRECTFB_FOUND)
   493   endif(VIDEO_DIRECTFB)
   494 endmacro(CheckDirectFB)
   495 
   496 # Requires:
   497 # - nada
   498 macro(CheckOpenGLX11)
   499   if(VIDEO_OPENGL)
   500     check_c_source_compiles("
   501         #include <GL/gl.h>
   502         #include <GL/glx.h>
   503         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   504 
   505     if(HAVE_VIDEO_OPENGL)
   506       set(HAVE_VIDEO_OPENGL TRUE)
   507       set(SDL_VIDEO_OPENGL 1)
   508       set(SDL_VIDEO_OPENGL_GLX 1)
   509       set(SDL_VIDEO_RENDER_OGL 1)
   510       list(APPEND EXTRA_LIBS GL)
   511     endif(HAVE_VIDEO_OPENGL)
   512   endif(VIDEO_OPENGL)
   513 endmacro(CheckOpenGLX11)
   514 
   515 # Requires:
   516 # - nada
   517 macro(CheckOpenGLESX11)
   518   if(VIDEO_OPENGLES)
   519     check_c_source_compiles("
   520         #include <EGL/egl.h>
   521         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES)
   522     if(HAVE_VIDEO_OPENGLES)
   523       check_c_source_compiles("
   524           #include <GLES/gl.h>
   525           #include <GLES/glext.h>
   526           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   527       if(HAVE_VIDEO_OPENGLES_V1)
   528         set(SDL_VIDEO_OPENGL_ES 1)
   529         set(SDL_VIDEO_RENDER_OGL_ES 1)
   530       endif(HAVE_VIDEO_OPENGLES_V1)
   531       check_c_source_compiles("
   532           #include <GLES2/gl2.h>
   533           #include <GLES2/gl2ext.h>
   534           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   535       if(HAVE_VIDEO_OPENGLES_V2)
   536         set(SDL_VIDEO_OPENGL_ES2 1)
   537         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   538       endif(HAVE_VIDEO_OPENGLES_V2)
   539     endif(HAVE_VIDEO_OPENGLES)
   540   endif(VIDEO_OPENGLES)
   541 endmacro(CheckOpenGLESX11)
   542 
   543 # Rquires:
   544 # - nada
   545 # Optional:
   546 # - THREADS opt
   547 # Sets:
   548 # PTHREAD_CFLAGS
   549 # PTHREAD_LIBS
   550 macro(CheckPTHREAD)
   551   if(PTHREADS)
   552     if(LINUX)
   553       set(PTHREAD_CFLAGS "-D_REENTRANT")
   554       set(PTHREAD_LDFLAGS "-pthread")
   555     elseif(BSDI)
   556       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   557       set(PTHREAD_LDFLAGS "")
   558     elseif(DARWIN)
   559       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   560       # causes Carbon.p complaints?
   561       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   562       set(PTHREAD_LDFLAGS "")
   563     elseif(FREEBSD)
   564       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   565       set(PTHREAD_LDFLAGS "-pthread")
   566     elseif(NETBSD)
   567       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   568       set(PTHREAD_LDFLAGS "-lpthread")
   569     elseif(OPENBSD)
   570       set(PTHREAD_CFLAGS "-D_REENTRANT")
   571       set(PTHREAD_LDFLAGS "-pthread")
   572     elseif(SOLARIS)
   573       set(PTHREAD_CFLAGS "-D_REENTRANT")
   574       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   575     elseif(SYSV5)
   576       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   577       set(PTHREAD_LDFLAGS "")
   578     elseif(AIX)
   579       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   580       set(PTHREAD_LDFLAGS "-pthread")
   581     elseif(HPUX)
   582       set(PTHREAD_CFLAGS "-D_REENTRANT")
   583       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   584     else()
   585       set(PTHREAD_CFLAGS "-D_REENTRANT")
   586       set(PTHREAD_LDFLAGS "-lpthread")
   587     endif(LINUX)
   588 
   589     # Run some tests
   590     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   591     check_c_source_runs("
   592         #include <pthread.h>
   593         int main(int argc, char** argv) {
   594           pthread_attr_t type;
   595           pthread_attr_init(&type);
   596           return 0;
   597         }" HAVE_PTHREADS)
   598     if(HAVE_PTHREADS)
   599       set(SDL_THREAD_PTHREAD 1)
   600       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   601       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   602       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   603       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   604 
   605       check_c_source_compiles("
   606         #include <pthread.h>
   607         int main(int argc, char **argv) {
   608           pthread_mutexattr_t attr;
   609           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   610           return 0;
   611         }" HAVE_RECURSIVE_MUTEXES)
   612       if(HAVE_RECURSIVE_MUTEXES)
   613         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   614       else(HAVE_RECURSIVE_MUTEXES)
   615         check_c_source_compiles("
   616             #include <pthread.h>
   617             int main(int argc, char **argv) {
   618               pthread_mutexattr_t attr;
   619               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   620               return 0;
   621             }" HAVE_RECURSIVE_MUTEXES_NP)
   622         if(HAVE_RECURSIVE_MUTEXES_NP)
   623           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   624         endif(HAVE_RECURSIVE_MUTEXES_NP)
   625       endif(HAVE_RECURSIVE_MUTEXES)
   626 
   627       if(PTHREADS_SEM)
   628         check_c_source_compiles("#include <pthread.h>
   629                                  #include <semaphore.h>
   630                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   631         if(HAVE_PTHREADS_SEM)
   632           check_c_source_compiles("
   633               #include <pthread.h>
   634               #include <semaphore.h>
   635               int main(int argc, char **argv) {
   636                   sem_timedwait(NULL, NULL);
   637                   return 0;
   638               }" HAVE_SEM_TIMEDWAIT)
   639         endif(HAVE_PTHREADS_SEM)
   640       endif(PTHREADS_SEM)
   641 
   642       check_c_source_compiles("
   643           #include <pthread.h>
   644           int main(int argc, char** argv) {
   645               pthread_spin_trylock(NULL);
   646               return 0;
   647           }" HAVE_PTHREAD_SPINLOCK)
   648 
   649       check_c_source_compiles("
   650           #include <pthread.h>
   651           #include <pthread_np.h>
   652           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   653       check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   654       check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   655       set(CMAKE_REQUIRED_FLAGS)
   656 
   657       set(SOURCE_FILES ${SOURCE_FILES}
   658           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   659           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   660           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   661           )
   662       if(HAVE_PTHREADS_SEM)
   663         set(SOURCE_FILES ${SOURCE_FILES}
   664             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   665       else(HAVE_PTHREADS_SEM)
   666         set(SOURCE_FILES ${SOURCE_FILES}
   667             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   668       endif(HAVE_PTHREADS_SEM)
   669       set(HAVE_SDL_THREADS TRUE)
   670     endif(HAVE_PTHREADS)
   671   endif(PTHREADS)
   672 endmacro(CheckPTHREAD)
   673 
   674 # Requires
   675 # - nada
   676 # Optional:
   677 # Sets:
   678 # USB_LIBS
   679 # USB_CFLAGS
   680 macro(CheckUSBHID)
   681   check_library_exists(usbhid hid_init "" LIBUSBHID)
   682   if(LIBUSBHID)
   683     check_include_file(usbhid.h HAVE_USBHID_H)
   684     if(HAVE_USBHID_H)
   685       set(USB_CFLAGS "-DHAVE_USBHID_H")
   686     endif(HAVE_USBHID_H)
   687 
   688     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   689     if(HAVE_LIBUSBHID_H)
   690       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   691     endif(HAVE_LIBUSBHID_H)
   692     set(USB_LIBS ${USB_LIBS} usbhid)
   693   else(LIBUSBHID)
   694     check_include_file(usb.h HAVE_USB_H)
   695     if(HAVE_USB_H)
   696       set(USB_CFLAGS "-DHAVE_USB_H")
   697     endif(HAVE_USB_H)
   698     check_include_file(libusb.h HAVE_LIBUSB_H)
   699     if(HAVE_LIBUSB_H)
   700       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   701     endif(HAVE_LIBUSB_H)
   702     check_library_exists(usb hid_init "" LIBUSB)
   703     if(LIBUSB)
   704       set(USB_LIBS ${USB_LIBS} usb)
   705     endif(LIBUSB)
   706   endif(LIBUSBHID)
   707 
   708   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   709   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   710   check_c_source_compiles("
   711        #include <sys/types.h>
   712         #if defined(HAVE_USB_H)
   713         #include <usb.h>
   714         #endif
   715         #ifdef __DragonFly__
   716         # include <bus/usb/usb.h>
   717         # include <bus/usb/usbhid.h>
   718         #else
   719         # include <dev/usb/usb.h>
   720         # include <dev/usb/usbhid.h>
   721         #endif
   722         #if defined(HAVE_USBHID_H)
   723         #include <usbhid.h>
   724         #elif defined(HAVE_LIBUSB_H)
   725         #include <libusb.h>
   726         #elif defined(HAVE_LIBUSBHID_H)
   727         #include <libusbhid.h>
   728         #endif
   729         int main(int argc, char **argv) {
   730           struct report_desc *repdesc;
   731           struct usb_ctl_report *repbuf;
   732           hid_kind_t hidkind;
   733           return 0;
   734         }" HAVE_USBHID)
   735   if(HAVE_USBHID)
   736     check_c_source_compiles("
   737           #include <sys/types.h>
   738           #if defined(HAVE_USB_H)
   739           #include <usb.h>
   740           #endif
   741           #ifdef __DragonFly__
   742           # include <bus/usb/usb.h>
   743           # include <bus/usb/usbhid.h>
   744           #else
   745           # include <dev/usb/usb.h>
   746           # include <dev/usb/usbhid.h>
   747           #endif
   748           #if defined(HAVE_USBHID_H)
   749           #include <usbhid.h>
   750           #elif defined(HAVE_LIBUSB_H)
   751           #include <libusb.h>
   752           #elif defined(HAVE_LIBUSBHID_H)
   753           #include <libusbhid.h>
   754           #endif
   755           int main(int argc, char** argv) {
   756             struct usb_ctl_report buf;
   757             if (buf.ucr_data) { }
   758             return 0;
   759           }" HAVE_USBHID_UCR_DATA)
   760     if(HAVE_USBHID_UCR_DATA)
   761       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   762     endif(HAVE_USBHID_UCR_DATA)
   763 
   764     check_c_source_compiles("
   765           #include <sys/types.h>
   766           #if defined(HAVE_USB_H)
   767           #include <usb.h>
   768           #endif
   769           #ifdef __DragonFly__
   770           #include <bus/usb/usb.h>
   771           #include <bus/usb/usbhid.h>
   772           #else
   773           #include <dev/usb/usb.h>
   774           #include <dev/usb/usbhid.h>
   775           #endif
   776           #if defined(HAVE_USBHID_H)
   777           #include <usbhid.h>
   778           #elif defined(HAVE_LIBUSB_H)
   779           #include <libusb.h>
   780           #elif defined(HAVE_LIBUSBHID_H)
   781           #include <libusbhid.h>
   782           #endif
   783           int main(int argc, char **argv) {
   784             report_desc_t d;
   785             hid_start_parse(d, 1, 1);
   786             return 0;
   787           }" HAVE_USBHID_NEW)
   788     if(HAVE_USBHID_NEW)
   789       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   790     endif(HAVE_USBHID_NEW)
   791 
   792     check_c_source_compiles("
   793         #include <machine/joystick.h>
   794         int main(int argc, char** argv) {
   795             struct joystick t;
   796             return 0;
   797         }" HAVE_MACHINE_JOYSTICK)
   798     if(HAVE_MACHINE_JOYSTICK)
   799       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   800     endif(HAVE_MACHINE_JOYSTICK)
   801     set(SDL_JOYSTICK_USBHID 1)
   802     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   803     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   804     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   805     list(APPEND EXTRA_LIBS ${USB_LIBS})
   806     set(HAVE_SDL_JOYSTICK TRUE)
   807 
   808     set(CMAKE_REQUIRED_LIBRARIES)
   809     set(CMAKE_REQUIRED_FLAGS)
   810   endif(HAVE_USBHID)
   811 endmacro(CheckUSBHID)