cmake/sdlchecks.cmake
author Ryan C. Gordon <icculus@icculus.org>
Mon, 08 Jun 2015 01:13:51 -0400
changeset 9718 d5955671f259
parent 9415 93547cc94383
child 10005 dea345d3b00a
permissions -rw-r--r--
configure/cmake/x11: Removed SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 test.

This was the only thing that made SDL_config.h generate differently between
32 and 64-bit versions of Linux, so instead we force a function cast in our
X11 code to match our dynamic loader version, which removes the compile error
on some machines that prompted this test in the first place.

Xlib never wrote to this data, so if you're on an older Xlib where this param
wasn't const, your data should still be intact when we force the caller to
think it was actually const after all.

Fixes Bugzilla #1893.
     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_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()
   121       else()
   122         list(APPEND EXTRA_LIBS asound)
   123       endif()
   124       set(HAVE_SDL_AUDIO TRUE)
   125     endif()
   126   endif()
   127 endmacro()
   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()
   151       else()
   152         list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
   153       endif()
   154       set(HAVE_SDL_AUDIO TRUE)
   155     endif()
   156   endif()
   157 endmacro()
   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()
   181       else()
   182         list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   183       endif()
   184       set(HAVE_SDL_AUDIO TRUE)
   185     endif()
   186   endif()
   187 endmacro()
   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()
   216       else()
   217         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   218       endif()
   219       set(HAVE_SDL_AUDIO TRUE)
   220     endif()
   221   endif()
   222 endmacro()
   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()
   247       else()
   248         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   249       endif()
   250       set(HAVE_SDL_AUDIO TRUE)
   251     endif()
   252   endif()
   253 endmacro()
   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()
   278       else()
   279         list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
   280       endif()
   281       set(HAVE_SDL_AUDIO TRUE)
   282     endif()
   283   endif()
   284 endmacro()
   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()
   308       else()
   309         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   310       endif()
   311       set(HAVE_SDL_AUDIO TRUE)
   312     endif()
   313   endif()
   314 endmacro()
   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()
   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()
   364         if(NOT HAVE_SHMAT)
   365           add_definitions(-DNO_SHARED_MEMORY)
   366           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   367         endif()
   368       endif()
   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()
   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()
   381           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   382         endif()
   383       endif()
   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()
   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()
   411 
   412       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   413 
   414       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   415         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   416         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   417           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
   418         else()
   419           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   420         endif()
   421         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   422       endif()
   423 
   424       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   425         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   426         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   427           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
   428         else()
   429           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   430         endif()
   431         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   432       endif()
   433 
   434       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   435         set(HAVE_VIDEO_X11_XINPUT TRUE)
   436         if(HAVE_X11_SHARED AND XI_LIB)
   437           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
   438         else()
   439           list(APPEND EXTRA_LIBS ${XI_LIB})
   440         endif()
   441         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   442 
   443         # Check for multitouch
   444         check_c_source_compiles("
   445             #include <X11/Xlib.h>
   446             #include <X11/Xproto.h>
   447             #include <X11/extensions/XInput2.h>
   448             int event_type = XI_TouchBegin;
   449             XITouchClassInfo *t;
   450             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   451             {
   452               return (Status)0;
   453             }
   454             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   455         if(HAVE_XINPUT2_MULTITOUCH)
   456           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   457         endif()
   458       endif()
   459 
   460       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   461         if(HAVE_X11_SHARED AND XRANDR_LIB)
   462           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
   463         else()
   464           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   465         endif()
   466         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   467         set(HAVE_VIDEO_X11_XRANDR TRUE)
   468       endif()
   469 
   470       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   471         if(HAVE_X11_SHARED AND XSS_LIB)
   472           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
   473         else()
   474           list(APPEND EXTRA_LIBS ${XSS_LIB})
   475         endif()
   476         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   477         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   478       endif()
   479 
   480       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   481         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   482         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   483       endif()
   484 
   485       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   486         if(HAVE_X11_SHARED AND XXF86VM_LIB)
   487           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
   488         else()
   489           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   490         endif()
   491         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   492         set(HAVE_VIDEO_X11_XVM TRUE)
   493       endif()
   494 
   495       set(CMAKE_REQUIRED_LIBRARIES)
   496     endif()
   497   endif()
   498 endmacro()
   499 
   500 # Requires:
   501 # - EGL
   502 # - PkgCheckModules
   503 # Optional:
   504 # - MIR_SHARED opt
   505 # - HAVE_DLOPEN opt
   506 macro(CheckMir)
   507     if(VIDEO_MIR)
   508         find_library(MIR_LIB mirclient mircommon egl)
   509         pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
   510         pkg_check_modules(EGL egl)
   511         pkg_check_modules(XKB xkbcommon)
   512 
   513         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   514             set(HAVE_VIDEO_MIR TRUE)
   515             set(HAVE_SDL_VIDEO TRUE)
   516 
   517             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   518             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   519             set(SDL_VIDEO_DRIVER_MIR 1)
   520 
   521             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
   522 
   523             if(MIR_SHARED)
   524                 if(NOT HAVE_DLOPEN)
   525                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   526                 else()
   527                     FindLibraryAndSONAME(mirclient)
   528                     FindLibraryAndSONAME(xkbcommon)
   529                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   530                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   531                     set(HAVE_MIR_SHARED TRUE)
   532                 endif()
   533             else()
   534                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   535             endif()
   536         endif()
   537     endif()
   538 endmacro()
   539 
   540 # Requires:
   541 # - EGL
   542 # - PkgCheckModules
   543 # Optional:
   544 # - WAYLAND_SHARED opt
   545 # - HAVE_DLOPEN opt
   546 macro(CheckWayland)
   547   if(VIDEO_WAYLAND)
   548     pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
   549     if(WAYLAND_FOUND)
   550       link_directories(
   551           ${WAYLAND_LIBRARY_DIRS}
   552       )
   553       include_directories(
   554           ${WAYLAND_INCLUDE_DIRS}
   555       )
   556       set(HAVE_VIDEO_WAYLAND TRUE)
   557       set(HAVE_SDL_VIDEO TRUE)
   558 
   559       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   560       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   561 
   562       if(VIDEO_WAYLAND_QT_TOUCH)
   563           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   564       endif()
   565 
   566       if(WAYLAND_SHARED)
   567         if(NOT HAVE_DLOPEN)
   568           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   569         else()
   570           FindLibraryAndSONAME(wayland-client)
   571           FindLibraryAndSONAME(wayland-egl)
   572           FindLibraryAndSONAME(wayland-cursor)
   573           FindLibraryAndSONAME(xkbcommon)
   574           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   575           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   576           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   577           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   578           set(HAVE_WAYLAND_SHARED TRUE)
   579         endif()
   580       else()
   581         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   582       endif()
   583 
   584       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   585     endif()
   586   endif()
   587 endmacro()
   588 
   589 # Requires:
   590 # - n/a
   591 #
   592 macro(CheckCOCOA)
   593   if(VIDEO_COCOA)
   594     if(APPLE) # Apple always has Cocoa.
   595       set(HAVE_VIDEO_COCOA TRUE)
   596     endif()
   597     if(HAVE_VIDEO_COCOA)
   598       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   599       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   600       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   601       set(SDL_VIDEO_DRIVER_COCOA 1)
   602       set(HAVE_SDL_VIDEO TRUE)
   603     endif()
   604   endif()
   605 endmacro()
   606 
   607 # Requires:
   608 # - PkgCheckModules
   609 # Optional:
   610 # - DIRECTFB_SHARED opt
   611 # - HAVE_DLOPEN opt
   612 macro(CheckDirectFB)
   613   if(VIDEO_DIRECTFB)
   614     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   615     if(PKG_DIRECTFB_FOUND)
   616       set(HAVE_VIDEO_DIRECTFB TRUE)
   617       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   618       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   619       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   620       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   621       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   622       if(DIRECTFB_SHARED)
   623         if(NOT HAVE_DLOPEN)
   624           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   625         else()
   626           FindLibraryAndSONAME("directfb")
   627           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   628           set(HAVE_DIRECTFB_SHARED TRUE)
   629         endif()
   630       else()
   631         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   632       endif()
   633       set(HAVE_SDL_VIDEO TRUE)
   634     endif()
   635   endif()
   636 endmacro()
   637 
   638 # Requires:
   639 # - n/a
   640 macro(CheckVivante)
   641   if(VIDEO_VIVANTE)
   642     check_c_source_compiles("
   643         #include <gc_vdk.h>
   644         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   645     check_c_source_compiles("
   646         #define LINUX
   647         #define EGL_API_FB
   648         #include <EGL/eglvivante.h>
   649         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   650     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   651       set(HAVE_VIDEO_VIVANTE TRUE)
   652       set(HAVE_SDL_VIDEO TRUE)
   653 
   654       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   655       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   656       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   657       if(HAVE_VIDEO_VIVANTE_VDK)
   658         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   659         list(APPEND EXTRA_LIBS VDK VIVANTE)
   660       else()
   661         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   662         list(APPEND EXTRA_LIBS EGL)
   663       endif(HAVE_VIDEO_VIVANTE_VDK)
   664     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   665   endif(VIDEO_VIVANTE)
   666 endmacro(CheckVivante)
   667 
   668 # Requires:
   669 # - nada
   670 macro(CheckOpenGLX11)
   671   if(VIDEO_OPENGL)
   672     check_c_source_compiles("
   673         #include <GL/gl.h>
   674         #include <GL/glx.h>
   675         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   676 
   677     if(HAVE_VIDEO_OPENGL)
   678       set(HAVE_VIDEO_OPENGL TRUE)
   679       set(SDL_VIDEO_OPENGL 1)
   680       set(SDL_VIDEO_OPENGL_GLX 1)
   681       set(SDL_VIDEO_RENDER_OGL 1)
   682       list(APPEND EXTRA_LIBS GL)
   683     endif()
   684   endif()
   685 endmacro()
   686 
   687 # Requires:
   688 # - nada
   689 macro(CheckOpenGLESX11)
   690   if(VIDEO_OPENGLES)
   691     check_c_source_compiles("
   692         #define EGL_API_FB
   693         #include <EGL/egl.h>
   694         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   695     if(HAVE_VIDEO_OPENGL_EGL)
   696         set(SDL_VIDEO_OPENGL_EGL 1)
   697     endif()
   698     check_c_source_compiles("
   699       #include <GLES/gl.h>
   700       #include <GLES/glext.h>
   701       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   702     if(HAVE_VIDEO_OPENGLES_V1)
   703         set(HAVE_VIDEO_OPENGLES TRUE)
   704         set(SDL_VIDEO_OPENGL_ES 1)
   705         set(SDL_VIDEO_RENDER_OGL_ES 1)
   706     endif()
   707     check_c_source_compiles("
   708       #include <GLES2/gl2.h>
   709       #include <GLES2/gl2ext.h>
   710       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   711     if(HAVE_VIDEO_OPENGLES_V2)
   712         set(HAVE_VIDEO_OPENGLES TRUE)
   713         set(SDL_VIDEO_OPENGL_ES2 1)
   714         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   715     endif()
   716 
   717   endif()
   718 endmacro()
   719 
   720 # Requires:
   721 # - nada
   722 # Optional:
   723 # - THREADS opt
   724 # Sets:
   725 # PTHREAD_CFLAGS
   726 # PTHREAD_LIBS
   727 macro(CheckPTHREAD)
   728   if(PTHREADS)
   729     if(LINUX)
   730       set(PTHREAD_CFLAGS "-D_REENTRANT")
   731       set(PTHREAD_LDFLAGS "-pthread")
   732     elseif(BSDI)
   733       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   734       set(PTHREAD_LDFLAGS "")
   735     elseif(DARWIN)
   736       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   737       # causes Carbon.p complaints?
   738       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   739       set(PTHREAD_LDFLAGS "")
   740     elseif(FREEBSD)
   741       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   742       set(PTHREAD_LDFLAGS "-pthread")
   743     elseif(NETBSD)
   744       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   745       set(PTHREAD_LDFLAGS "-lpthread")
   746     elseif(OPENBSD)
   747       set(PTHREAD_CFLAGS "-D_REENTRANT")
   748       set(PTHREAD_LDFLAGS "-pthread")
   749     elseif(SOLARIS)
   750       set(PTHREAD_CFLAGS "-D_REENTRANT")
   751       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   752     elseif(SYSV5)
   753       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   754       set(PTHREAD_LDFLAGS "")
   755     elseif(AIX)
   756       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   757       set(PTHREAD_LDFLAGS "-pthread")
   758     elseif(HPUX)
   759       set(PTHREAD_CFLAGS "-D_REENTRANT")
   760       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   761     elseif(HAIKU)
   762       set(PTHREAD_CFLAGS "-D_REENTRANT")
   763       set(PTHREAD_LDFLAGS "")
   764     else()
   765       set(PTHREAD_CFLAGS "-D_REENTRANT")
   766       set(PTHREAD_LDFLAGS "-lpthread")
   767     endif()
   768 
   769     # Run some tests
   770     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   771     if(CMAKE_CROSSCOMPILING)
   772       set(HAVE_PTHREADS 1)
   773     else()
   774       check_c_source_runs("
   775         #include <pthread.h>
   776         int main(int argc, char** argv) {
   777           pthread_attr_t type;
   778           pthread_attr_init(&type);
   779           return 0;
   780         }" HAVE_PTHREADS)
   781     endif()
   782     if(HAVE_PTHREADS)
   783       set(SDL_THREAD_PTHREAD 1)
   784       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   785       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   786       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   787       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   788 
   789       check_c_source_compiles("
   790         #include <pthread.h>
   791         int main(int argc, char **argv) {
   792           pthread_mutexattr_t attr;
   793           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   794           return 0;
   795         }" HAVE_RECURSIVE_MUTEXES)
   796       if(HAVE_RECURSIVE_MUTEXES)
   797         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   798       else()
   799         check_c_source_compiles("
   800             #include <pthread.h>
   801             int main(int argc, char **argv) {
   802               pthread_mutexattr_t attr;
   803               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   804               return 0;
   805             }" HAVE_RECURSIVE_MUTEXES_NP)
   806         if(HAVE_RECURSIVE_MUTEXES_NP)
   807           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   808         endif()
   809       endif()
   810 
   811       if(PTHREADS_SEM)
   812         check_c_source_compiles("#include <pthread.h>
   813                                  #include <semaphore.h>
   814                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   815         if(HAVE_PTHREADS_SEM)
   816           check_c_source_compiles("
   817               #include <pthread.h>
   818               #include <semaphore.h>
   819               int main(int argc, char **argv) {
   820                   sem_timedwait(NULL, NULL);
   821                   return 0;
   822               }" HAVE_SEM_TIMEDWAIT)
   823         endif()
   824       endif()
   825 
   826       check_c_source_compiles("
   827           #include <pthread.h>
   828           #include <pthread_np.h>
   829           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   830       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   831       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   832       set(CMAKE_REQUIRED_FLAGS)
   833 
   834       set(SOURCE_FILES ${SOURCE_FILES}
   835           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   836           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   837           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   838           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   839           )
   840       if(HAVE_PTHREADS_SEM)
   841         set(SOURCE_FILES ${SOURCE_FILES}
   842             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   843       else()
   844         set(SOURCE_FILES ${SOURCE_FILES}
   845             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   846       endif()
   847       set(HAVE_SDL_THREADS TRUE)
   848     endif()
   849   endif()
   850 endmacro()
   851 
   852 # Requires
   853 # - nada
   854 # Optional:
   855 # Sets:
   856 # USB_LIBS
   857 # USB_CFLAGS
   858 macro(CheckUSBHID)
   859   check_library_exists(usbhid hid_init "" LIBUSBHID)
   860   if(LIBUSBHID)
   861     check_include_file(usbhid.h HAVE_USBHID_H)
   862     if(HAVE_USBHID_H)
   863       set(USB_CFLAGS "-DHAVE_USBHID_H")
   864     endif()
   865 
   866     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   867     if(HAVE_LIBUSBHID_H)
   868       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   869     endif()
   870     set(USB_LIBS ${USB_LIBS} usbhid)
   871   else()
   872     check_include_file(usb.h HAVE_USB_H)
   873     if(HAVE_USB_H)
   874       set(USB_CFLAGS "-DHAVE_USB_H")
   875     endif()
   876     check_include_file(libusb.h HAVE_LIBUSB_H)
   877     if(HAVE_LIBUSB_H)
   878       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   879     endif()
   880     check_library_exists(usb hid_init "" LIBUSB)
   881     if(LIBUSB)
   882       set(USB_LIBS ${USB_LIBS} usb)
   883     endif()
   884   endif()
   885 
   886   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   887   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   888   check_c_source_compiles("
   889        #include <sys/types.h>
   890         #if defined(HAVE_USB_H)
   891         #include <usb.h>
   892         #endif
   893         #ifdef __DragonFly__
   894         # include <bus/usb/usb.h>
   895         # include <bus/usb/usbhid.h>
   896         #else
   897         # include <dev/usb/usb.h>
   898         # include <dev/usb/usbhid.h>
   899         #endif
   900         #if defined(HAVE_USBHID_H)
   901         #include <usbhid.h>
   902         #elif defined(HAVE_LIBUSB_H)
   903         #include <libusb.h>
   904         #elif defined(HAVE_LIBUSBHID_H)
   905         #include <libusbhid.h>
   906         #endif
   907         int main(int argc, char **argv) {
   908           struct report_desc *repdesc;
   909           struct usb_ctl_report *repbuf;
   910           hid_kind_t hidkind;
   911           return 0;
   912         }" HAVE_USBHID)
   913   if(HAVE_USBHID)
   914     check_c_source_compiles("
   915           #include <sys/types.h>
   916           #if defined(HAVE_USB_H)
   917           #include <usb.h>
   918           #endif
   919           #ifdef __DragonFly__
   920           # include <bus/usb/usb.h>
   921           # include <bus/usb/usbhid.h>
   922           #else
   923           # include <dev/usb/usb.h>
   924           # include <dev/usb/usbhid.h>
   925           #endif
   926           #if defined(HAVE_USBHID_H)
   927           #include <usbhid.h>
   928           #elif defined(HAVE_LIBUSB_H)
   929           #include <libusb.h>
   930           #elif defined(HAVE_LIBUSBHID_H)
   931           #include <libusbhid.h>
   932           #endif
   933           int main(int argc, char** argv) {
   934             struct usb_ctl_report buf;
   935             if (buf.ucr_data) { }
   936             return 0;
   937           }" HAVE_USBHID_UCR_DATA)
   938     if(HAVE_USBHID_UCR_DATA)
   939       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   940     endif()
   941 
   942     check_c_source_compiles("
   943           #include <sys/types.h>
   944           #if defined(HAVE_USB_H)
   945           #include <usb.h>
   946           #endif
   947           #ifdef __DragonFly__
   948           #include <bus/usb/usb.h>
   949           #include <bus/usb/usbhid.h>
   950           #else
   951           #include <dev/usb/usb.h>
   952           #include <dev/usb/usbhid.h>
   953           #endif
   954           #if defined(HAVE_USBHID_H)
   955           #include <usbhid.h>
   956           #elif defined(HAVE_LIBUSB_H)
   957           #include <libusb.h>
   958           #elif defined(HAVE_LIBUSBHID_H)
   959           #include <libusbhid.h>
   960           #endif
   961           int main(int argc, char **argv) {
   962             report_desc_t d;
   963             hid_start_parse(d, 1, 1);
   964             return 0;
   965           }" HAVE_USBHID_NEW)
   966     if(HAVE_USBHID_NEW)
   967       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   968     endif()
   969 
   970     check_c_source_compiles("
   971         #include <machine/joystick.h>
   972         int main(int argc, char** argv) {
   973             struct joystick t;
   974             return 0;
   975         }" HAVE_MACHINE_JOYSTICK)
   976     if(HAVE_MACHINE_JOYSTICK)
   977       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   978     endif()
   979     set(SDL_JOYSTICK_USBHID 1)
   980     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   981     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   982     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   983     list(APPEND EXTRA_LIBS ${USB_LIBS})
   984     set(HAVE_SDL_JOYSTICK TRUE)
   985 
   986     set(CMAKE_REQUIRED_LIBRARIES)
   987     set(CMAKE_REQUIRED_FLAGS)
   988   endif()
   989 endmacro()
   990 
   991 # Requires:
   992 # - n/a
   993 macro(CheckRPI)
   994   if(VIDEO_RPI)
   995     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
   996     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
   997     set(VIDEO_RPI_LIBS bcm_host )
   998     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
   999     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1000 
  1001     set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1002     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1003     check_c_source_compiles("
  1004         #include <bcm_host.h>
  1005         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1006     set(CMAKE_REQUIRED_FLAGS)
  1007     set(CMAKE_REQUIRED_LIBRARIES)
  1008 
  1009     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1010       set(HAVE_SDL_VIDEO TRUE)
  1011       set(SDL_VIDEO_DRIVER_RPI 1)
  1012       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1013       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1014       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1015       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1016     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1017   endif(VIDEO_RPI)
  1018 endmacro(CheckRPI)