cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Fri, 06 Jan 2017 20:43:53 -0800
changeset 10777 2883d23b5a28
parent 10511 8e646a2d1929
child 11081 eea7f98a37e4
permissions -rw-r--r--
Added configure and cmake support for libsamplerate
     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 # - LIBSAMPLERATE
   320 # Optional:
   321 # - LIBSAMPLERATE_SHARED opt
   322 # - HAVE_DLOPEN opt
   323 macro(CheckLibSampleRate)
   324   if(LIBSAMPLERATE)
   325     check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
   326     if(HAVE_LIBSAMPLERATE_H)
   327       if(LIBSAMPLERATE_SHARED)
   328         if(NOT HAVE_DLOPEN)
   329           message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
   330         else()
   331           FindLibraryAndSONAME("samplerate")
   332           set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
   333         endif()
   334       else()
   335         list(APPEND EXTRA_LDFLAGS -lsamplerate)
   336       endif()
   337     endif()
   338   endif()
   339 endmacro()
   340 
   341 # Requires:
   342 # - n/a
   343 # Optional:
   344 # - X11_SHARED opt
   345 # - HAVE_DLOPEN opt
   346 macro(CheckX11)
   347   if(VIDEO_X11)
   348     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   349         FindLibraryAndSONAME("${_LIB}")
   350     endforeach()
   351 
   352     find_path(X_INCLUDEDIR X11/Xlib.h)
   353     if(X_INCLUDEDIR)
   354       set(X_CFLAGS "-I${X_INCLUDEDIR}")
   355     endif()
   356 
   357     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   358     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   359     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   360     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   361     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   362     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   363     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   364     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   365     check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
   366 
   367     if(X11_LIB)
   368       if(NOT HAVE_XEXT_H)
   369         message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
   370       endif()
   371 
   372       set(HAVE_VIDEO_X11 TRUE)
   373       set(HAVE_SDL_VIDEO TRUE)
   374 
   375       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   376       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   377       set(SDL_VIDEO_DRIVER_X11 1)
   378 
   379       if(APPLE)
   380         set(X11_SHARED OFF)
   381       endif()
   382 
   383       check_function_exists("shmat" HAVE_SHMAT)
   384       if(NOT HAVE_SHMAT)
   385         check_library_exists(ipc shmat "" HAVE_SHMAT)
   386         if(HAVE_SHMAT)
   387           list(APPEND EXTRA_LIBS ipc)
   388         endif()
   389         if(NOT HAVE_SHMAT)
   390           add_definitions(-DNO_SHARED_MEMORY)
   391           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   392         endif()
   393       endif()
   394 
   395       if(X11_SHARED)
   396         if(NOT HAVE_DLOPEN)
   397           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   398           set(HAVE_X11_SHARED FALSE)
   399         else()
   400           set(HAVE_X11_SHARED TRUE)
   401         endif()
   402         if(HAVE_X11_SHARED)
   403           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
   404           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
   405         else()
   406           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   407         endif()
   408       endif()
   409 
   410       set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
   411 
   412       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   413       check_c_source_compiles("
   414           #include <X11/Xlib.h>
   415           #include <X11/Xproto.h>
   416           #include <X11/extensions/Xext.h>
   417           #include <X11/extensions/extutil.h>
   418           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   419           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   420       if(HAVE_CONST_XEXT_ADDDISPLAY)
   421         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   422       endif()
   423 
   424       check_c_source_compiles("
   425           #include <X11/Xlib.h>
   426           int main(int argc, char **argv) {
   427             Display *display;
   428             XEvent event;
   429             XGenericEventCookie *cookie = &event.xcookie;
   430             XNextEvent(display, &event);
   431             XGetEventData(display, cookie);
   432             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   433       if(HAVE_XGENERICEVENT)
   434         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   435       endif()
   436 
   437       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   438 
   439       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   440         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   441         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   442           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
   443         else()
   444           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   445         endif()
   446         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   447       endif()
   448 
   449       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   450         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   451         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   452           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
   453         else()
   454           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   455         endif()
   456         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   457       endif()
   458 
   459       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   460         set(HAVE_VIDEO_X11_XINPUT TRUE)
   461         if(HAVE_X11_SHARED AND XI_LIB)
   462           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
   463         else()
   464           list(APPEND EXTRA_LIBS ${XI_LIB})
   465         endif()
   466         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   467 
   468         # Check for multitouch
   469         check_c_source_compiles("
   470             #include <X11/Xlib.h>
   471             #include <X11/Xproto.h>
   472             #include <X11/extensions/XInput2.h>
   473             int event_type = XI_TouchBegin;
   474             XITouchClassInfo *t;
   475             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   476             {
   477               return (Status)0;
   478             }
   479             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   480         if(HAVE_XINPUT2_MULTITOUCH)
   481           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   482         endif()
   483       endif()
   484 
   485       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   486         if(HAVE_X11_SHARED AND XRANDR_LIB)
   487           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
   488         else()
   489           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   490         endif()
   491         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   492         set(HAVE_VIDEO_X11_XRANDR TRUE)
   493       endif()
   494 
   495       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   496         if(HAVE_X11_SHARED AND XSS_LIB)
   497           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
   498         else()
   499           list(APPEND EXTRA_LIBS ${XSS_LIB})
   500         endif()
   501         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   502         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   503       endif()
   504 
   505       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   506         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   507         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   508       endif()
   509 
   510       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   511         if(HAVE_X11_SHARED AND XXF86VM_LIB)
   512           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
   513         else()
   514           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   515         endif()
   516         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   517         set(HAVE_VIDEO_X11_XVM TRUE)
   518       endif()
   519 
   520       set(CMAKE_REQUIRED_LIBRARIES)
   521     endif()
   522   endif()
   523 endmacro()
   524 
   525 # Requires:
   526 # - EGL
   527 # - PkgCheckModules
   528 # Optional:
   529 # - MIR_SHARED opt
   530 # - HAVE_DLOPEN opt
   531 macro(CheckMir)
   532     if(VIDEO_MIR)
   533         find_library(MIR_LIB mirclient mircommon egl)
   534         pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
   535         pkg_check_modules(EGL egl)
   536         pkg_check_modules(XKB xkbcommon)
   537 
   538         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   539             set(HAVE_VIDEO_MIR TRUE)
   540             set(HAVE_SDL_VIDEO TRUE)
   541 
   542             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   543             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   544             set(SDL_VIDEO_DRIVER_MIR 1)
   545 
   546             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
   547 
   548             if(MIR_SHARED)
   549                 if(NOT HAVE_DLOPEN)
   550                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   551                 else()
   552                     FindLibraryAndSONAME(mirclient)
   553                     FindLibraryAndSONAME(xkbcommon)
   554                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   555                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   556                     set(HAVE_MIR_SHARED TRUE)
   557                 endif()
   558             else()
   559                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   560             endif()
   561         endif()
   562     endif()
   563 endmacro()
   564 
   565 macro(WaylandProtocolGen _SCANNER _XML _PROTL)
   566     set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
   567     set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
   568 
   569     add_custom_command(
   570         OUTPUT "${_WAYLAND_PROT_H_CODE}"
   571         DEPENDS "${_XML}"
   572         COMMAND "${_SCANNER}"
   573         ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
   574     )
   575 
   576     add_custom_command(
   577         OUTPUT "${_WAYLAND_PROT_C_CODE}"
   578         DEPENDS "${_WAYLAND_PROT_H_CODE}"
   579         COMMAND "${_SCANNER}"
   580         ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
   581     )
   582 
   583     set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
   584 endmacro()
   585 
   586 # Requires:
   587 # - EGL
   588 # - PkgCheckModules
   589 # Optional:
   590 # - WAYLAND_SHARED opt
   591 # - HAVE_DLOPEN opt
   592 macro(CheckWayland)
   593   if(VIDEO_WAYLAND)
   594     pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
   595 
   596     # We have to generate some protocol interface code for some various Wayland features.
   597     if(WAYLAND_FOUND)
   598       execute_process(
   599         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
   600         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   601         RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
   602         OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
   603         ERROR_QUIET
   604         OUTPUT_STRIP_TRAILING_WHITESPACE
   605       )
   606       if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
   607         set(WAYLAND_FOUND FALSE)
   608       endif()
   609     endif()
   610 
   611     if(WAYLAND_FOUND)
   612       execute_process(
   613         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
   614         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   615         RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
   616         OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
   617         ERROR_QUIET
   618         OUTPUT_STRIP_TRAILING_WHITESPACE
   619       )
   620       if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
   621         set(WAYLAND_FOUND FALSE)
   622       endif()
   623     endif()
   624 
   625     if(WAYLAND_FOUND)
   626       execute_process(
   627         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
   628         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   629         RESULT_VARIABLE WAYLAND_SCANNER_RC
   630         OUTPUT_VARIABLE WAYLAND_SCANNER
   631         ERROR_QUIET
   632         OUTPUT_STRIP_TRAILING_WHITESPACE
   633       )
   634       if(NOT WAYLAND_SCANNER_RC EQUAL 0)
   635         set(WAYLAND_FOUND FALSE)
   636       endif()
   637     endif()
   638 
   639     if(WAYLAND_FOUND)
   640       link_directories(
   641           ${WAYLAND_LIBRARY_DIRS}
   642       )
   643       include_directories(
   644           ${WAYLAND_INCLUDE_DIRS}
   645       )
   646       set(HAVE_VIDEO_WAYLAND TRUE)
   647       set(HAVE_SDL_VIDEO TRUE)
   648 
   649       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   650       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   651 
   652       # We have to generate some protocol interface code for some unstable Wayland features.
   653       file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   654       include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   655 
   656       WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
   657 
   658       foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
   659         string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
   660         WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
   661       endforeach()
   662 
   663       if(VIDEO_WAYLAND_QT_TOUCH)
   664           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   665       endif()
   666 
   667       if(WAYLAND_SHARED)
   668         if(NOT HAVE_DLOPEN)
   669           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   670         else()
   671           FindLibraryAndSONAME(wayland-client)
   672           FindLibraryAndSONAME(wayland-egl)
   673           FindLibraryAndSONAME(wayland-cursor)
   674           FindLibraryAndSONAME(xkbcommon)
   675           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   676           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   677           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   678           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   679           set(HAVE_WAYLAND_SHARED TRUE)
   680         endif()
   681       else()
   682         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   683       endif()
   684 
   685       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   686     endif()
   687   endif()
   688 endmacro()
   689 
   690 # Requires:
   691 # - n/a
   692 #
   693 macro(CheckCOCOA)
   694   if(VIDEO_COCOA)
   695     if(APPLE) # Apple always has Cocoa.
   696       set(HAVE_VIDEO_COCOA TRUE)
   697     endif()
   698     if(HAVE_VIDEO_COCOA)
   699       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   700       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   701       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   702       set(SDL_VIDEO_DRIVER_COCOA 1)
   703       set(HAVE_SDL_VIDEO TRUE)
   704     endif()
   705   endif()
   706 endmacro()
   707 
   708 # Requires:
   709 # - PkgCheckModules
   710 # Optional:
   711 # - DIRECTFB_SHARED opt
   712 # - HAVE_DLOPEN opt
   713 macro(CheckDirectFB)
   714   if(VIDEO_DIRECTFB)
   715     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   716     if(PKG_DIRECTFB_FOUND)
   717       set(HAVE_VIDEO_DIRECTFB TRUE)
   718       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   719       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   720       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   721       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   722       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   723       if(DIRECTFB_SHARED)
   724         if(NOT HAVE_DLOPEN)
   725           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   726         else()
   727           FindLibraryAndSONAME("directfb")
   728           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   729           set(HAVE_DIRECTFB_SHARED TRUE)
   730         endif()
   731       else()
   732         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   733       endif()
   734       set(HAVE_SDL_VIDEO TRUE)
   735     endif()
   736   endif()
   737 endmacro()
   738 
   739 # Requires:
   740 # - n/a
   741 macro(CheckVivante)
   742   if(VIDEO_VIVANTE)
   743     check_c_source_compiles("
   744         #include <gc_vdk.h>
   745         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   746     check_c_source_compiles("
   747         #define LINUX
   748         #define EGL_API_FB
   749         #include <EGL/eglvivante.h>
   750         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   751     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   752       set(HAVE_VIDEO_VIVANTE TRUE)
   753       set(HAVE_SDL_VIDEO TRUE)
   754 
   755       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   756       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   757       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   758       if(HAVE_VIDEO_VIVANTE_VDK)
   759         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   760         list(APPEND EXTRA_LIBS VDK VIVANTE)
   761       else()
   762         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   763         list(APPEND EXTRA_LIBS EGL)
   764       endif(HAVE_VIDEO_VIVANTE_VDK)
   765     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   766   endif(VIDEO_VIVANTE)
   767 endmacro(CheckVivante)
   768 
   769 # Requires:
   770 # - nada
   771 macro(CheckOpenGLX11)
   772   if(VIDEO_OPENGL)
   773     check_c_source_compiles("
   774         #include <GL/gl.h>
   775         #include <GL/glx.h>
   776         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   777 
   778     if(HAVE_VIDEO_OPENGL)
   779       set(HAVE_VIDEO_OPENGL TRUE)
   780       set(SDL_VIDEO_OPENGL 1)
   781       set(SDL_VIDEO_OPENGL_GLX 1)
   782       set(SDL_VIDEO_RENDER_OGL 1)
   783     endif()
   784   endif()
   785 endmacro()
   786 
   787 # Requires:
   788 # - nada
   789 macro(CheckOpenGLESX11)
   790   if(VIDEO_OPENGLES)
   791     check_c_source_compiles("
   792         #define EGL_API_FB
   793         #include <EGL/egl.h>
   794         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   795     if(HAVE_VIDEO_OPENGL_EGL)
   796         set(SDL_VIDEO_OPENGL_EGL 1)
   797     endif()
   798     check_c_source_compiles("
   799       #include <GLES/gl.h>
   800       #include <GLES/glext.h>
   801       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   802     if(HAVE_VIDEO_OPENGLES_V1)
   803         set(HAVE_VIDEO_OPENGLES TRUE)
   804         set(SDL_VIDEO_OPENGL_ES 1)
   805         set(SDL_VIDEO_RENDER_OGL_ES 1)
   806     endif()
   807     check_c_source_compiles("
   808       #include <GLES2/gl2.h>
   809       #include <GLES2/gl2ext.h>
   810       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   811     if(HAVE_VIDEO_OPENGLES_V2)
   812         set(HAVE_VIDEO_OPENGLES TRUE)
   813         set(SDL_VIDEO_OPENGL_ES2 1)
   814         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   815     endif()
   816 
   817   endif()
   818 endmacro()
   819 
   820 # Requires:
   821 # - nada
   822 # Optional:
   823 # - THREADS opt
   824 # Sets:
   825 # PTHREAD_CFLAGS
   826 # PTHREAD_LIBS
   827 macro(CheckPTHREAD)
   828   if(PTHREADS)
   829     if(LINUX)
   830       set(PTHREAD_CFLAGS "-D_REENTRANT")
   831       set(PTHREAD_LDFLAGS "-pthread")
   832     elseif(BSDI)
   833       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   834       set(PTHREAD_LDFLAGS "")
   835     elseif(DARWIN)
   836       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   837       # causes Carbon.p complaints?
   838       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   839       set(PTHREAD_LDFLAGS "")
   840     elseif(FREEBSD)
   841       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   842       set(PTHREAD_LDFLAGS "-pthread")
   843     elseif(NETBSD)
   844       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   845       set(PTHREAD_LDFLAGS "-lpthread")
   846     elseif(OPENBSD)
   847       set(PTHREAD_CFLAGS "-D_REENTRANT")
   848       set(PTHREAD_LDFLAGS "-pthread")
   849     elseif(SOLARIS)
   850       set(PTHREAD_CFLAGS "-D_REENTRANT")
   851       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   852     elseif(SYSV5)
   853       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   854       set(PTHREAD_LDFLAGS "")
   855     elseif(AIX)
   856       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   857       set(PTHREAD_LDFLAGS "-pthread")
   858     elseif(HPUX)
   859       set(PTHREAD_CFLAGS "-D_REENTRANT")
   860       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   861     elseif(HAIKU)
   862       set(PTHREAD_CFLAGS "-D_REENTRANT")
   863       set(PTHREAD_LDFLAGS "")
   864     else()
   865       set(PTHREAD_CFLAGS "-D_REENTRANT")
   866       set(PTHREAD_LDFLAGS "-lpthread")
   867     endif()
   868 
   869     # Run some tests
   870     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   871     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   872     if(CMAKE_CROSSCOMPILING)
   873       set(HAVE_PTHREADS 1)
   874     else()
   875       check_c_source_runs("
   876         #include <pthread.h>
   877         int main(int argc, char** argv) {
   878           pthread_attr_t type;
   879           pthread_attr_init(&type);
   880           return 0;
   881         }" HAVE_PTHREADS)
   882     endif()
   883     if(HAVE_PTHREADS)
   884       set(SDL_THREAD_PTHREAD 1)
   885       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   886       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   887       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   888       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   889 
   890       check_c_source_compiles("
   891         #include <pthread.h>
   892         int main(int argc, char **argv) {
   893           pthread_mutexattr_t attr;
   894           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   895           return 0;
   896         }" HAVE_RECURSIVE_MUTEXES)
   897       if(HAVE_RECURSIVE_MUTEXES)
   898         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   899       else()
   900         check_c_source_compiles("
   901             #include <pthread.h>
   902             int main(int argc, char **argv) {
   903               pthread_mutexattr_t attr;
   904               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   905               return 0;
   906             }" HAVE_RECURSIVE_MUTEXES_NP)
   907         if(HAVE_RECURSIVE_MUTEXES_NP)
   908           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   909         endif()
   910       endif()
   911 
   912       if(PTHREADS_SEM)
   913         check_c_source_compiles("#include <pthread.h>
   914                                  #include <semaphore.h>
   915                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   916         if(HAVE_PTHREADS_SEM)
   917           check_c_source_compiles("
   918               #include <pthread.h>
   919               #include <semaphore.h>
   920               int main(int argc, char **argv) {
   921                   sem_timedwait(NULL, NULL);
   922                   return 0;
   923               }" HAVE_SEM_TIMEDWAIT)
   924         endif()
   925       endif()
   926 
   927       check_c_source_compiles("
   928           #include <pthread.h>
   929           #include <pthread_np.h>
   930           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   931       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   932       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   933       set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
   934 
   935       set(SOURCE_FILES ${SOURCE_FILES}
   936           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   937           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   938           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   939           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   940           )
   941       if(HAVE_PTHREADS_SEM)
   942         set(SOURCE_FILES ${SOURCE_FILES}
   943             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   944       else()
   945         set(SOURCE_FILES ${SOURCE_FILES}
   946             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   947       endif()
   948       set(HAVE_SDL_THREADS TRUE)
   949     endif()
   950   endif()
   951 endmacro()
   952 
   953 # Requires
   954 # - nada
   955 # Optional:
   956 # Sets:
   957 # USB_LIBS
   958 # USB_CFLAGS
   959 macro(CheckUSBHID)
   960   check_library_exists(usbhid hid_init "" LIBUSBHID)
   961   if(LIBUSBHID)
   962     check_include_file(usbhid.h HAVE_USBHID_H)
   963     if(HAVE_USBHID_H)
   964       set(USB_CFLAGS "-DHAVE_USBHID_H")
   965     endif()
   966 
   967     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   968     if(HAVE_LIBUSBHID_H)
   969       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   970     endif()
   971     set(USB_LIBS ${USB_LIBS} usbhid)
   972   else()
   973     check_include_file(usb.h HAVE_USB_H)
   974     if(HAVE_USB_H)
   975       set(USB_CFLAGS "-DHAVE_USB_H")
   976     endif()
   977     check_include_file(libusb.h HAVE_LIBUSB_H)
   978     if(HAVE_LIBUSB_H)
   979       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   980     endif()
   981     check_library_exists(usb hid_init "" LIBUSB)
   982     if(LIBUSB)
   983       set(USB_LIBS ${USB_LIBS} usb)
   984     endif()
   985   endif()
   986 
   987   set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   988   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
   989   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   990   check_c_source_compiles("
   991        #include <sys/types.h>
   992         #if defined(HAVE_USB_H)
   993         #include <usb.h>
   994         #endif
   995         #ifdef __DragonFly__
   996         # include <bus/usb/usb.h>
   997         # include <bus/usb/usbhid.h>
   998         #else
   999         # include <dev/usb/usb.h>
  1000         # include <dev/usb/usbhid.h>
  1001         #endif
  1002         #if defined(HAVE_USBHID_H)
  1003         #include <usbhid.h>
  1004         #elif defined(HAVE_LIBUSB_H)
  1005         #include <libusb.h>
  1006         #elif defined(HAVE_LIBUSBHID_H)
  1007         #include <libusbhid.h>
  1008         #endif
  1009         int main(int argc, char **argv) {
  1010           struct report_desc *repdesc;
  1011           struct usb_ctl_report *repbuf;
  1012           hid_kind_t hidkind;
  1013           return 0;
  1014         }" HAVE_USBHID)
  1015   if(HAVE_USBHID)
  1016     check_c_source_compiles("
  1017           #include <sys/types.h>
  1018           #if defined(HAVE_USB_H)
  1019           #include <usb.h>
  1020           #endif
  1021           #ifdef __DragonFly__
  1022           # include <bus/usb/usb.h>
  1023           # include <bus/usb/usbhid.h>
  1024           #else
  1025           # include <dev/usb/usb.h>
  1026           # include <dev/usb/usbhid.h>
  1027           #endif
  1028           #if defined(HAVE_USBHID_H)
  1029           #include <usbhid.h>
  1030           #elif defined(HAVE_LIBUSB_H)
  1031           #include <libusb.h>
  1032           #elif defined(HAVE_LIBUSBHID_H)
  1033           #include <libusbhid.h>
  1034           #endif
  1035           int main(int argc, char** argv) {
  1036             struct usb_ctl_report buf;
  1037             if (buf.ucr_data) { }
  1038             return 0;
  1039           }" HAVE_USBHID_UCR_DATA)
  1040     if(HAVE_USBHID_UCR_DATA)
  1041       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  1042     endif()
  1043 
  1044     check_c_source_compiles("
  1045           #include <sys/types.h>
  1046           #if defined(HAVE_USB_H)
  1047           #include <usb.h>
  1048           #endif
  1049           #ifdef __DragonFly__
  1050           #include <bus/usb/usb.h>
  1051           #include <bus/usb/usbhid.h>
  1052           #else
  1053           #include <dev/usb/usb.h>
  1054           #include <dev/usb/usbhid.h>
  1055           #endif
  1056           #if defined(HAVE_USBHID_H)
  1057           #include <usbhid.h>
  1058           #elif defined(HAVE_LIBUSB_H)
  1059           #include <libusb.h>
  1060           #elif defined(HAVE_LIBUSBHID_H)
  1061           #include <libusbhid.h>
  1062           #endif
  1063           int main(int argc, char **argv) {
  1064             report_desc_t d;
  1065             hid_start_parse(d, 1, 1);
  1066             return 0;
  1067           }" HAVE_USBHID_NEW)
  1068     if(HAVE_USBHID_NEW)
  1069       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  1070     endif()
  1071 
  1072     check_c_source_compiles("
  1073         #include <machine/joystick.h>
  1074         int main(int argc, char** argv) {
  1075             struct joystick t;
  1076             return 0;
  1077         }" HAVE_MACHINE_JOYSTICK)
  1078     if(HAVE_MACHINE_JOYSTICK)
  1079       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  1080     endif()
  1081     set(SDL_JOYSTICK_USBHID 1)
  1082     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  1083     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  1084     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  1085     list(APPEND EXTRA_LIBS ${USB_LIBS})
  1086     set(HAVE_SDL_JOYSTICK TRUE)
  1087 
  1088     set(CMAKE_REQUIRED_LIBRARIES)
  1089     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1090   endif()
  1091 endmacro()
  1092 
  1093 # Requires:
  1094 # - n/a
  1095 macro(CheckRPI)
  1096   if(VIDEO_RPI)
  1097     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1098     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1099     set(VIDEO_RPI_LIBS bcm_host )
  1100     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1101     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1102 
  1103     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1104     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1105     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1106     check_c_source_compiles("
  1107         #include <bcm_host.h>
  1108         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1109     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1110     set(CMAKE_REQUIRED_LIBRARIES)
  1111 
  1112     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1113       set(HAVE_SDL_VIDEO TRUE)
  1114       set(SDL_VIDEO_DRIVER_RPI 1)
  1115       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1116       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1117       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1118       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1119     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1120   endif(VIDEO_RPI)
  1121 endmacro(CheckRPI)