cmake/sdlchecks.cmake
author Philipp Wiesemann
Tue, 30 Aug 2016 21:14:13 +0200
changeset 10294 1ed0064677af
parent 10005 dea345d3b00a
child 10329 ad0bee16b6b9
permissions -rw-r--r--
Fixed compiling if filesystem is disabled (thanks, Elias!).

Fixes Bugzilla #3414.
     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     endif()
   683   endif()
   684 endmacro()
   685 
   686 # Requires:
   687 # - nada
   688 macro(CheckOpenGLESX11)
   689   if(VIDEO_OPENGLES)
   690     check_c_source_compiles("
   691         #define EGL_API_FB
   692         #include <EGL/egl.h>
   693         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   694     if(HAVE_VIDEO_OPENGL_EGL)
   695         set(SDL_VIDEO_OPENGL_EGL 1)
   696     endif()
   697     check_c_source_compiles("
   698       #include <GLES/gl.h>
   699       #include <GLES/glext.h>
   700       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   701     if(HAVE_VIDEO_OPENGLES_V1)
   702         set(HAVE_VIDEO_OPENGLES TRUE)
   703         set(SDL_VIDEO_OPENGL_ES 1)
   704         set(SDL_VIDEO_RENDER_OGL_ES 1)
   705     endif()
   706     check_c_source_compiles("
   707       #include <GLES2/gl2.h>
   708       #include <GLES2/gl2ext.h>
   709       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   710     if(HAVE_VIDEO_OPENGLES_V2)
   711         set(HAVE_VIDEO_OPENGLES TRUE)
   712         set(SDL_VIDEO_OPENGL_ES2 1)
   713         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   714     endif()
   715 
   716   endif()
   717 endmacro()
   718 
   719 # Requires:
   720 # - nada
   721 # Optional:
   722 # - THREADS opt
   723 # Sets:
   724 # PTHREAD_CFLAGS
   725 # PTHREAD_LIBS
   726 macro(CheckPTHREAD)
   727   if(PTHREADS)
   728     if(LINUX)
   729       set(PTHREAD_CFLAGS "-D_REENTRANT")
   730       set(PTHREAD_LDFLAGS "-pthread")
   731     elseif(BSDI)
   732       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   733       set(PTHREAD_LDFLAGS "")
   734     elseif(DARWIN)
   735       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   736       # causes Carbon.p complaints?
   737       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   738       set(PTHREAD_LDFLAGS "")
   739     elseif(FREEBSD)
   740       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   741       set(PTHREAD_LDFLAGS "-pthread")
   742     elseif(NETBSD)
   743       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   744       set(PTHREAD_LDFLAGS "-lpthread")
   745     elseif(OPENBSD)
   746       set(PTHREAD_CFLAGS "-D_REENTRANT")
   747       set(PTHREAD_LDFLAGS "-pthread")
   748     elseif(SOLARIS)
   749       set(PTHREAD_CFLAGS "-D_REENTRANT")
   750       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   751     elseif(SYSV5)
   752       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   753       set(PTHREAD_LDFLAGS "")
   754     elseif(AIX)
   755       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   756       set(PTHREAD_LDFLAGS "-pthread")
   757     elseif(HPUX)
   758       set(PTHREAD_CFLAGS "-D_REENTRANT")
   759       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   760     elseif(HAIKU)
   761       set(PTHREAD_CFLAGS "-D_REENTRANT")
   762       set(PTHREAD_LDFLAGS "")
   763     else()
   764       set(PTHREAD_CFLAGS "-D_REENTRANT")
   765       set(PTHREAD_LDFLAGS "-lpthread")
   766     endif()
   767 
   768     # Run some tests
   769     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   770     if(CMAKE_CROSSCOMPILING)
   771       set(HAVE_PTHREADS 1)
   772     else()
   773       check_c_source_runs("
   774         #include <pthread.h>
   775         int main(int argc, char** argv) {
   776           pthread_attr_t type;
   777           pthread_attr_init(&type);
   778           return 0;
   779         }" HAVE_PTHREADS)
   780     endif()
   781     if(HAVE_PTHREADS)
   782       set(SDL_THREAD_PTHREAD 1)
   783       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   784       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   785       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   786       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   787 
   788       check_c_source_compiles("
   789         #include <pthread.h>
   790         int main(int argc, char **argv) {
   791           pthread_mutexattr_t attr;
   792           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   793           return 0;
   794         }" HAVE_RECURSIVE_MUTEXES)
   795       if(HAVE_RECURSIVE_MUTEXES)
   796         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   797       else()
   798         check_c_source_compiles("
   799             #include <pthread.h>
   800             int main(int argc, char **argv) {
   801               pthread_mutexattr_t attr;
   802               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   803               return 0;
   804             }" HAVE_RECURSIVE_MUTEXES_NP)
   805         if(HAVE_RECURSIVE_MUTEXES_NP)
   806           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   807         endif()
   808       endif()
   809 
   810       if(PTHREADS_SEM)
   811         check_c_source_compiles("#include <pthread.h>
   812                                  #include <semaphore.h>
   813                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   814         if(HAVE_PTHREADS_SEM)
   815           check_c_source_compiles("
   816               #include <pthread.h>
   817               #include <semaphore.h>
   818               int main(int argc, char **argv) {
   819                   sem_timedwait(NULL, NULL);
   820                   return 0;
   821               }" HAVE_SEM_TIMEDWAIT)
   822         endif()
   823       endif()
   824 
   825       check_c_source_compiles("
   826           #include <pthread.h>
   827           #include <pthread_np.h>
   828           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   829       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   830       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   831       set(CMAKE_REQUIRED_FLAGS)
   832 
   833       set(SOURCE_FILES ${SOURCE_FILES}
   834           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   835           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   836           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   837           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   838           )
   839       if(HAVE_PTHREADS_SEM)
   840         set(SOURCE_FILES ${SOURCE_FILES}
   841             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   842       else()
   843         set(SOURCE_FILES ${SOURCE_FILES}
   844             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   845       endif()
   846       set(HAVE_SDL_THREADS TRUE)
   847     endif()
   848   endif()
   849 endmacro()
   850 
   851 # Requires
   852 # - nada
   853 # Optional:
   854 # Sets:
   855 # USB_LIBS
   856 # USB_CFLAGS
   857 macro(CheckUSBHID)
   858   check_library_exists(usbhid hid_init "" LIBUSBHID)
   859   if(LIBUSBHID)
   860     check_include_file(usbhid.h HAVE_USBHID_H)
   861     if(HAVE_USBHID_H)
   862       set(USB_CFLAGS "-DHAVE_USBHID_H")
   863     endif()
   864 
   865     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   866     if(HAVE_LIBUSBHID_H)
   867       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   868     endif()
   869     set(USB_LIBS ${USB_LIBS} usbhid)
   870   else()
   871     check_include_file(usb.h HAVE_USB_H)
   872     if(HAVE_USB_H)
   873       set(USB_CFLAGS "-DHAVE_USB_H")
   874     endif()
   875     check_include_file(libusb.h HAVE_LIBUSB_H)
   876     if(HAVE_LIBUSB_H)
   877       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   878     endif()
   879     check_library_exists(usb hid_init "" LIBUSB)
   880     if(LIBUSB)
   881       set(USB_LIBS ${USB_LIBS} usb)
   882     endif()
   883   endif()
   884 
   885   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   886   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   887   check_c_source_compiles("
   888        #include <sys/types.h>
   889         #if defined(HAVE_USB_H)
   890         #include <usb.h>
   891         #endif
   892         #ifdef __DragonFly__
   893         # include <bus/usb/usb.h>
   894         # include <bus/usb/usbhid.h>
   895         #else
   896         # include <dev/usb/usb.h>
   897         # include <dev/usb/usbhid.h>
   898         #endif
   899         #if defined(HAVE_USBHID_H)
   900         #include <usbhid.h>
   901         #elif defined(HAVE_LIBUSB_H)
   902         #include <libusb.h>
   903         #elif defined(HAVE_LIBUSBHID_H)
   904         #include <libusbhid.h>
   905         #endif
   906         int main(int argc, char **argv) {
   907           struct report_desc *repdesc;
   908           struct usb_ctl_report *repbuf;
   909           hid_kind_t hidkind;
   910           return 0;
   911         }" HAVE_USBHID)
   912   if(HAVE_USBHID)
   913     check_c_source_compiles("
   914           #include <sys/types.h>
   915           #if defined(HAVE_USB_H)
   916           #include <usb.h>
   917           #endif
   918           #ifdef __DragonFly__
   919           # include <bus/usb/usb.h>
   920           # include <bus/usb/usbhid.h>
   921           #else
   922           # include <dev/usb/usb.h>
   923           # include <dev/usb/usbhid.h>
   924           #endif
   925           #if defined(HAVE_USBHID_H)
   926           #include <usbhid.h>
   927           #elif defined(HAVE_LIBUSB_H)
   928           #include <libusb.h>
   929           #elif defined(HAVE_LIBUSBHID_H)
   930           #include <libusbhid.h>
   931           #endif
   932           int main(int argc, char** argv) {
   933             struct usb_ctl_report buf;
   934             if (buf.ucr_data) { }
   935             return 0;
   936           }" HAVE_USBHID_UCR_DATA)
   937     if(HAVE_USBHID_UCR_DATA)
   938       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   939     endif()
   940 
   941     check_c_source_compiles("
   942           #include <sys/types.h>
   943           #if defined(HAVE_USB_H)
   944           #include <usb.h>
   945           #endif
   946           #ifdef __DragonFly__
   947           #include <bus/usb/usb.h>
   948           #include <bus/usb/usbhid.h>
   949           #else
   950           #include <dev/usb/usb.h>
   951           #include <dev/usb/usbhid.h>
   952           #endif
   953           #if defined(HAVE_USBHID_H)
   954           #include <usbhid.h>
   955           #elif defined(HAVE_LIBUSB_H)
   956           #include <libusb.h>
   957           #elif defined(HAVE_LIBUSBHID_H)
   958           #include <libusbhid.h>
   959           #endif
   960           int main(int argc, char **argv) {
   961             report_desc_t d;
   962             hid_start_parse(d, 1, 1);
   963             return 0;
   964           }" HAVE_USBHID_NEW)
   965     if(HAVE_USBHID_NEW)
   966       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   967     endif()
   968 
   969     check_c_source_compiles("
   970         #include <machine/joystick.h>
   971         int main(int argc, char** argv) {
   972             struct joystick t;
   973             return 0;
   974         }" HAVE_MACHINE_JOYSTICK)
   975     if(HAVE_MACHINE_JOYSTICK)
   976       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   977     endif()
   978     set(SDL_JOYSTICK_USBHID 1)
   979     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   980     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   981     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   982     list(APPEND EXTRA_LIBS ${USB_LIBS})
   983     set(HAVE_SDL_JOYSTICK TRUE)
   984 
   985     set(CMAKE_REQUIRED_LIBRARIES)
   986     set(CMAKE_REQUIRED_FLAGS)
   987   endif()
   988 endmacro()
   989 
   990 # Requires:
   991 # - n/a
   992 macro(CheckRPI)
   993   if(VIDEO_RPI)
   994     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
   995     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
   996     set(VIDEO_RPI_LIBS bcm_host )
   997     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
   998     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
   999 
  1000     set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1001     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1002     check_c_source_compiles("
  1003         #include <bcm_host.h>
  1004         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1005     set(CMAKE_REQUIRED_FLAGS)
  1006     set(CMAKE_REQUIRED_LIBRARIES)
  1007 
  1008     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1009       set(HAVE_SDL_VIDEO TRUE)
  1010       set(SDL_VIDEO_DRIVER_RPI 1)
  1011       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1012       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1013       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1014       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1015     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1016   endif(VIDEO_RPI)
  1017 endmacro(CheckRPI)