cmake/sdlchecks.cmake
author Azamat H. Hackimov <azamat.hackimov@gmail.com>
Sun, 02 Jun 2013 20:20:18 +0600
changeset 7266 6caad66a4966
parent 7182 1089a8a701c3
child 7367 d6eabafa8776
permissions -rw-r--r--
Fix compilation with libX11 >= 1.5.99.902.

These changes fixes bug #1769 for SDL2
(http://bugzilla.libsdl.org/show_bug.cgi?id=1769).
     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_c_source_compiles("
   360           #include <X11/Xlibint.h>
   361           extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
   362           int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
   363       if(HAVE_CONST_XDATA32)
   364         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 1)
   365       endif(HAVE_CONST_XDATA32)
   366 
   367       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   368 
   369       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   370         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   371         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   372           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB}\"")
   373         else(HAVE_X11_SHARED AND XCURSOR_LIB)
   374           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   375         endif(HAVE_X11_SHARED AND XCURSOR_LIB)
   376         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   377       endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   378 
   379       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   380         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   381         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   382           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB}\"")
   383         else(HAVE_X11_SHARED AND XINERAMA_LIB)
   384           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   385         endif(HAVE_X11_SHARED AND XINERAMA_LIB)
   386         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   387       endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   388 
   389       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   390         set(HAVE_VIDEO_X11_XINPUT TRUE)
   391         if(HAVE_X11_SHARED AND XI_LIB)
   392           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB}\"")
   393         else(HAVE_X11_SHARED AND XI_LIB)
   394           list(APPEND EXTRA_LIBS ${XI_LIB})
   395         endif(HAVE_X11_SHARED AND XI_LIB)
   396         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   397 
   398         # Check for multitouch
   399         check_c_source_compiles("
   400             #include <X11/Xlib.h>
   401             #include <X11/Xproto.h>
   402             #include <X11/extensions/XInput2.h>
   403             int event_type = XI_TouchBegin;
   404             XITouchClassInfo *t;
   405             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   406             {
   407               return (Status)0;
   408             }
   409             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   410         if(HAVE_XINPUT2_MULTITOUCH)
   411           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   412         endif(HAVE_XINPUT2_MULTITOUCH)
   413       endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   414 
   415       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   416         if(HAVE_X11_SHARED AND XRANDR_LIB)
   417           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB}\"")
   418         else(HAVE_X11_SHARED AND XRANDR_LIB)
   419           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   420         endif(HAVE_X11_SHARED AND XRANDR_LIB)
   421         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   422         set(HAVE_VIDEO_X11_XRANDR TRUE)
   423       endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   424 
   425       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   426         if(HAVE_X11_SHARED AND XSS_LIB)
   427           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB}\"")
   428         else(HAVE_X11_SHARED AND XSS_LIB)
   429           list(APPEND EXTRA_LIBS ${XSS_LIB})
   430         endif(HAVE_X11_SHARED AND XSS_LIB)
   431         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   432         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   433       endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   434 
   435       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   436         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   437         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   438       endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   439 
   440       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   441         if(HAVE_X11_SHARED AND XF86VMODE_LIB)
   442           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XF86VMODE_LIB}\"")
   443         else(HAVE_X11_SHARED AND XF86VMODE_LIB)
   444           list(APPEND EXTRA_LIBS ${XF86VMODE_LIB})
   445         endif(HAVE_X11_SHARED AND XF86VMODE_LIB)
   446         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   447         set(HAVE_VIDEO_X11_XVM TRUE)
   448       endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   449 
   450       set(CMAKE_REQUIRED_LIBRARIES)
   451     endif(X11_LIB)
   452   endif(VIDEO_X11)
   453 endmacro(CheckX11)
   454 
   455 # Requires:
   456 # - n/a
   457 #
   458 macro(CheckCOCOA)
   459   if(VIDEO_COCOA)
   460     check_objc_source_compiles("
   461         #import <Cocoa/Cocoa.h>
   462         int main (int argc, char** argv) {}" HAVE_VIDEO_COCOA)
   463     if(HAVE_VIDEO_COCOA)
   464       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   465       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   466       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   467       set(SDL_VIDEO_DRIVER_COCOA 1)
   468       set(HAVE_SDL_VIDEO TRUE)
   469     endif(HAVE_VIDEO_COCOA)
   470   endif(VIDEO_COCOA)
   471 endmacro(CheckCOCOA)
   472 
   473 # Requires:
   474 # - PkgCheckModules
   475 # Optional:
   476 # - DIRECTFB_SHARED opt
   477 # - HAVE_DLOPEN opt
   478 macro(CheckDirectFB)
   479   if(VIDEO_DIRECTFB)
   480     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   481     if(PKG_DIRECTFB_FOUND)
   482       set(HAVE_VIDEO_DIRECTFB TRUE)
   483       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   484       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   485       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   486       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   487       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   488       if(DIRECTFB_SHARED)
   489         if(NOT HAVE_DLOPEN)
   490           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   491         else()
   492           find_library(D_DIRECTFB_LIB directfb)
   493           get_filename_component(F_DIRECTFB_LIB ${D_DIRECTFB_LIB} NAME)
   494           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${F_DIRECTFB_LIB}\"")
   495           set(HAVE_DIRECTFB_SHARED TRUE)
   496         endif(NOT HAVE_DLOPEN)
   497       else(DIRECTFB_SHARED)
   498         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   499       endif(DIRECTFB_SHARED)
   500       set(HAVE_SDL_VIDEO TRUE)
   501     endif(PKG_DIRECTFB_FOUND)
   502   endif(VIDEO_DIRECTFB)
   503 endmacro(CheckDirectFB)
   504 
   505 # Requires:
   506 # - nada
   507 macro(CheckOpenGLX11)
   508   if(VIDEO_OPENGL)
   509     check_c_source_compiles("
   510         #include <GL/gl.h>
   511         #include <GL/glx.h>
   512         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   513 
   514     if(HAVE_VIDEO_OPENGL)
   515       set(HAVE_VIDEO_OPENGL TRUE)
   516       set(SDL_VIDEO_OPENGL 1)
   517       set(SDL_VIDEO_OPENGL_GLX 1)
   518       set(SDL_VIDEO_RENDER_OGL 1)
   519       list(APPEND EXTRA_LIBS GL)
   520     endif(HAVE_VIDEO_OPENGL)
   521   endif(VIDEO_OPENGL)
   522 endmacro(CheckOpenGLX11)
   523 
   524 # Requires:
   525 # - nada
   526 macro(CheckOpenGLESX11)
   527   if(VIDEO_OPENGLES)
   528     check_c_source_compiles("
   529         #include <EGL/egl.h>
   530         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES)
   531     if(HAVE_VIDEO_OPENGLES)
   532       check_c_source_compiles("
   533           #include <GLES/gl.h>
   534           #include <GLES/glext.h>
   535           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   536       if(HAVE_VIDEO_OPENGLES_V1)
   537         set(SDL_VIDEO_OPENGL_ES 1)
   538         set(SDL_VIDEO_RENDER_OGL_ES 1)
   539       endif(HAVE_VIDEO_OPENGLES_V1)
   540       check_c_source_compiles("
   541           #include <GLES2/gl2.h>
   542           #include <GLES2/gl2ext.h>
   543           int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   544       if(HAVE_VIDEO_OPENGLES_V2)
   545         set(SDL_VIDEO_OPENGL_ES2 1)
   546         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   547       endif(HAVE_VIDEO_OPENGLES_V2)
   548     endif(HAVE_VIDEO_OPENGLES)
   549   endif(VIDEO_OPENGLES)
   550 endmacro(CheckOpenGLESX11)
   551 
   552 # Rquires:
   553 # - nada
   554 # Optional:
   555 # - THREADS opt
   556 # Sets:
   557 # PTHREAD_CFLAGS
   558 # PTHREAD_LIBS
   559 macro(CheckPTHREAD)
   560   if(PTHREADS)
   561     if(LINUX)
   562       set(PTHREAD_CFLAGS "-D_REENTRANT")
   563       set(PTHREAD_LDFLAGS "-pthread")
   564     elseif(BSDI)
   565       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   566       set(PTHREAD_LDFLAGS "")
   567     elseif(DARWIN)
   568       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   569       # causes Carbon.p complaints?
   570       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   571       set(PTHREAD_LDFLAGS "")
   572     elseif(FREEBSD)
   573       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   574       set(PTHREAD_LDFLAGS "-pthread")
   575     elseif(NETBSD)
   576       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   577       set(PTHREAD_LDFLAGS "-lpthread")
   578     elseif(OPENBSD)
   579       set(PTHREAD_CFLAGS "-D_REENTRANT")
   580       set(PTHREAD_LDFLAGS "-pthread")
   581     elseif(SOLARIS)
   582       set(PTHREAD_CFLAGS "-D_REENTRANT")
   583       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   584     elseif(SYSV5)
   585       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   586       set(PTHREAD_LDFLAGS "")
   587     elseif(AIX)
   588       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   589       set(PTHREAD_LDFLAGS "-pthread")
   590     elseif(HPUX)
   591       set(PTHREAD_CFLAGS "-D_REENTRANT")
   592       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   593     else()
   594       set(PTHREAD_CFLAGS "-D_REENTRANT")
   595       set(PTHREAD_LDFLAGS "-lpthread")
   596     endif(LINUX)
   597 
   598     # Run some tests
   599     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   600     check_c_source_runs("
   601         #include <pthread.h>
   602         int main(int argc, char** argv) {
   603           pthread_attr_t type;
   604           pthread_attr_init(&type);
   605           return 0;
   606         }" HAVE_PTHREADS)
   607     if(HAVE_PTHREADS)
   608       set(SDL_THREAD_PTHREAD 1)
   609       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   610       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   611       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   612       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   613 
   614       check_c_source_compiles("
   615         #include <pthread.h>
   616         int main(int argc, char **argv) {
   617           pthread_mutexattr_t attr;
   618           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   619           return 0;
   620         }" HAVE_RECURSIVE_MUTEXES)
   621       if(HAVE_RECURSIVE_MUTEXES)
   622         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   623       else(HAVE_RECURSIVE_MUTEXES)
   624         check_c_source_compiles("
   625             #include <pthread.h>
   626             int main(int argc, char **argv) {
   627               pthread_mutexattr_t attr;
   628               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   629               return 0;
   630             }" HAVE_RECURSIVE_MUTEXES_NP)
   631         if(HAVE_RECURSIVE_MUTEXES_NP)
   632           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   633         endif(HAVE_RECURSIVE_MUTEXES_NP)
   634       endif(HAVE_RECURSIVE_MUTEXES)
   635 
   636       if(PTHREADS_SEM)
   637         check_c_source_compiles("#include <pthread.h>
   638                                  #include <semaphore.h>
   639                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   640         if(HAVE_PTHREADS_SEM)
   641           check_c_source_compiles("
   642               #include <pthread.h>
   643               #include <semaphore.h>
   644               int main(int argc, char **argv) {
   645                   sem_timedwait(NULL, NULL);
   646                   return 0;
   647               }" HAVE_SEM_TIMEDWAIT)
   648         endif(HAVE_PTHREADS_SEM)
   649       endif(PTHREADS_SEM)
   650 
   651       check_c_source_compiles("
   652           #include <pthread.h>
   653           int main(int argc, char** argv) {
   654               pthread_spin_trylock(NULL);
   655               return 0;
   656           }" HAVE_PTHREAD_SPINLOCK)
   657 
   658       check_c_source_compiles("
   659           #include <pthread.h>
   660           #include <pthread_np.h>
   661           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   662       check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   663       check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   664       set(CMAKE_REQUIRED_FLAGS)
   665 
   666       set(SOURCE_FILES ${SOURCE_FILES}
   667           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   668           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   669           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   670           )
   671       if(HAVE_PTHREADS_SEM)
   672         set(SOURCE_FILES ${SOURCE_FILES}
   673             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   674       else(HAVE_PTHREADS_SEM)
   675         set(SOURCE_FILES ${SOURCE_FILES}
   676             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   677       endif(HAVE_PTHREADS_SEM)
   678       set(HAVE_SDL_THREADS TRUE)
   679     endif(HAVE_PTHREADS)
   680   endif(PTHREADS)
   681 endmacro(CheckPTHREAD)
   682 
   683 # Requires
   684 # - nada
   685 # Optional:
   686 # Sets:
   687 # USB_LIBS
   688 # USB_CFLAGS
   689 macro(CheckUSBHID)
   690   check_library_exists(usbhid hid_init "" LIBUSBHID)
   691   if(LIBUSBHID)
   692     check_include_file(usbhid.h HAVE_USBHID_H)
   693     if(HAVE_USBHID_H)
   694       set(USB_CFLAGS "-DHAVE_USBHID_H")
   695     endif(HAVE_USBHID_H)
   696 
   697     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   698     if(HAVE_LIBUSBHID_H)
   699       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   700     endif(HAVE_LIBUSBHID_H)
   701     set(USB_LIBS ${USB_LIBS} usbhid)
   702   else(LIBUSBHID)
   703     check_include_file(usb.h HAVE_USB_H)
   704     if(HAVE_USB_H)
   705       set(USB_CFLAGS "-DHAVE_USB_H")
   706     endif(HAVE_USB_H)
   707     check_include_file(libusb.h HAVE_LIBUSB_H)
   708     if(HAVE_LIBUSB_H)
   709       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   710     endif(HAVE_LIBUSB_H)
   711     check_library_exists(usb hid_init "" LIBUSB)
   712     if(LIBUSB)
   713       set(USB_LIBS ${USB_LIBS} usb)
   714     endif(LIBUSB)
   715   endif(LIBUSBHID)
   716 
   717   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   718   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   719   check_c_source_compiles("
   720        #include <sys/types.h>
   721         #if defined(HAVE_USB_H)
   722         #include <usb.h>
   723         #endif
   724         #ifdef __DragonFly__
   725         # include <bus/usb/usb.h>
   726         # include <bus/usb/usbhid.h>
   727         #else
   728         # include <dev/usb/usb.h>
   729         # include <dev/usb/usbhid.h>
   730         #endif
   731         #if defined(HAVE_USBHID_H)
   732         #include <usbhid.h>
   733         #elif defined(HAVE_LIBUSB_H)
   734         #include <libusb.h>
   735         #elif defined(HAVE_LIBUSBHID_H)
   736         #include <libusbhid.h>
   737         #endif
   738         int main(int argc, char **argv) {
   739           struct report_desc *repdesc;
   740           struct usb_ctl_report *repbuf;
   741           hid_kind_t hidkind;
   742           return 0;
   743         }" HAVE_USBHID)
   744   if(HAVE_USBHID)
   745     check_c_source_compiles("
   746           #include <sys/types.h>
   747           #if defined(HAVE_USB_H)
   748           #include <usb.h>
   749           #endif
   750           #ifdef __DragonFly__
   751           # include <bus/usb/usb.h>
   752           # include <bus/usb/usbhid.h>
   753           #else
   754           # include <dev/usb/usb.h>
   755           # include <dev/usb/usbhid.h>
   756           #endif
   757           #if defined(HAVE_USBHID_H)
   758           #include <usbhid.h>
   759           #elif defined(HAVE_LIBUSB_H)
   760           #include <libusb.h>
   761           #elif defined(HAVE_LIBUSBHID_H)
   762           #include <libusbhid.h>
   763           #endif
   764           int main(int argc, char** argv) {
   765             struct usb_ctl_report buf;
   766             if (buf.ucr_data) { }
   767             return 0;
   768           }" HAVE_USBHID_UCR_DATA)
   769     if(HAVE_USBHID_UCR_DATA)
   770       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   771     endif(HAVE_USBHID_UCR_DATA)
   772 
   773     check_c_source_compiles("
   774           #include <sys/types.h>
   775           #if defined(HAVE_USB_H)
   776           #include <usb.h>
   777           #endif
   778           #ifdef __DragonFly__
   779           #include <bus/usb/usb.h>
   780           #include <bus/usb/usbhid.h>
   781           #else
   782           #include <dev/usb/usb.h>
   783           #include <dev/usb/usbhid.h>
   784           #endif
   785           #if defined(HAVE_USBHID_H)
   786           #include <usbhid.h>
   787           #elif defined(HAVE_LIBUSB_H)
   788           #include <libusb.h>
   789           #elif defined(HAVE_LIBUSBHID_H)
   790           #include <libusbhid.h>
   791           #endif
   792           int main(int argc, char **argv) {
   793             report_desc_t d;
   794             hid_start_parse(d, 1, 1);
   795             return 0;
   796           }" HAVE_USBHID_NEW)
   797     if(HAVE_USBHID_NEW)
   798       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   799     endif(HAVE_USBHID_NEW)
   800 
   801     check_c_source_compiles("
   802         #include <machine/joystick.h>
   803         int main(int argc, char** argv) {
   804             struct joystick t;
   805             return 0;
   806         }" HAVE_MACHINE_JOYSTICK)
   807     if(HAVE_MACHINE_JOYSTICK)
   808       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   809     endif(HAVE_MACHINE_JOYSTICK)
   810     set(SDL_JOYSTICK_USBHID 1)
   811     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   812     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   813     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   814     list(APPEND EXTRA_LIBS ${USB_LIBS})
   815     set(HAVE_SDL_JOYSTICK TRUE)
   816 
   817     set(CMAKE_REQUIRED_LIBRARIES)
   818     set(CMAKE_REQUIRED_FLAGS)
   819   endif(HAVE_USBHID)
   820 endmacro(CheckUSBHID)