cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Fri, 07 Oct 2016 18:03:08 -0700
changeset 10490 24472af11074
parent 10329 ad0bee16b6b9
child 10511 8e646a2d1929
permissions -rw-r--r--
Fixed bug 3043 - fix alsa configury and cmake checks

Ozkan Sezer

SDL's alsa uses snd_pcm_recover() which has been available only since alsa-lib-1.0.11.
     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()
    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()
    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()
    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()
    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()
    94       set(HAVE_SDL_AUDIO TRUE)
    95     endif()
    96   endif()
    97 endmacro()
    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_recover "" HAVE_LIBASOUND)
   109     endif()
   110     if(HAVE_LIBASOUND)
   111       set(HAVE_ALSA TRUE)
   112       file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
   113       set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
   114       set(SDL_AUDIO_DRIVER_ALSA 1)
   115       if(ALSA_SHARED)
   116         if(NOT HAVE_DLOPEN)
   117           message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
   118         else()
   119           FindLibraryAndSONAME("asound")
   120           set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
   121           set(HAVE_ALSA_SHARED TRUE)
   122         endif()
   123       else()
   124         list(APPEND EXTRA_LIBS asound)
   125       endif()
   126       set(HAVE_SDL_AUDIO TRUE)
   127     endif()
   128   endif()
   129 endmacro()
   130 
   131 # Requires:
   132 # - PkgCheckModules
   133 # Optional:
   134 # - PULSEAUDIO_SHARED opt
   135 # - HAVE_DLOPEN opt
   136 macro(CheckPulseAudio)
   137   if(PULSEAUDIO)
   138     pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
   139     if(PKG_PULSEAUDIO_FOUND)
   140       set(HAVE_PULSEAUDIO TRUE)
   141       file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
   142       set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
   143       set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
   144       list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
   145       if(PULSEAUDIO_SHARED)
   146         if(NOT HAVE_DLOPEN)
   147           message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
   148         else()
   149           FindLibraryAndSONAME("pulse-simple")
   150           set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
   151           set(HAVE_PULSEAUDIO_SHARED TRUE)
   152         endif()
   153       else()
   154         list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
   155       endif()
   156       set(HAVE_SDL_AUDIO TRUE)
   157     endif()
   158   endif()
   159 endmacro()
   160 
   161 # Requires:
   162 # - PkgCheckModules
   163 # Optional:
   164 # - ESD_SHARED opt
   165 # - HAVE_DLOPEN opt
   166 macro(CheckESD)
   167   if(ESD)
   168     pkg_check_modules(PKG_ESD esound)
   169     if(PKG_ESD_FOUND)
   170       set(HAVE_ESD TRUE)
   171       file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
   172       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
   173       set(SDL_AUDIO_DRIVER_ESD 1)
   174       list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
   175       if(ESD_SHARED)
   176         if(NOT HAVE_DLOPEN)
   177           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
   178         else()
   179           FindLibraryAndSONAME(esd)
   180           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
   181           set(HAVE_ESD_SHARED TRUE)
   182         endif()
   183       else()
   184         list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   185       endif()
   186       set(HAVE_SDL_AUDIO TRUE)
   187     endif()
   188   endif()
   189 endmacro()
   190 
   191 # Requires:
   192 # - n/a
   193 # Optional:
   194 # - ARTS_SHARED opt
   195 # - HAVE_DLOPEN opt
   196 macro(CheckARTS)
   197   if(ARTS)
   198     find_program(ARTS_CONFIG arts-config)
   199     if(ARTS_CONFIG)
   200       execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
   201         OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   202       list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
   203       execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
   204         OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
   205       file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
   206       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
   207       set(SDL_AUDIO_DRIVER_ARTS 1)
   208       set(HAVE_ARTS TRUE)
   209       if(ARTS_SHARED)
   210         if(NOT HAVE_DLOPEN)
   211           message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
   212         else()
   213           # TODO
   214           FindLibraryAndSONAME(artsc)
   215           set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
   216           set(HAVE_ARTS_SHARED TRUE)
   217         endif()
   218       else()
   219         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   220       endif()
   221       set(HAVE_SDL_AUDIO TRUE)
   222     endif()
   223   endif()
   224 endmacro()
   225 
   226 # Requires:
   227 # - n/a
   228 # Optional:
   229 # - NAS_SHARED opt
   230 # - HAVE_DLOPEN opt
   231 macro(CheckNAS)
   232   if(NAS)
   233     # TODO: set include paths properly, so the NAS headers are found
   234     check_include_file(audio/audiolib.h HAVE_NAS_H)
   235     find_library(D_NAS_LIB audio)
   236     if(HAVE_NAS_H AND D_NAS_LIB)
   237       set(HAVE_NAS TRUE)
   238       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
   239       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
   240       set(SDL_AUDIO_DRIVER_NAS 1)
   241       if(NAS_SHARED)
   242         if(NOT HAVE_DLOPEN)
   243           message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
   244         else()
   245           FindLibraryAndSONAME("audio")
   246           set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
   247           set(HAVE_NAS_SHARED TRUE)
   248         endif()
   249       else()
   250         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   251       endif()
   252       set(HAVE_SDL_AUDIO TRUE)
   253     endif()
   254   endif()
   255 endmacro()
   256 
   257 # Requires:
   258 # - n/a
   259 # Optional:
   260 # - SNDIO_SHARED opt
   261 # - HAVE_DLOPEN opt
   262 macro(CheckSNDIO)
   263   if(SNDIO)
   264     # TODO: set include paths properly, so the sndio headers are found
   265     check_include_file(sndio.h HAVE_SNDIO_H)
   266     find_library(D_SNDIO_LIB sndio)
   267     if(HAVE_SNDIO_H AND D_SNDIO_LIB)
   268       set(HAVE_SNDIO TRUE)
   269       file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
   270       set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
   271       set(SDL_AUDIO_DRIVER_SNDIO 1)
   272       if(SNDIO_SHARED)
   273         if(NOT HAVE_DLOPEN)
   274           message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
   275         else()
   276           FindLibraryAndSONAME("sndio")
   277           set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
   278           set(HAVE_SNDIO_SHARED TRUE)
   279         endif()
   280       else()
   281         list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
   282       endif()
   283       set(HAVE_SDL_AUDIO TRUE)
   284     endif()
   285   endif()
   286 endmacro()
   287 
   288 # Requires:
   289 # - PkgCheckModules
   290 # Optional:
   291 # - FUSIONSOUND_SHARED opt
   292 # - HAVE_DLOPEN opt
   293 macro(CheckFusionSound)
   294   if(FUSIONSOUND)
   295     pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
   296     if(PKG_FUSIONSOUND_FOUND)
   297       set(HAVE_FUSIONSOUND TRUE)
   298       file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
   299       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
   300       set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
   301       list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
   302       if(FUSIONSOUND_SHARED)
   303         if(NOT HAVE_DLOPEN)
   304           message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
   305         else()
   306           FindLibraryAndSONAME("fusionsound")
   307           set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
   308           set(HAVE_FUSIONSOUND_SHARED TRUE)
   309         endif()
   310       else()
   311         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   312       endif()
   313       set(HAVE_SDL_AUDIO TRUE)
   314     endif()
   315   endif()
   316 endmacro()
   317 
   318 # Requires:
   319 # - n/a
   320 # Optional:
   321 # - X11_SHARED opt
   322 # - HAVE_DLOPEN opt
   323 macro(CheckX11)
   324   if(VIDEO_X11)
   325     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   326         FindLibraryAndSONAME("${_LIB}")
   327     endforeach()
   328 
   329     find_path(X_INCLUDEDIR X11/Xlib.h)
   330     if(X_INCLUDEDIR)
   331       set(X_CFLAGS "-I${X_INCLUDEDIR}")
   332     endif()
   333 
   334     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   335     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   336     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   337     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   338     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   339     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   340     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   341     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   342     check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
   343 
   344     if(X11_LIB)
   345       if(NOT HAVE_XEXT_H)
   346         message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
   347       endif()
   348 
   349       set(HAVE_VIDEO_X11 TRUE)
   350       set(HAVE_SDL_VIDEO TRUE)
   351 
   352       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   353       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   354       set(SDL_VIDEO_DRIVER_X11 1)
   355 
   356       if(APPLE)
   357         set(X11_SHARED OFF)
   358       endif()
   359 
   360       check_function_exists("shmat" HAVE_SHMAT)
   361       if(NOT HAVE_SHMAT)
   362         check_library_exists(ipc shmat "" HAVE_SHMAT)
   363         if(HAVE_SHMAT)
   364           list(APPEND EXTRA_LIBS ipc)
   365         endif()
   366         if(NOT HAVE_SHMAT)
   367           add_definitions(-DNO_SHARED_MEMORY)
   368           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   369         endif()
   370       endif()
   371 
   372       if(X11_SHARED)
   373         if(NOT HAVE_DLOPEN)
   374           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   375           set(HAVE_X11_SHARED FALSE)
   376         else()
   377           set(HAVE_X11_SHARED TRUE)
   378         endif()
   379         if(HAVE_X11_SHARED)
   380           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
   381           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
   382         else()
   383           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   384         endif()
   385       endif()
   386 
   387       set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
   388 
   389       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   390       check_c_source_compiles("
   391           #include <X11/Xlib.h>
   392           #include <X11/Xproto.h>
   393           #include <X11/extensions/Xext.h>
   394           #include <X11/extensions/extutil.h>
   395           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   396           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   397       if(HAVE_CONST_XEXT_ADDDISPLAY)
   398         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   399       endif()
   400 
   401       check_c_source_compiles("
   402           #include <X11/Xlib.h>
   403           int main(int argc, char **argv) {
   404             Display *display;
   405             XEvent event;
   406             XGenericEventCookie *cookie = &event.xcookie;
   407             XNextEvent(display, &event);
   408             XGetEventData(display, cookie);
   409             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   410       if(HAVE_XGENERICEVENT)
   411         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   412       endif()
   413 
   414       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   415 
   416       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   417         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   418         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   419           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
   420         else()
   421           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   422         endif()
   423         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   424       endif()
   425 
   426       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   427         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   428         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   429           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
   430         else()
   431           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   432         endif()
   433         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   434       endif()
   435 
   436       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   437         set(HAVE_VIDEO_X11_XINPUT TRUE)
   438         if(HAVE_X11_SHARED AND XI_LIB)
   439           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
   440         else()
   441           list(APPEND EXTRA_LIBS ${XI_LIB})
   442         endif()
   443         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   444 
   445         # Check for multitouch
   446         check_c_source_compiles("
   447             #include <X11/Xlib.h>
   448             #include <X11/Xproto.h>
   449             #include <X11/extensions/XInput2.h>
   450             int event_type = XI_TouchBegin;
   451             XITouchClassInfo *t;
   452             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   453             {
   454               return (Status)0;
   455             }
   456             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   457         if(HAVE_XINPUT2_MULTITOUCH)
   458           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   459         endif()
   460       endif()
   461 
   462       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   463         if(HAVE_X11_SHARED AND XRANDR_LIB)
   464           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
   465         else()
   466           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   467         endif()
   468         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   469         set(HAVE_VIDEO_X11_XRANDR TRUE)
   470       endif()
   471 
   472       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   473         if(HAVE_X11_SHARED AND XSS_LIB)
   474           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
   475         else()
   476           list(APPEND EXTRA_LIBS ${XSS_LIB})
   477         endif()
   478         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   479         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   480       endif()
   481 
   482       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   483         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   484         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   485       endif()
   486 
   487       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   488         if(HAVE_X11_SHARED AND XXF86VM_LIB)
   489           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
   490         else()
   491           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   492         endif()
   493         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   494         set(HAVE_VIDEO_X11_XVM TRUE)
   495       endif()
   496 
   497       set(CMAKE_REQUIRED_LIBRARIES)
   498     endif()
   499   endif()
   500 endmacro()
   501 
   502 # Requires:
   503 # - EGL
   504 # - PkgCheckModules
   505 # Optional:
   506 # - MIR_SHARED opt
   507 # - HAVE_DLOPEN opt
   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 
   525             if(MIR_SHARED)
   526                 if(NOT HAVE_DLOPEN)
   527                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   528                 else()
   529                     FindLibraryAndSONAME(mirclient)
   530                     FindLibraryAndSONAME(xkbcommon)
   531                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   532                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   533                     set(HAVE_MIR_SHARED TRUE)
   534                 endif()
   535             else()
   536                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   537             endif()
   538         endif()
   539     endif()
   540 endmacro()
   541 
   542 # Requires:
   543 # - EGL
   544 # - PkgCheckModules
   545 # Optional:
   546 # - WAYLAND_SHARED opt
   547 # - HAVE_DLOPEN opt
   548 macro(CheckWayland)
   549   if(VIDEO_WAYLAND)
   550     pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
   551     if(WAYLAND_FOUND)
   552       link_directories(
   553           ${WAYLAND_LIBRARY_DIRS}
   554       )
   555       include_directories(
   556           ${WAYLAND_INCLUDE_DIRS}
   557       )
   558       set(HAVE_VIDEO_WAYLAND TRUE)
   559       set(HAVE_SDL_VIDEO TRUE)
   560 
   561       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   562       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   563 
   564       if(VIDEO_WAYLAND_QT_TOUCH)
   565           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   566       endif()
   567 
   568       if(WAYLAND_SHARED)
   569         if(NOT HAVE_DLOPEN)
   570           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   571         else()
   572           FindLibraryAndSONAME(wayland-client)
   573           FindLibraryAndSONAME(wayland-egl)
   574           FindLibraryAndSONAME(wayland-cursor)
   575           FindLibraryAndSONAME(xkbcommon)
   576           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   577           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   578           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   579           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   580           set(HAVE_WAYLAND_SHARED TRUE)
   581         endif()
   582       else()
   583         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   584       endif()
   585 
   586       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   587     endif()
   588   endif()
   589 endmacro()
   590 
   591 # Requires:
   592 # - n/a
   593 #
   594 macro(CheckCOCOA)
   595   if(VIDEO_COCOA)
   596     if(APPLE) # Apple always has Cocoa.
   597       set(HAVE_VIDEO_COCOA TRUE)
   598     endif()
   599     if(HAVE_VIDEO_COCOA)
   600       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   601       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   602       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   603       set(SDL_VIDEO_DRIVER_COCOA 1)
   604       set(HAVE_SDL_VIDEO TRUE)
   605     endif()
   606   endif()
   607 endmacro()
   608 
   609 # Requires:
   610 # - PkgCheckModules
   611 # Optional:
   612 # - DIRECTFB_SHARED opt
   613 # - HAVE_DLOPEN opt
   614 macro(CheckDirectFB)
   615   if(VIDEO_DIRECTFB)
   616     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   617     if(PKG_DIRECTFB_FOUND)
   618       set(HAVE_VIDEO_DIRECTFB TRUE)
   619       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   620       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   621       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   622       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   623       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   624       if(DIRECTFB_SHARED)
   625         if(NOT HAVE_DLOPEN)
   626           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   627         else()
   628           FindLibraryAndSONAME("directfb")
   629           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   630           set(HAVE_DIRECTFB_SHARED TRUE)
   631         endif()
   632       else()
   633         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   634       endif()
   635       set(HAVE_SDL_VIDEO TRUE)
   636     endif()
   637   endif()
   638 endmacro()
   639 
   640 # Requires:
   641 # - n/a
   642 macro(CheckVivante)
   643   if(VIDEO_VIVANTE)
   644     check_c_source_compiles("
   645         #include <gc_vdk.h>
   646         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   647     check_c_source_compiles("
   648         #define LINUX
   649         #define EGL_API_FB
   650         #include <EGL/eglvivante.h>
   651         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   652     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   653       set(HAVE_VIDEO_VIVANTE TRUE)
   654       set(HAVE_SDL_VIDEO TRUE)
   655 
   656       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   657       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   658       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   659       if(HAVE_VIDEO_VIVANTE_VDK)
   660         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   661         list(APPEND EXTRA_LIBS VDK VIVANTE)
   662       else()
   663         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   664         list(APPEND EXTRA_LIBS EGL)
   665       endif(HAVE_VIDEO_VIVANTE_VDK)
   666     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   667   endif(VIDEO_VIVANTE)
   668 endmacro(CheckVivante)
   669 
   670 # Requires:
   671 # - nada
   672 macro(CheckOpenGLX11)
   673   if(VIDEO_OPENGL)
   674     check_c_source_compiles("
   675         #include <GL/gl.h>
   676         #include <GL/glx.h>
   677         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   678 
   679     if(HAVE_VIDEO_OPENGL)
   680       set(HAVE_VIDEO_OPENGL TRUE)
   681       set(SDL_VIDEO_OPENGL 1)
   682       set(SDL_VIDEO_OPENGL_GLX 1)
   683       set(SDL_VIDEO_RENDER_OGL 1)
   684     endif()
   685   endif()
   686 endmacro()
   687 
   688 # Requires:
   689 # - nada
   690 macro(CheckOpenGLESX11)
   691   if(VIDEO_OPENGLES)
   692     check_c_source_compiles("
   693         #define EGL_API_FB
   694         #include <EGL/egl.h>
   695         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   696     if(HAVE_VIDEO_OPENGL_EGL)
   697         set(SDL_VIDEO_OPENGL_EGL 1)
   698     endif()
   699     check_c_source_compiles("
   700       #include <GLES/gl.h>
   701       #include <GLES/glext.h>
   702       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   703     if(HAVE_VIDEO_OPENGLES_V1)
   704         set(HAVE_VIDEO_OPENGLES TRUE)
   705         set(SDL_VIDEO_OPENGL_ES 1)
   706         set(SDL_VIDEO_RENDER_OGL_ES 1)
   707     endif()
   708     check_c_source_compiles("
   709       #include <GLES2/gl2.h>
   710       #include <GLES2/gl2ext.h>
   711       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   712     if(HAVE_VIDEO_OPENGLES_V2)
   713         set(HAVE_VIDEO_OPENGLES TRUE)
   714         set(SDL_VIDEO_OPENGL_ES2 1)
   715         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   716     endif()
   717 
   718   endif()
   719 endmacro()
   720 
   721 # Requires:
   722 # - nada
   723 # Optional:
   724 # - THREADS opt
   725 # Sets:
   726 # PTHREAD_CFLAGS
   727 # PTHREAD_LIBS
   728 macro(CheckPTHREAD)
   729   if(PTHREADS)
   730     if(LINUX)
   731       set(PTHREAD_CFLAGS "-D_REENTRANT")
   732       set(PTHREAD_LDFLAGS "-pthread")
   733     elseif(BSDI)
   734       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   735       set(PTHREAD_LDFLAGS "")
   736     elseif(DARWIN)
   737       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   738       # causes Carbon.p complaints?
   739       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   740       set(PTHREAD_LDFLAGS "")
   741     elseif(FREEBSD)
   742       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   743       set(PTHREAD_LDFLAGS "-pthread")
   744     elseif(NETBSD)
   745       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   746       set(PTHREAD_LDFLAGS "-lpthread")
   747     elseif(OPENBSD)
   748       set(PTHREAD_CFLAGS "-D_REENTRANT")
   749       set(PTHREAD_LDFLAGS "-pthread")
   750     elseif(SOLARIS)
   751       set(PTHREAD_CFLAGS "-D_REENTRANT")
   752       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   753     elseif(SYSV5)
   754       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   755       set(PTHREAD_LDFLAGS "")
   756     elseif(AIX)
   757       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   758       set(PTHREAD_LDFLAGS "-pthread")
   759     elseif(HPUX)
   760       set(PTHREAD_CFLAGS "-D_REENTRANT")
   761       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   762     elseif(HAIKU)
   763       set(PTHREAD_CFLAGS "-D_REENTRANT")
   764       set(PTHREAD_LDFLAGS "")
   765     else()
   766       set(PTHREAD_CFLAGS "-D_REENTRANT")
   767       set(PTHREAD_LDFLAGS "-lpthread")
   768     endif()
   769 
   770     # Run some tests
   771     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   772     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   773     if(CMAKE_CROSSCOMPILING)
   774       set(HAVE_PTHREADS 1)
   775     else()
   776       check_c_source_runs("
   777         #include <pthread.h>
   778         int main(int argc, char** argv) {
   779           pthread_attr_t type;
   780           pthread_attr_init(&type);
   781           return 0;
   782         }" HAVE_PTHREADS)
   783     endif()
   784     if(HAVE_PTHREADS)
   785       set(SDL_THREAD_PTHREAD 1)
   786       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   787       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   788       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   789       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   790 
   791       check_c_source_compiles("
   792         #include <pthread.h>
   793         int main(int argc, char **argv) {
   794           pthread_mutexattr_t attr;
   795           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   796           return 0;
   797         }" HAVE_RECURSIVE_MUTEXES)
   798       if(HAVE_RECURSIVE_MUTEXES)
   799         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   800       else()
   801         check_c_source_compiles("
   802             #include <pthread.h>
   803             int main(int argc, char **argv) {
   804               pthread_mutexattr_t attr;
   805               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   806               return 0;
   807             }" HAVE_RECURSIVE_MUTEXES_NP)
   808         if(HAVE_RECURSIVE_MUTEXES_NP)
   809           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   810         endif()
   811       endif()
   812 
   813       if(PTHREADS_SEM)
   814         check_c_source_compiles("#include <pthread.h>
   815                                  #include <semaphore.h>
   816                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   817         if(HAVE_PTHREADS_SEM)
   818           check_c_source_compiles("
   819               #include <pthread.h>
   820               #include <semaphore.h>
   821               int main(int argc, char **argv) {
   822                   sem_timedwait(NULL, NULL);
   823                   return 0;
   824               }" HAVE_SEM_TIMEDWAIT)
   825         endif()
   826       endif()
   827 
   828       check_c_source_compiles("
   829           #include <pthread.h>
   830           #include <pthread_np.h>
   831           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   832       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   833       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   834       set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
   835 
   836       set(SOURCE_FILES ${SOURCE_FILES}
   837           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   838           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   839           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   840           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   841           )
   842       if(HAVE_PTHREADS_SEM)
   843         set(SOURCE_FILES ${SOURCE_FILES}
   844             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   845       else()
   846         set(SOURCE_FILES ${SOURCE_FILES}
   847             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   848       endif()
   849       set(HAVE_SDL_THREADS TRUE)
   850     endif()
   851   endif()
   852 endmacro()
   853 
   854 # Requires
   855 # - nada
   856 # Optional:
   857 # Sets:
   858 # USB_LIBS
   859 # USB_CFLAGS
   860 macro(CheckUSBHID)
   861   check_library_exists(usbhid hid_init "" LIBUSBHID)
   862   if(LIBUSBHID)
   863     check_include_file(usbhid.h HAVE_USBHID_H)
   864     if(HAVE_USBHID_H)
   865       set(USB_CFLAGS "-DHAVE_USBHID_H")
   866     endif()
   867 
   868     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   869     if(HAVE_LIBUSBHID_H)
   870       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   871     endif()
   872     set(USB_LIBS ${USB_LIBS} usbhid)
   873   else()
   874     check_include_file(usb.h HAVE_USB_H)
   875     if(HAVE_USB_H)
   876       set(USB_CFLAGS "-DHAVE_USB_H")
   877     endif()
   878     check_include_file(libusb.h HAVE_LIBUSB_H)
   879     if(HAVE_LIBUSB_H)
   880       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   881     endif()
   882     check_library_exists(usb hid_init "" LIBUSB)
   883     if(LIBUSB)
   884       set(USB_LIBS ${USB_LIBS} usb)
   885     endif()
   886   endif()
   887 
   888   set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   889   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
   890   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   891   check_c_source_compiles("
   892        #include <sys/types.h>
   893         #if defined(HAVE_USB_H)
   894         #include <usb.h>
   895         #endif
   896         #ifdef __DragonFly__
   897         # include <bus/usb/usb.h>
   898         # include <bus/usb/usbhid.h>
   899         #else
   900         # include <dev/usb/usb.h>
   901         # include <dev/usb/usbhid.h>
   902         #endif
   903         #if defined(HAVE_USBHID_H)
   904         #include <usbhid.h>
   905         #elif defined(HAVE_LIBUSB_H)
   906         #include <libusb.h>
   907         #elif defined(HAVE_LIBUSBHID_H)
   908         #include <libusbhid.h>
   909         #endif
   910         int main(int argc, char **argv) {
   911           struct report_desc *repdesc;
   912           struct usb_ctl_report *repbuf;
   913           hid_kind_t hidkind;
   914           return 0;
   915         }" HAVE_USBHID)
   916   if(HAVE_USBHID)
   917     check_c_source_compiles("
   918           #include <sys/types.h>
   919           #if defined(HAVE_USB_H)
   920           #include <usb.h>
   921           #endif
   922           #ifdef __DragonFly__
   923           # include <bus/usb/usb.h>
   924           # include <bus/usb/usbhid.h>
   925           #else
   926           # include <dev/usb/usb.h>
   927           # include <dev/usb/usbhid.h>
   928           #endif
   929           #if defined(HAVE_USBHID_H)
   930           #include <usbhid.h>
   931           #elif defined(HAVE_LIBUSB_H)
   932           #include <libusb.h>
   933           #elif defined(HAVE_LIBUSBHID_H)
   934           #include <libusbhid.h>
   935           #endif
   936           int main(int argc, char** argv) {
   937             struct usb_ctl_report buf;
   938             if (buf.ucr_data) { }
   939             return 0;
   940           }" HAVE_USBHID_UCR_DATA)
   941     if(HAVE_USBHID_UCR_DATA)
   942       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   943     endif()
   944 
   945     check_c_source_compiles("
   946           #include <sys/types.h>
   947           #if defined(HAVE_USB_H)
   948           #include <usb.h>
   949           #endif
   950           #ifdef __DragonFly__
   951           #include <bus/usb/usb.h>
   952           #include <bus/usb/usbhid.h>
   953           #else
   954           #include <dev/usb/usb.h>
   955           #include <dev/usb/usbhid.h>
   956           #endif
   957           #if defined(HAVE_USBHID_H)
   958           #include <usbhid.h>
   959           #elif defined(HAVE_LIBUSB_H)
   960           #include <libusb.h>
   961           #elif defined(HAVE_LIBUSBHID_H)
   962           #include <libusbhid.h>
   963           #endif
   964           int main(int argc, char **argv) {
   965             report_desc_t d;
   966             hid_start_parse(d, 1, 1);
   967             return 0;
   968           }" HAVE_USBHID_NEW)
   969     if(HAVE_USBHID_NEW)
   970       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   971     endif()
   972 
   973     check_c_source_compiles("
   974         #include <machine/joystick.h>
   975         int main(int argc, char** argv) {
   976             struct joystick t;
   977             return 0;
   978         }" HAVE_MACHINE_JOYSTICK)
   979     if(HAVE_MACHINE_JOYSTICK)
   980       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   981     endif()
   982     set(SDL_JOYSTICK_USBHID 1)
   983     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   984     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   985     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   986     list(APPEND EXTRA_LIBS ${USB_LIBS})
   987     set(HAVE_SDL_JOYSTICK TRUE)
   988 
   989     set(CMAKE_REQUIRED_LIBRARIES)
   990     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
   991   endif()
   992 endmacro()
   993 
   994 # Requires:
   995 # - n/a
   996 macro(CheckRPI)
   997   if(VIDEO_RPI)
   998     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
   999     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1000     set(VIDEO_RPI_LIBS bcm_host )
  1001     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1002     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1003 
  1004     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1005     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1006     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1007     check_c_source_compiles("
  1008         #include <bcm_host.h>
  1009         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1010     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1011     set(CMAKE_REQUIRED_LIBRARIES)
  1012 
  1013     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1014       set(HAVE_SDL_VIDEO TRUE)
  1015       set(SDL_VIDEO_DRIVER_RPI 1)
  1016       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1017       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1018       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1019       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1020     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1021   endif(VIDEO_RPI)
  1022 endmacro(CheckRPI)