cmake/sdlchecks.cmake
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Mon, 18 May 2015 21:21:14 +0200
changeset 9607 7746ab058d12
parent 9415 93547cc94383
child 9718 d5955671f259
permissions -rw-r--r--
Added missing loop cancel for Emscripten in test programs.
     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_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()
   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()
   427           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   428         endif()
   429         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   430       endif()
   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()
   437           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   438         endif()
   439         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   440       endif()
   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()
   447           list(APPEND EXTRA_LIBS ${XI_LIB})
   448         endif()
   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()
   466       endif()
   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()
   472           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   473         endif()
   474         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   475         set(HAVE_VIDEO_X11_XRANDR TRUE)
   476       endif()
   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()
   482           list(APPEND EXTRA_LIBS ${XSS_LIB})
   483         endif()
   484         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   485         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   486       endif()
   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()
   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()
   497           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   498         endif()
   499         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   500         set(HAVE_VIDEO_X11_XVM TRUE)
   501       endif()
   502 
   503       set(CMAKE_REQUIRED_LIBRARIES)
   504     endif()
   505   endif()
   506 endmacro()
   507 
   508 # Requires:
   509 # - EGL
   510 # - PkgCheckModules
   511 # Optional:
   512 # - MIR_SHARED opt
   513 # - HAVE_DLOPEN opt
   514 macro(CheckMir)
   515     if(VIDEO_MIR)
   516         find_library(MIR_LIB mirclient mircommon egl)
   517         pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
   518         pkg_check_modules(EGL egl)
   519         pkg_check_modules(XKB xkbcommon)
   520 
   521         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   522             set(HAVE_VIDEO_MIR TRUE)
   523             set(HAVE_SDL_VIDEO TRUE)
   524 
   525             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   526             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   527             set(SDL_VIDEO_DRIVER_MIR 1)
   528 
   529             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
   530 
   531             if(MIR_SHARED)
   532                 if(NOT HAVE_DLOPEN)
   533                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   534                 else()
   535                     FindLibraryAndSONAME(mirclient)
   536                     FindLibraryAndSONAME(xkbcommon)
   537                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   538                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   539                     set(HAVE_MIR_SHARED TRUE)
   540                 endif()
   541             else()
   542                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   543             endif()
   544         endif()
   545     endif()
   546 endmacro()
   547 
   548 # Requires:
   549 # - EGL
   550 # - PkgCheckModules
   551 # Optional:
   552 # - WAYLAND_SHARED opt
   553 # - HAVE_DLOPEN opt
   554 macro(CheckWayland)
   555   if(VIDEO_WAYLAND)
   556     pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
   557     if(WAYLAND_FOUND)
   558       link_directories(
   559           ${WAYLAND_LIBRARY_DIRS}
   560       )
   561       include_directories(
   562           ${WAYLAND_INCLUDE_DIRS}
   563       )
   564       set(HAVE_VIDEO_WAYLAND TRUE)
   565       set(HAVE_SDL_VIDEO TRUE)
   566 
   567       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   568       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   569 
   570       if(VIDEO_WAYLAND_QT_TOUCH)
   571           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   572       endif()
   573 
   574       if(WAYLAND_SHARED)
   575         if(NOT HAVE_DLOPEN)
   576           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   577         else()
   578           FindLibraryAndSONAME(wayland-client)
   579           FindLibraryAndSONAME(wayland-egl)
   580           FindLibraryAndSONAME(wayland-cursor)
   581           FindLibraryAndSONAME(xkbcommon)
   582           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   583           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   584           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   585           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   586           set(HAVE_WAYLAND_SHARED TRUE)
   587         endif()
   588       else()
   589         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   590       endif()
   591 
   592       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   593     endif()
   594   endif()
   595 endmacro()
   596 
   597 # Requires:
   598 # - n/a
   599 #
   600 macro(CheckCOCOA)
   601   if(VIDEO_COCOA)
   602     if(APPLE) # Apple always has Cocoa.
   603       set(HAVE_VIDEO_COCOA TRUE)
   604     endif()
   605     if(HAVE_VIDEO_COCOA)
   606       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   607       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   608       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   609       set(SDL_VIDEO_DRIVER_COCOA 1)
   610       set(HAVE_SDL_VIDEO TRUE)
   611     endif()
   612   endif()
   613 endmacro()
   614 
   615 # Requires:
   616 # - PkgCheckModules
   617 # Optional:
   618 # - DIRECTFB_SHARED opt
   619 # - HAVE_DLOPEN opt
   620 macro(CheckDirectFB)
   621   if(VIDEO_DIRECTFB)
   622     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   623     if(PKG_DIRECTFB_FOUND)
   624       set(HAVE_VIDEO_DIRECTFB TRUE)
   625       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   626       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   627       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   628       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   629       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   630       if(DIRECTFB_SHARED)
   631         if(NOT HAVE_DLOPEN)
   632           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   633         else()
   634           FindLibraryAndSONAME("directfb")
   635           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   636           set(HAVE_DIRECTFB_SHARED TRUE)
   637         endif()
   638       else()
   639         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   640       endif()
   641       set(HAVE_SDL_VIDEO TRUE)
   642     endif()
   643   endif()
   644 endmacro()
   645 
   646 # Requires:
   647 # - n/a
   648 macro(CheckVivante)
   649   if(VIDEO_VIVANTE)
   650     check_c_source_compiles("
   651         #include <gc_vdk.h>
   652         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   653     check_c_source_compiles("
   654         #define LINUX
   655         #define EGL_API_FB
   656         #include <EGL/eglvivante.h>
   657         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   658     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   659       set(HAVE_VIDEO_VIVANTE TRUE)
   660       set(HAVE_SDL_VIDEO TRUE)
   661 
   662       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   663       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   664       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   665       if(HAVE_VIDEO_VIVANTE_VDK)
   666         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   667         list(APPEND EXTRA_LIBS VDK VIVANTE)
   668       else()
   669         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   670         list(APPEND EXTRA_LIBS EGL)
   671       endif(HAVE_VIDEO_VIVANTE_VDK)
   672     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   673   endif(VIDEO_VIVANTE)
   674 endmacro(CheckVivante)
   675 
   676 # Requires:
   677 # - nada
   678 macro(CheckOpenGLX11)
   679   if(VIDEO_OPENGL)
   680     check_c_source_compiles("
   681         #include <GL/gl.h>
   682         #include <GL/glx.h>
   683         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   684 
   685     if(HAVE_VIDEO_OPENGL)
   686       set(HAVE_VIDEO_OPENGL TRUE)
   687       set(SDL_VIDEO_OPENGL 1)
   688       set(SDL_VIDEO_OPENGL_GLX 1)
   689       set(SDL_VIDEO_RENDER_OGL 1)
   690       list(APPEND EXTRA_LIBS GL)
   691     endif()
   692   endif()
   693 endmacro()
   694 
   695 # Requires:
   696 # - nada
   697 macro(CheckOpenGLESX11)
   698   if(VIDEO_OPENGLES)
   699     check_c_source_compiles("
   700         #define EGL_API_FB
   701         #include <EGL/egl.h>
   702         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   703     if(HAVE_VIDEO_OPENGL_EGL)
   704         set(SDL_VIDEO_OPENGL_EGL 1)
   705     endif()
   706     check_c_source_compiles("
   707       #include <GLES/gl.h>
   708       #include <GLES/glext.h>
   709       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   710     if(HAVE_VIDEO_OPENGLES_V1)
   711         set(HAVE_VIDEO_OPENGLES TRUE)
   712         set(SDL_VIDEO_OPENGL_ES 1)
   713         set(SDL_VIDEO_RENDER_OGL_ES 1)
   714     endif()
   715     check_c_source_compiles("
   716       #include <GLES2/gl2.h>
   717       #include <GLES2/gl2ext.h>
   718       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   719     if(HAVE_VIDEO_OPENGLES_V2)
   720         set(HAVE_VIDEO_OPENGLES TRUE)
   721         set(SDL_VIDEO_OPENGL_ES2 1)
   722         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   723     endif()
   724 
   725   endif()
   726 endmacro()
   727 
   728 # Requires:
   729 # - nada
   730 # Optional:
   731 # - THREADS opt
   732 # Sets:
   733 # PTHREAD_CFLAGS
   734 # PTHREAD_LIBS
   735 macro(CheckPTHREAD)
   736   if(PTHREADS)
   737     if(LINUX)
   738       set(PTHREAD_CFLAGS "-D_REENTRANT")
   739       set(PTHREAD_LDFLAGS "-pthread")
   740     elseif(BSDI)
   741       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   742       set(PTHREAD_LDFLAGS "")
   743     elseif(DARWIN)
   744       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   745       # causes Carbon.p complaints?
   746       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   747       set(PTHREAD_LDFLAGS "")
   748     elseif(FREEBSD)
   749       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   750       set(PTHREAD_LDFLAGS "-pthread")
   751     elseif(NETBSD)
   752       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   753       set(PTHREAD_LDFLAGS "-lpthread")
   754     elseif(OPENBSD)
   755       set(PTHREAD_CFLAGS "-D_REENTRANT")
   756       set(PTHREAD_LDFLAGS "-pthread")
   757     elseif(SOLARIS)
   758       set(PTHREAD_CFLAGS "-D_REENTRANT")
   759       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   760     elseif(SYSV5)
   761       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   762       set(PTHREAD_LDFLAGS "")
   763     elseif(AIX)
   764       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   765       set(PTHREAD_LDFLAGS "-pthread")
   766     elseif(HPUX)
   767       set(PTHREAD_CFLAGS "-D_REENTRANT")
   768       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   769     elseif(HAIKU)
   770       set(PTHREAD_CFLAGS "-D_REENTRANT")
   771       set(PTHREAD_LDFLAGS "")
   772     else()
   773       set(PTHREAD_CFLAGS "-D_REENTRANT")
   774       set(PTHREAD_LDFLAGS "-lpthread")
   775     endif()
   776 
   777     # Run some tests
   778     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   779     if(CMAKE_CROSSCOMPILING)
   780       set(HAVE_PTHREADS 1)
   781     else()
   782       check_c_source_runs("
   783         #include <pthread.h>
   784         int main(int argc, char** argv) {
   785           pthread_attr_t type;
   786           pthread_attr_init(&type);
   787           return 0;
   788         }" HAVE_PTHREADS)
   789     endif()
   790     if(HAVE_PTHREADS)
   791       set(SDL_THREAD_PTHREAD 1)
   792       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   793       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   794       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   795       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   796 
   797       check_c_source_compiles("
   798         #include <pthread.h>
   799         int main(int argc, char **argv) {
   800           pthread_mutexattr_t attr;
   801           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   802           return 0;
   803         }" HAVE_RECURSIVE_MUTEXES)
   804       if(HAVE_RECURSIVE_MUTEXES)
   805         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   806       else()
   807         check_c_source_compiles("
   808             #include <pthread.h>
   809             int main(int argc, char **argv) {
   810               pthread_mutexattr_t attr;
   811               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   812               return 0;
   813             }" HAVE_RECURSIVE_MUTEXES_NP)
   814         if(HAVE_RECURSIVE_MUTEXES_NP)
   815           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   816         endif()
   817       endif()
   818 
   819       if(PTHREADS_SEM)
   820         check_c_source_compiles("#include <pthread.h>
   821                                  #include <semaphore.h>
   822                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   823         if(HAVE_PTHREADS_SEM)
   824           check_c_source_compiles("
   825               #include <pthread.h>
   826               #include <semaphore.h>
   827               int main(int argc, char **argv) {
   828                   sem_timedwait(NULL, NULL);
   829                   return 0;
   830               }" HAVE_SEM_TIMEDWAIT)
   831         endif()
   832       endif()
   833 
   834       check_c_source_compiles("
   835           #include <pthread.h>
   836           #include <pthread_np.h>
   837           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   838       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   839       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   840       set(CMAKE_REQUIRED_FLAGS)
   841 
   842       set(SOURCE_FILES ${SOURCE_FILES}
   843           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   844           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   845           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   846           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   847           )
   848       if(HAVE_PTHREADS_SEM)
   849         set(SOURCE_FILES ${SOURCE_FILES}
   850             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   851       else()
   852         set(SOURCE_FILES ${SOURCE_FILES}
   853             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   854       endif()
   855       set(HAVE_SDL_THREADS TRUE)
   856     endif()
   857   endif()
   858 endmacro()
   859 
   860 # Requires
   861 # - nada
   862 # Optional:
   863 # Sets:
   864 # USB_LIBS
   865 # USB_CFLAGS
   866 macro(CheckUSBHID)
   867   check_library_exists(usbhid hid_init "" LIBUSBHID)
   868   if(LIBUSBHID)
   869     check_include_file(usbhid.h HAVE_USBHID_H)
   870     if(HAVE_USBHID_H)
   871       set(USB_CFLAGS "-DHAVE_USBHID_H")
   872     endif()
   873 
   874     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   875     if(HAVE_LIBUSBHID_H)
   876       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   877     endif()
   878     set(USB_LIBS ${USB_LIBS} usbhid)
   879   else()
   880     check_include_file(usb.h HAVE_USB_H)
   881     if(HAVE_USB_H)
   882       set(USB_CFLAGS "-DHAVE_USB_H")
   883     endif()
   884     check_include_file(libusb.h HAVE_LIBUSB_H)
   885     if(HAVE_LIBUSB_H)
   886       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   887     endif()
   888     check_library_exists(usb hid_init "" LIBUSB)
   889     if(LIBUSB)
   890       set(USB_LIBS ${USB_LIBS} usb)
   891     endif()
   892   endif()
   893 
   894   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   895   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   896   check_c_source_compiles("
   897        #include <sys/types.h>
   898         #if defined(HAVE_USB_H)
   899         #include <usb.h>
   900         #endif
   901         #ifdef __DragonFly__
   902         # include <bus/usb/usb.h>
   903         # include <bus/usb/usbhid.h>
   904         #else
   905         # include <dev/usb/usb.h>
   906         # include <dev/usb/usbhid.h>
   907         #endif
   908         #if defined(HAVE_USBHID_H)
   909         #include <usbhid.h>
   910         #elif defined(HAVE_LIBUSB_H)
   911         #include <libusb.h>
   912         #elif defined(HAVE_LIBUSBHID_H)
   913         #include <libusbhid.h>
   914         #endif
   915         int main(int argc, char **argv) {
   916           struct report_desc *repdesc;
   917           struct usb_ctl_report *repbuf;
   918           hid_kind_t hidkind;
   919           return 0;
   920         }" HAVE_USBHID)
   921   if(HAVE_USBHID)
   922     check_c_source_compiles("
   923           #include <sys/types.h>
   924           #if defined(HAVE_USB_H)
   925           #include <usb.h>
   926           #endif
   927           #ifdef __DragonFly__
   928           # include <bus/usb/usb.h>
   929           # include <bus/usb/usbhid.h>
   930           #else
   931           # include <dev/usb/usb.h>
   932           # include <dev/usb/usbhid.h>
   933           #endif
   934           #if defined(HAVE_USBHID_H)
   935           #include <usbhid.h>
   936           #elif defined(HAVE_LIBUSB_H)
   937           #include <libusb.h>
   938           #elif defined(HAVE_LIBUSBHID_H)
   939           #include <libusbhid.h>
   940           #endif
   941           int main(int argc, char** argv) {
   942             struct usb_ctl_report buf;
   943             if (buf.ucr_data) { }
   944             return 0;
   945           }" HAVE_USBHID_UCR_DATA)
   946     if(HAVE_USBHID_UCR_DATA)
   947       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   948     endif()
   949 
   950     check_c_source_compiles("
   951           #include <sys/types.h>
   952           #if defined(HAVE_USB_H)
   953           #include <usb.h>
   954           #endif
   955           #ifdef __DragonFly__
   956           #include <bus/usb/usb.h>
   957           #include <bus/usb/usbhid.h>
   958           #else
   959           #include <dev/usb/usb.h>
   960           #include <dev/usb/usbhid.h>
   961           #endif
   962           #if defined(HAVE_USBHID_H)
   963           #include <usbhid.h>
   964           #elif defined(HAVE_LIBUSB_H)
   965           #include <libusb.h>
   966           #elif defined(HAVE_LIBUSBHID_H)
   967           #include <libusbhid.h>
   968           #endif
   969           int main(int argc, char **argv) {
   970             report_desc_t d;
   971             hid_start_parse(d, 1, 1);
   972             return 0;
   973           }" HAVE_USBHID_NEW)
   974     if(HAVE_USBHID_NEW)
   975       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   976     endif()
   977 
   978     check_c_source_compiles("
   979         #include <machine/joystick.h>
   980         int main(int argc, char** argv) {
   981             struct joystick t;
   982             return 0;
   983         }" HAVE_MACHINE_JOYSTICK)
   984     if(HAVE_MACHINE_JOYSTICK)
   985       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   986     endif()
   987     set(SDL_JOYSTICK_USBHID 1)
   988     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   989     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   990     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   991     list(APPEND EXTRA_LIBS ${USB_LIBS})
   992     set(HAVE_SDL_JOYSTICK TRUE)
   993 
   994     set(CMAKE_REQUIRED_LIBRARIES)
   995     set(CMAKE_REQUIRED_FLAGS)
   996   endif()
   997 endmacro()
   998 
   999 # Requires:
  1000 # - n/a
  1001 macro(CheckRPI)
  1002   if(VIDEO_RPI)
  1003     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1004     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1005     set(VIDEO_RPI_LIBS bcm_host )
  1006     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1007     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1008 
  1009     set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1010     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1011     check_c_source_compiles("
  1012         #include <bcm_host.h>
  1013         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1014     set(CMAKE_REQUIRED_FLAGS)
  1015     set(CMAKE_REQUIRED_LIBRARIES)
  1016 
  1017     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1018       set(HAVE_SDL_VIDEO TRUE)
  1019       set(SDL_VIDEO_DRIVER_RPI 1)
  1020       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1021       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1022       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1023       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1024     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1025   endif(VIDEO_RPI)
  1026 endmacro(CheckRPI)