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