cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Thu, 16 May 2013 00:52:33 -0700
changeset 7182 1089a8a701c3
parent 7078 a2bddc1fb02f
child 7266 6caad66a4966
permissions -rw-r--r--
Fixed bug 1839 - SDL2 Cmake: VIDEO_COCOA check fails on OS X; VIDEO_COCOA sources aren't compiled.
     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_objc_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_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   458       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   459       set(SDL_VIDEO_DRIVER_COCOA 1)
   460       set(HAVE_SDL_VIDEO TRUE)
   461     endif(HAVE_VIDEO_COCOA)
   462   endif(VIDEO_COCOA)
   463 endmacro(CheckCOCOA)
   464 
   465 # Requires:
   466 # - PkgCheckModules
   467 # Optional:
   468 # - DIRECTFB_SHARED opt
   469 # - HAVE_DLOPEN opt
   470 macro(CheckDirectFB)
   471   if(VIDEO_DIRECTFB)
   472     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   473     if(PKG_DIRECTFB_FOUND)
   474       set(HAVE_VIDEO_DIRECTFB TRUE)
   475       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   476       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   477       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   478       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   479       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   480       if(DIRECTFB_SHARED)
   481         if(NOT HAVE_DLOPEN)
   482           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   483         else()
   484           find_library(D_DIRECTFB_LIB directfb)
   485           get_filename_component(F_DIRECTFB_LIB ${D_DIRECTFB_LIB} NAME)
   486           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${F_DIRECTFB_LIB}\"")
   487           set(HAVE_DIRECTFB_SHARED TRUE)
   488         endif(NOT HAVE_DLOPEN)
   489       else(DIRECTFB_SHARED)
   490         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   491       endif(DIRECTFB_SHARED)
   492       set(HAVE_SDL_VIDEO TRUE)
   493     endif(PKG_DIRECTFB_FOUND)
   494   endif(VIDEO_DIRECTFB)
   495 endmacro(CheckDirectFB)
   496 
   497 # Requires:
   498 # - nada
   499 macro(CheckOpenGLX11)
   500   if(VIDEO_OPENGL)
   501     check_c_source_compiles("
   502         #include <GL/gl.h>
   503         #include <GL/glx.h>
   504         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   505 
   506     if(HAVE_VIDEO_OPENGL)
   507       set(HAVE_VIDEO_OPENGL TRUE)
   508       set(SDL_VIDEO_OPENGL 1)
   509       set(SDL_VIDEO_OPENGL_GLX 1)
   510       set(SDL_VIDEO_RENDER_OGL 1)
   511       list(APPEND EXTRA_LIBS GL)
   512     endif(HAVE_VIDEO_OPENGL)
   513   endif(VIDEO_OPENGL)
   514 endmacro(CheckOpenGLX11)
   515 
   516 # Requires:
   517 # - nada
   518 macro(CheckOpenGLESX11)
   519   if(VIDEO_OPENGLES)
   520     check_c_source_compiles("
   521         #include <EGL/egl.h>
   522         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES)
   523     if(HAVE_VIDEO_OPENGLES)
   524       check_c_source_compiles("
   525           #include <GLES/gl.h>
   526           #include <GLES/glext.h>
   527           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   528       if(HAVE_VIDEO_OPENGLES_V1)
   529         set(SDL_VIDEO_OPENGL_ES 1)
   530         set(SDL_VIDEO_RENDER_OGL_ES 1)
   531       endif(HAVE_VIDEO_OPENGLES_V1)
   532       check_c_source_compiles("
   533           #include <GLES2/gl2.h>
   534           #include <GLES2/gl2ext.h>
   535           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   536       if(HAVE_VIDEO_OPENGLES_V2)
   537         set(SDL_VIDEO_OPENGL_ES2 1)
   538         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   539       endif(HAVE_VIDEO_OPENGLES_V2)
   540     endif(HAVE_VIDEO_OPENGLES)
   541   endif(VIDEO_OPENGLES)
   542 endmacro(CheckOpenGLESX11)
   543 
   544 # Rquires:
   545 # - nada
   546 # Optional:
   547 # - THREADS opt
   548 # Sets:
   549 # PTHREAD_CFLAGS
   550 # PTHREAD_LIBS
   551 macro(CheckPTHREAD)
   552   if(PTHREADS)
   553     if(LINUX)
   554       set(PTHREAD_CFLAGS "-D_REENTRANT")
   555       set(PTHREAD_LDFLAGS "-pthread")
   556     elseif(BSDI)
   557       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   558       set(PTHREAD_LDFLAGS "")
   559     elseif(DARWIN)
   560       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   561       # causes Carbon.p complaints?
   562       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   563       set(PTHREAD_LDFLAGS "")
   564     elseif(FREEBSD)
   565       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   566       set(PTHREAD_LDFLAGS "-pthread")
   567     elseif(NETBSD)
   568       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   569       set(PTHREAD_LDFLAGS "-lpthread")
   570     elseif(OPENBSD)
   571       set(PTHREAD_CFLAGS "-D_REENTRANT")
   572       set(PTHREAD_LDFLAGS "-pthread")
   573     elseif(SOLARIS)
   574       set(PTHREAD_CFLAGS "-D_REENTRANT")
   575       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   576     elseif(SYSV5)
   577       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   578       set(PTHREAD_LDFLAGS "")
   579     elseif(AIX)
   580       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   581       set(PTHREAD_LDFLAGS "-pthread")
   582     elseif(HPUX)
   583       set(PTHREAD_CFLAGS "-D_REENTRANT")
   584       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   585     else()
   586       set(PTHREAD_CFLAGS "-D_REENTRANT")
   587       set(PTHREAD_LDFLAGS "-lpthread")
   588     endif(LINUX)
   589 
   590     # Run some tests
   591     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   592     check_c_source_runs("
   593         #include <pthread.h>
   594         int main(int argc, char** argv) {
   595           pthread_attr_t type;
   596           pthread_attr_init(&type);
   597           return 0;
   598         }" HAVE_PTHREADS)
   599     if(HAVE_PTHREADS)
   600       set(SDL_THREAD_PTHREAD 1)
   601       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   602       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   603       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   604       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   605 
   606       check_c_source_compiles("
   607         #include <pthread.h>
   608         int main(int argc, char **argv) {
   609           pthread_mutexattr_t attr;
   610           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   611           return 0;
   612         }" HAVE_RECURSIVE_MUTEXES)
   613       if(HAVE_RECURSIVE_MUTEXES)
   614         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   615       else(HAVE_RECURSIVE_MUTEXES)
   616         check_c_source_compiles("
   617             #include <pthread.h>
   618             int main(int argc, char **argv) {
   619               pthread_mutexattr_t attr;
   620               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   621               return 0;
   622             }" HAVE_RECURSIVE_MUTEXES_NP)
   623         if(HAVE_RECURSIVE_MUTEXES_NP)
   624           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   625         endif(HAVE_RECURSIVE_MUTEXES_NP)
   626       endif(HAVE_RECURSIVE_MUTEXES)
   627 
   628       if(PTHREADS_SEM)
   629         check_c_source_compiles("#include <pthread.h>
   630                                  #include <semaphore.h>
   631                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   632         if(HAVE_PTHREADS_SEM)
   633           check_c_source_compiles("
   634               #include <pthread.h>
   635               #include <semaphore.h>
   636               int main(int argc, char **argv) {
   637                   sem_timedwait(NULL, NULL);
   638                   return 0;
   639               }" HAVE_SEM_TIMEDWAIT)
   640         endif(HAVE_PTHREADS_SEM)
   641       endif(PTHREADS_SEM)
   642 
   643       check_c_source_compiles("
   644           #include <pthread.h>
   645           int main(int argc, char** argv) {
   646               pthread_spin_trylock(NULL);
   647               return 0;
   648           }" HAVE_PTHREAD_SPINLOCK)
   649 
   650       check_c_source_compiles("
   651           #include <pthread.h>
   652           #include <pthread_np.h>
   653           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   654       check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   655       check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   656       set(CMAKE_REQUIRED_FLAGS)
   657 
   658       set(SOURCE_FILES ${SOURCE_FILES}
   659           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   660           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   661           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   662           )
   663       if(HAVE_PTHREADS_SEM)
   664         set(SOURCE_FILES ${SOURCE_FILES}
   665             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   666       else(HAVE_PTHREADS_SEM)
   667         set(SOURCE_FILES ${SOURCE_FILES}
   668             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   669       endif(HAVE_PTHREADS_SEM)
   670       set(HAVE_SDL_THREADS TRUE)
   671     endif(HAVE_PTHREADS)
   672   endif(PTHREADS)
   673 endmacro(CheckPTHREAD)
   674 
   675 # Requires
   676 # - nada
   677 # Optional:
   678 # Sets:
   679 # USB_LIBS
   680 # USB_CFLAGS
   681 macro(CheckUSBHID)
   682   check_library_exists(usbhid hid_init "" LIBUSBHID)
   683   if(LIBUSBHID)
   684     check_include_file(usbhid.h HAVE_USBHID_H)
   685     if(HAVE_USBHID_H)
   686       set(USB_CFLAGS "-DHAVE_USBHID_H")
   687     endif(HAVE_USBHID_H)
   688 
   689     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   690     if(HAVE_LIBUSBHID_H)
   691       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   692     endif(HAVE_LIBUSBHID_H)
   693     set(USB_LIBS ${USB_LIBS} usbhid)
   694   else(LIBUSBHID)
   695     check_include_file(usb.h HAVE_USB_H)
   696     if(HAVE_USB_H)
   697       set(USB_CFLAGS "-DHAVE_USB_H")
   698     endif(HAVE_USB_H)
   699     check_include_file(libusb.h HAVE_LIBUSB_H)
   700     if(HAVE_LIBUSB_H)
   701       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   702     endif(HAVE_LIBUSB_H)
   703     check_library_exists(usb hid_init "" LIBUSB)
   704     if(LIBUSB)
   705       set(USB_LIBS ${USB_LIBS} usb)
   706     endif(LIBUSB)
   707   endif(LIBUSBHID)
   708 
   709   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   710   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   711   check_c_source_compiles("
   712        #include <sys/types.h>
   713         #if defined(HAVE_USB_H)
   714         #include <usb.h>
   715         #endif
   716         #ifdef __DragonFly__
   717         # include <bus/usb/usb.h>
   718         # include <bus/usb/usbhid.h>
   719         #else
   720         # include <dev/usb/usb.h>
   721         # include <dev/usb/usbhid.h>
   722         #endif
   723         #if defined(HAVE_USBHID_H)
   724         #include <usbhid.h>
   725         #elif defined(HAVE_LIBUSB_H)
   726         #include <libusb.h>
   727         #elif defined(HAVE_LIBUSBHID_H)
   728         #include <libusbhid.h>
   729         #endif
   730         int main(int argc, char **argv) {
   731           struct report_desc *repdesc;
   732           struct usb_ctl_report *repbuf;
   733           hid_kind_t hidkind;
   734           return 0;
   735         }" HAVE_USBHID)
   736   if(HAVE_USBHID)
   737     check_c_source_compiles("
   738           #include <sys/types.h>
   739           #if defined(HAVE_USB_H)
   740           #include <usb.h>
   741           #endif
   742           #ifdef __DragonFly__
   743           # include <bus/usb/usb.h>
   744           # include <bus/usb/usbhid.h>
   745           #else
   746           # include <dev/usb/usb.h>
   747           # include <dev/usb/usbhid.h>
   748           #endif
   749           #if defined(HAVE_USBHID_H)
   750           #include <usbhid.h>
   751           #elif defined(HAVE_LIBUSB_H)
   752           #include <libusb.h>
   753           #elif defined(HAVE_LIBUSBHID_H)
   754           #include <libusbhid.h>
   755           #endif
   756           int main(int argc, char** argv) {
   757             struct usb_ctl_report buf;
   758             if (buf.ucr_data) { }
   759             return 0;
   760           }" HAVE_USBHID_UCR_DATA)
   761     if(HAVE_USBHID_UCR_DATA)
   762       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   763     endif(HAVE_USBHID_UCR_DATA)
   764 
   765     check_c_source_compiles("
   766           #include <sys/types.h>
   767           #if defined(HAVE_USB_H)
   768           #include <usb.h>
   769           #endif
   770           #ifdef __DragonFly__
   771           #include <bus/usb/usb.h>
   772           #include <bus/usb/usbhid.h>
   773           #else
   774           #include <dev/usb/usb.h>
   775           #include <dev/usb/usbhid.h>
   776           #endif
   777           #if defined(HAVE_USBHID_H)
   778           #include <usbhid.h>
   779           #elif defined(HAVE_LIBUSB_H)
   780           #include <libusb.h>
   781           #elif defined(HAVE_LIBUSBHID_H)
   782           #include <libusbhid.h>
   783           #endif
   784           int main(int argc, char **argv) {
   785             report_desc_t d;
   786             hid_start_parse(d, 1, 1);
   787             return 0;
   788           }" HAVE_USBHID_NEW)
   789     if(HAVE_USBHID_NEW)
   790       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   791     endif(HAVE_USBHID_NEW)
   792 
   793     check_c_source_compiles("
   794         #include <machine/joystick.h>
   795         int main(int argc, char** argv) {
   796             struct joystick t;
   797             return 0;
   798         }" HAVE_MACHINE_JOYSTICK)
   799     if(HAVE_MACHINE_JOYSTICK)
   800       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   801     endif(HAVE_MACHINE_JOYSTICK)
   802     set(SDL_JOYSTICK_USBHID 1)
   803     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   804     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   805     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   806     list(APPEND EXTRA_LIBS ${USB_LIBS})
   807     set(HAVE_SDL_JOYSTICK TRUE)
   808 
   809     set(CMAKE_REQUIRED_LIBRARIES)
   810     set(CMAKE_REQUIRED_FLAGS)
   811   endif(HAVE_USBHID)
   812 endmacro(CheckUSBHID)