cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Aug 2017 10:22:48 -0700
changeset 11175 cbc6a8a5b701
parent 11139 4c165b1a0596
child 11207 4ed2e42b7497
permissions -rw-r--r--
Fixed bug 3690 - SDL2 KMS/DRM render context support

Manuel

The attached patch adds support for KMS/DRM context graphics.

It builds with no problem on X86_64 GNU/Linux systems, provided the needed libraries are present, and on ARM GNU/Linux systems that have KMS/DRM support and a GLES2 implementation.
Tested on Raspberry Pi: KMS/DRM is what the Raspberry Pi will use as default in the near future, once the propietary DispmanX API by Broadcom is overtaken by open graphics stack, it's possible to boot current Raspbian system in KMS mode by adding "dtoverlay=vc4-kms-v3d" to config.txt on Raspbian's boot partition.
X86 systems use KMS right away in every current GNU/Linux system.

Simple build instructions:

$./autogen.sh
$./configure --enable-video-kmsdrm
$make
     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 # - JACK_SHARED opt
   165 # - HAVE_DLOPEN opt
   166 macro(CheckJACK)
   167   if(JACK)
   168     pkg_check_modules(PKG_JACK jack)
   169     if(PKG_JACK_FOUND)
   170       set(HAVE_JACK TRUE)
   171       file(GLOB JACK_SOURCES ${SDL2_SOURCE_DIR}/src/audio/jack/*.c)
   172       set(SOURCE_FILES ${SOURCE_FILES} ${JACK_SOURCES})
   173       set(SDL_AUDIO_DRIVER_JACK 1)
   174       list(APPEND EXTRA_CFLAGS ${PKG_JACK_CFLAGS})
   175       if(JACK_SHARED)
   176         if(NOT HAVE_DLOPEN)
   177           message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading")
   178         else()
   179           FindLibraryAndSONAME("jack")
   180           set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"")
   181           set(HAVE_JACK_SHARED TRUE)
   182         endif()
   183       else()
   184         list(APPEND EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS})
   185       endif()
   186       set(HAVE_SDL_AUDIO TRUE)
   187     endif()
   188   endif()
   189 endmacro()
   190 
   191 # Requires:
   192 # - PkgCheckModules
   193 # Optional:
   194 # - ESD_SHARED opt
   195 # - HAVE_DLOPEN opt
   196 macro(CheckESD)
   197   if(ESD)
   198     pkg_check_modules(PKG_ESD esound)
   199     if(PKG_ESD_FOUND)
   200       set(HAVE_ESD TRUE)
   201       file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
   202       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
   203       set(SDL_AUDIO_DRIVER_ESD 1)
   204       list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
   205       if(ESD_SHARED)
   206         if(NOT HAVE_DLOPEN)
   207           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
   208         else()
   209           FindLibraryAndSONAME(esd)
   210           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
   211           set(HAVE_ESD_SHARED TRUE)
   212         endif()
   213       else()
   214         list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   215       endif()
   216       set(HAVE_SDL_AUDIO TRUE)
   217     endif()
   218   endif()
   219 endmacro()
   220 
   221 # Requires:
   222 # - n/a
   223 # Optional:
   224 # - ARTS_SHARED opt
   225 # - HAVE_DLOPEN opt
   226 macro(CheckARTS)
   227   if(ARTS)
   228     find_program(ARTS_CONFIG arts-config)
   229     if(ARTS_CONFIG)
   230       execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
   231         OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   232       list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
   233       execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
   234         OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
   235       file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
   236       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
   237       set(SDL_AUDIO_DRIVER_ARTS 1)
   238       set(HAVE_ARTS TRUE)
   239       if(ARTS_SHARED)
   240         if(NOT HAVE_DLOPEN)
   241           message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
   242         else()
   243           # TODO
   244           FindLibraryAndSONAME(artsc)
   245           set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
   246           set(HAVE_ARTS_SHARED TRUE)
   247         endif()
   248       else()
   249         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   250       endif()
   251       set(HAVE_SDL_AUDIO TRUE)
   252     endif()
   253   endif()
   254 endmacro()
   255 
   256 # Requires:
   257 # - n/a
   258 # Optional:
   259 # - NAS_SHARED opt
   260 # - HAVE_DLOPEN opt
   261 macro(CheckNAS)
   262   if(NAS)
   263     # TODO: set include paths properly, so the NAS headers are found
   264     check_include_file(audio/audiolib.h HAVE_NAS_H)
   265     find_library(D_NAS_LIB audio)
   266     if(HAVE_NAS_H AND D_NAS_LIB)
   267       set(HAVE_NAS TRUE)
   268       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
   269       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
   270       set(SDL_AUDIO_DRIVER_NAS 1)
   271       if(NAS_SHARED)
   272         if(NOT HAVE_DLOPEN)
   273           message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
   274         else()
   275           FindLibraryAndSONAME("audio")
   276           set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
   277           set(HAVE_NAS_SHARED TRUE)
   278         endif()
   279       else()
   280         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   281       endif()
   282       set(HAVE_SDL_AUDIO TRUE)
   283     endif()
   284   endif()
   285 endmacro()
   286 
   287 # Requires:
   288 # - n/a
   289 # Optional:
   290 # - SNDIO_SHARED opt
   291 # - HAVE_DLOPEN opt
   292 macro(CheckSNDIO)
   293   if(SNDIO)
   294     # TODO: set include paths properly, so the sndio headers are found
   295     check_include_file(sndio.h HAVE_SNDIO_H)
   296     find_library(D_SNDIO_LIB sndio)
   297     if(HAVE_SNDIO_H AND D_SNDIO_LIB)
   298       set(HAVE_SNDIO TRUE)
   299       file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
   300       set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
   301       set(SDL_AUDIO_DRIVER_SNDIO 1)
   302       if(SNDIO_SHARED)
   303         if(NOT HAVE_DLOPEN)
   304           message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
   305         else()
   306           FindLibraryAndSONAME("sndio")
   307           set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
   308           set(HAVE_SNDIO_SHARED TRUE)
   309         endif()
   310       else()
   311         list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
   312       endif()
   313       set(HAVE_SDL_AUDIO TRUE)
   314     endif()
   315   endif()
   316 endmacro()
   317 
   318 # Requires:
   319 # - PkgCheckModules
   320 # Optional:
   321 # - FUSIONSOUND_SHARED opt
   322 # - HAVE_DLOPEN opt
   323 macro(CheckFusionSound)
   324   if(FUSIONSOUND)
   325     pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
   326     if(PKG_FUSIONSOUND_FOUND)
   327       set(HAVE_FUSIONSOUND TRUE)
   328       file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
   329       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
   330       set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
   331       list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
   332       if(FUSIONSOUND_SHARED)
   333         if(NOT HAVE_DLOPEN)
   334           message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
   335         else()
   336           FindLibraryAndSONAME("fusionsound")
   337           set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
   338           set(HAVE_FUSIONSOUND_SHARED TRUE)
   339         endif()
   340       else()
   341         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   342       endif()
   343       set(HAVE_SDL_AUDIO TRUE)
   344     endif()
   345   endif()
   346 endmacro()
   347 
   348 # Requires:
   349 # - LIBSAMPLERATE
   350 # Optional:
   351 # - LIBSAMPLERATE_SHARED opt
   352 # - HAVE_DLOPEN opt
   353 macro(CheckLibSampleRate)
   354   if(LIBSAMPLERATE)
   355     check_include_file(samplerate.h HAVE_LIBSAMPLERATE_H)
   356     if(HAVE_LIBSAMPLERATE_H)
   357       if(LIBSAMPLERATE_SHARED)
   358         if(NOT HAVE_DLOPEN)
   359           message_warn("You must have SDL_LoadObject() support for dynamic libsamplerate loading")
   360         else()
   361           FindLibraryAndSONAME("samplerate")
   362           set(SDL_LIBSAMPLERATE_DYNAMIC "\"${SAMPLERATE_LIB_SONAME}\"")
   363         endif()
   364       else()
   365         list(APPEND EXTRA_LDFLAGS -lsamplerate)
   366       endif()
   367     endif()
   368   endif()
   369 endmacro()
   370 
   371 # Requires:
   372 # - n/a
   373 # Optional:
   374 # - X11_SHARED opt
   375 # - HAVE_DLOPEN opt
   376 macro(CheckX11)
   377   if(VIDEO_X11)
   378     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   379         FindLibraryAndSONAME("${_LIB}")
   380     endforeach()
   381 
   382     find_path(X_INCLUDEDIR X11/Xlib.h)
   383     if(X_INCLUDEDIR)
   384       set(X_CFLAGS "-I${X_INCLUDEDIR}")
   385     endif()
   386 
   387     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   388     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   389     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   390     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   391     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   392     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   393     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   394     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   395     check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
   396 
   397     if(X11_LIB)
   398       if(NOT HAVE_XEXT_H)
   399         message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
   400       endif()
   401 
   402       set(HAVE_VIDEO_X11 TRUE)
   403       set(HAVE_SDL_VIDEO TRUE)
   404 
   405       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   406       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   407       set(SDL_VIDEO_DRIVER_X11 1)
   408 
   409       if(APPLE)
   410         set(X11_SHARED OFF)
   411       endif()
   412 
   413       check_function_exists("shmat" HAVE_SHMAT)
   414       if(NOT HAVE_SHMAT)
   415         check_library_exists(ipc shmat "" HAVE_SHMAT)
   416         if(HAVE_SHMAT)
   417           list(APPEND EXTRA_LIBS ipc)
   418         endif()
   419         if(NOT HAVE_SHMAT)
   420           add_definitions(-DNO_SHARED_MEMORY)
   421           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   422         endif()
   423       endif()
   424 
   425       if(X11_SHARED)
   426         if(NOT HAVE_DLOPEN)
   427           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   428           set(HAVE_X11_SHARED FALSE)
   429         else()
   430           set(HAVE_X11_SHARED TRUE)
   431         endif()
   432         if(HAVE_X11_SHARED)
   433           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
   434           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
   435         else()
   436           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   437         endif()
   438       endif()
   439 
   440       set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
   441 
   442       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   443       check_c_source_compiles("
   444           #include <X11/Xlib.h>
   445           #include <X11/Xproto.h>
   446           #include <X11/extensions/Xext.h>
   447           #include <X11/extensions/extutil.h>
   448           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   449           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   450       if(HAVE_CONST_XEXT_ADDDISPLAY)
   451         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   452       endif()
   453 
   454       check_c_source_compiles("
   455           #include <X11/Xlib.h>
   456           int main(int argc, char **argv) {
   457             Display *display;
   458             XEvent event;
   459             XGenericEventCookie *cookie = &event.xcookie;
   460             XNextEvent(display, &event);
   461             XGetEventData(display, cookie);
   462             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   463       if(HAVE_XGENERICEVENT)
   464         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   465       endif()
   466 
   467       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   468 
   469       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   470         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   471         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   472           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
   473         else()
   474           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   475         endif()
   476         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   477       endif()
   478 
   479       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   480         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   481         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   482           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
   483         else()
   484           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   485         endif()
   486         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   487       endif()
   488 
   489       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   490         set(HAVE_VIDEO_X11_XINPUT TRUE)
   491         if(HAVE_X11_SHARED AND XI_LIB)
   492           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
   493         else()
   494           list(APPEND EXTRA_LIBS ${XI_LIB})
   495         endif()
   496         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   497 
   498         # Check for multitouch
   499         check_c_source_compiles("
   500             #include <X11/Xlib.h>
   501             #include <X11/Xproto.h>
   502             #include <X11/extensions/XInput2.h>
   503             int event_type = XI_TouchBegin;
   504             XITouchClassInfo *t;
   505             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   506             {
   507               return (Status)0;
   508             }
   509             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   510         if(HAVE_XINPUT2_MULTITOUCH)
   511           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   512         endif()
   513       endif()
   514 
   515       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   516         if(HAVE_X11_SHARED AND XRANDR_LIB)
   517           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
   518         else()
   519           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   520         endif()
   521         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   522         set(HAVE_VIDEO_X11_XRANDR TRUE)
   523       endif()
   524 
   525       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   526         if(HAVE_X11_SHARED AND XSS_LIB)
   527           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
   528         else()
   529           list(APPEND EXTRA_LIBS ${XSS_LIB})
   530         endif()
   531         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   532         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   533       endif()
   534 
   535       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   536         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   537         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   538       endif()
   539 
   540       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   541         if(HAVE_X11_SHARED AND XXF86VM_LIB)
   542           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
   543         else()
   544           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   545         endif()
   546         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   547         set(HAVE_VIDEO_X11_XVM TRUE)
   548       endif()
   549 
   550       set(CMAKE_REQUIRED_LIBRARIES)
   551     endif()
   552   endif()
   553 endmacro()
   554 
   555 # Requires:
   556 # - EGL
   557 # - PkgCheckModules
   558 # Optional:
   559 # - MIR_SHARED opt
   560 # - HAVE_DLOPEN opt
   561 macro(CheckMir)
   562     if(VIDEO_MIR)
   563         find_library(MIR_LIB mirclient mircommon egl)
   564         pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
   565         pkg_check_modules(EGL egl)
   566         pkg_check_modules(XKB xkbcommon)
   567 
   568         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   569             set(HAVE_VIDEO_MIR TRUE)
   570             set(HAVE_SDL_VIDEO TRUE)
   571 
   572             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   573             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   574             set(SDL_VIDEO_DRIVER_MIR 1)
   575 
   576             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
   577 
   578             if(MIR_SHARED)
   579                 if(NOT HAVE_DLOPEN)
   580                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   581                 else()
   582                     FindLibraryAndSONAME(mirclient)
   583                     FindLibraryAndSONAME(xkbcommon)
   584                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   585                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   586                     set(HAVE_MIR_SHARED TRUE)
   587                 endif()
   588             else()
   589                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   590             endif()
   591         endif()
   592     endif()
   593 endmacro()
   594 
   595 macro(WaylandProtocolGen _SCANNER _XML _PROTL)
   596     set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
   597     set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
   598 
   599     add_custom_command(
   600         OUTPUT "${_WAYLAND_PROT_H_CODE}"
   601         DEPENDS "${_XML}"
   602         COMMAND "${_SCANNER}"
   603         ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
   604     )
   605 
   606     add_custom_command(
   607         OUTPUT "${_WAYLAND_PROT_C_CODE}"
   608         DEPENDS "${_WAYLAND_PROT_H_CODE}"
   609         COMMAND "${_SCANNER}"
   610         ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
   611     )
   612 
   613     set(SOURCE_FILES ${SOURCE_FILES} "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
   614 endmacro()
   615 
   616 # Requires:
   617 # - EGL
   618 # - PkgCheckModules
   619 # Optional:
   620 # - WAYLAND_SHARED opt
   621 # - HAVE_DLOPEN opt
   622 macro(CheckWayland)
   623   if(VIDEO_WAYLAND)
   624     pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
   625 
   626     # We have to generate some protocol interface code for some various Wayland features.
   627     if(WAYLAND_FOUND)
   628       execute_process(
   629         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-client
   630         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   631         RESULT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR_RC
   632         OUTPUT_VARIABLE WAYLAND_CORE_PROTOCOL_DIR
   633         ERROR_QUIET
   634         OUTPUT_STRIP_TRAILING_WHITESPACE
   635       )
   636       if(NOT WAYLAND_CORE_PROTOCOL_DIR_RC EQUAL 0)
   637         set(WAYLAND_FOUND FALSE)
   638       endif()
   639     endif()
   640 
   641     if(WAYLAND_FOUND)
   642       execute_process(
   643         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=pkgdatadir wayland-protocols
   644         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   645         RESULT_VARIABLE WAYLAND_PROTOCOLS_DIR_RC
   646         OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
   647         ERROR_QUIET
   648         OUTPUT_STRIP_TRAILING_WHITESPACE
   649       )
   650       if(NOT WAYLAND_PROTOCOLS_DIR_RC EQUAL 0)
   651         set(WAYLAND_FOUND FALSE)
   652       endif()
   653     endif()
   654 
   655     if(WAYLAND_FOUND)
   656       execute_process(
   657         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
   658         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   659         RESULT_VARIABLE WAYLAND_SCANNER_RC
   660         OUTPUT_VARIABLE WAYLAND_SCANNER
   661         ERROR_QUIET
   662         OUTPUT_STRIP_TRAILING_WHITESPACE
   663       )
   664       if(NOT WAYLAND_SCANNER_RC EQUAL 0)
   665         set(WAYLAND_FOUND FALSE)
   666       endif()
   667     endif()
   668 
   669     if(WAYLAND_FOUND)
   670       link_directories(
   671           ${WAYLAND_LIBRARY_DIRS}
   672       )
   673       include_directories(
   674           ${WAYLAND_INCLUDE_DIRS}
   675       )
   676       set(HAVE_VIDEO_WAYLAND TRUE)
   677       set(HAVE_SDL_VIDEO TRUE)
   678 
   679       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   680       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   681 
   682       # We have to generate some protocol interface code for some unstable Wayland features.
   683       file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   684       include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   685 
   686       WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_CORE_PROTOCOL_DIR}/wayland.xml" "wayland")
   687 
   688       foreach(_PROTL relative-pointer-unstable-v1 pointer-constraints-unstable-v1)
   689         string(REGEX REPLACE "\\-unstable\\-.*$" "" PROTSUBDIR ${_PROTL})
   690         WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_PROTOCOLS_DIR}/unstable/${PROTSUBDIR}/${_PROTL}.xml" "${_PROTL}")
   691       endforeach()
   692 
   693       if(VIDEO_WAYLAND_QT_TOUCH)
   694           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   695       endif()
   696 
   697       if(WAYLAND_SHARED)
   698         if(NOT HAVE_DLOPEN)
   699           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   700         else()
   701           FindLibraryAndSONAME(wayland-client)
   702           FindLibraryAndSONAME(wayland-egl)
   703           FindLibraryAndSONAME(wayland-cursor)
   704           FindLibraryAndSONAME(xkbcommon)
   705           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   706           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   707           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   708           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   709           set(HAVE_WAYLAND_SHARED TRUE)
   710         endif()
   711       else()
   712         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   713       endif()
   714 
   715       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   716     endif()
   717   endif()
   718 endmacro()
   719 
   720 # Requires:
   721 # - n/a
   722 #
   723 macro(CheckCOCOA)
   724   if(VIDEO_COCOA)
   725     if(APPLE) # Apple always has Cocoa.
   726       set(HAVE_VIDEO_COCOA TRUE)
   727     endif()
   728     if(HAVE_VIDEO_COCOA)
   729       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   730       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   731       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   732       set(SDL_VIDEO_DRIVER_COCOA 1)
   733       set(HAVE_SDL_VIDEO TRUE)
   734     endif()
   735   endif()
   736 endmacro()
   737 
   738 # Requires:
   739 # - PkgCheckModules
   740 # Optional:
   741 # - DIRECTFB_SHARED opt
   742 # - HAVE_DLOPEN opt
   743 macro(CheckDirectFB)
   744   if(VIDEO_DIRECTFB)
   745     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   746     if(PKG_DIRECTFB_FOUND)
   747       set(HAVE_VIDEO_DIRECTFB TRUE)
   748       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   749       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   750       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   751       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   752       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   753       if(DIRECTFB_SHARED)
   754         if(NOT HAVE_DLOPEN)
   755           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   756         else()
   757           FindLibraryAndSONAME("directfb")
   758           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   759           set(HAVE_DIRECTFB_SHARED TRUE)
   760         endif()
   761       else()
   762         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   763       endif()
   764       set(HAVE_SDL_VIDEO TRUE)
   765     endif()
   766   endif()
   767 endmacro()
   768 
   769 # Requires:
   770 # - n/a
   771 macro(CheckVivante)
   772   if(VIDEO_VIVANTE)
   773     check_c_source_compiles("
   774         #include <gc_vdk.h>
   775         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   776     check_c_source_compiles("
   777         #define LINUX
   778         #define EGL_API_FB
   779         #include <EGL/eglvivante.h>
   780         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   781     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   782       set(HAVE_VIDEO_VIVANTE TRUE)
   783       set(HAVE_SDL_VIDEO TRUE)
   784 
   785       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   786       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   787       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   788       if(HAVE_VIDEO_VIVANTE_VDK)
   789         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   790         list(APPEND EXTRA_LIBS VDK VIVANTE)
   791       else()
   792         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   793         list(APPEND EXTRA_LIBS EGL)
   794       endif(HAVE_VIDEO_VIVANTE_VDK)
   795     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   796   endif(VIDEO_VIVANTE)
   797 endmacro(CheckVivante)
   798 
   799 # Requires:
   800 # - nada
   801 macro(CheckOpenGLX11)
   802   if(VIDEO_OPENGL)
   803     check_c_source_compiles("
   804         #include <GL/gl.h>
   805         #include <GL/glx.h>
   806         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   807 
   808     if(HAVE_VIDEO_OPENGL)
   809       set(HAVE_VIDEO_OPENGL TRUE)
   810       set(SDL_VIDEO_OPENGL 1)
   811       set(SDL_VIDEO_OPENGL_GLX 1)
   812       set(SDL_VIDEO_RENDER_OGL 1)
   813     endif()
   814   endif()
   815 endmacro()
   816 
   817 # Requires:
   818 # - nada
   819 macro(CheckOpenGLESX11)
   820   if(VIDEO_OPENGLES)
   821     check_c_source_compiles("
   822         #define EGL_API_FB
   823         #include <EGL/egl.h>
   824         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   825     if(HAVE_VIDEO_OPENGL_EGL)
   826         set(SDL_VIDEO_OPENGL_EGL 1)
   827     endif()
   828     check_c_source_compiles("
   829       #include <GLES/gl.h>
   830       #include <GLES/glext.h>
   831       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   832     if(HAVE_VIDEO_OPENGLES_V1)
   833         set(HAVE_VIDEO_OPENGLES TRUE)
   834         set(SDL_VIDEO_OPENGL_ES 1)
   835         set(SDL_VIDEO_RENDER_OGL_ES 1)
   836     endif()
   837     check_c_source_compiles("
   838       #include <GLES2/gl2.h>
   839       #include <GLES2/gl2ext.h>
   840       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   841     if(HAVE_VIDEO_OPENGLES_V2)
   842         set(HAVE_VIDEO_OPENGLES TRUE)
   843         set(SDL_VIDEO_OPENGL_ES2 1)
   844         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   845     endif()
   846 
   847   endif()
   848 endmacro()
   849 
   850 # Requires:
   851 # - nada
   852 # Optional:
   853 # - THREADS opt
   854 # Sets:
   855 # PTHREAD_CFLAGS
   856 # PTHREAD_LIBS
   857 macro(CheckPTHREAD)
   858   if(PTHREADS)
   859     if(LINUX)
   860       set(PTHREAD_CFLAGS "-D_REENTRANT")
   861       set(PTHREAD_LDFLAGS "-pthread")
   862     elseif(BSDI)
   863       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   864       set(PTHREAD_LDFLAGS "")
   865     elseif(DARWIN)
   866       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   867       # causes Carbon.p complaints?
   868       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   869       set(PTHREAD_LDFLAGS "")
   870     elseif(FREEBSD)
   871       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   872       set(PTHREAD_LDFLAGS "-pthread")
   873     elseif(NETBSD)
   874       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   875       set(PTHREAD_LDFLAGS "-lpthread")
   876     elseif(OPENBSD)
   877       set(PTHREAD_CFLAGS "-D_REENTRANT")
   878       set(PTHREAD_LDFLAGS "-pthread")
   879     elseif(SOLARIS)
   880       set(PTHREAD_CFLAGS "-D_REENTRANT")
   881       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   882     elseif(SYSV5)
   883       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   884       set(PTHREAD_LDFLAGS "")
   885     elseif(AIX)
   886       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   887       set(PTHREAD_LDFLAGS "-pthread")
   888     elseif(HPUX)
   889       set(PTHREAD_CFLAGS "-D_REENTRANT")
   890       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   891     elseif(HAIKU)
   892       set(PTHREAD_CFLAGS "-D_REENTRANT")
   893       set(PTHREAD_LDFLAGS "")
   894     else()
   895       set(PTHREAD_CFLAGS "-D_REENTRANT")
   896       set(PTHREAD_LDFLAGS "-lpthread")
   897     endif()
   898 
   899     # Run some tests
   900     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   901     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   902     if(CMAKE_CROSSCOMPILING)
   903       set(HAVE_PTHREADS 1)
   904     else()
   905       check_c_source_runs("
   906         #include <pthread.h>
   907         int main(int argc, char** argv) {
   908           pthread_attr_t type;
   909           pthread_attr_init(&type);
   910           return 0;
   911         }" HAVE_PTHREADS)
   912     endif()
   913     if(HAVE_PTHREADS)
   914       set(SDL_THREAD_PTHREAD 1)
   915       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   916       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   917       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   918       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   919 
   920       check_c_source_compiles("
   921         #include <pthread.h>
   922         int main(int argc, char **argv) {
   923           pthread_mutexattr_t attr;
   924           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   925           return 0;
   926         }" HAVE_RECURSIVE_MUTEXES)
   927       if(HAVE_RECURSIVE_MUTEXES)
   928         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   929       else()
   930         check_c_source_compiles("
   931             #include <pthread.h>
   932             int main(int argc, char **argv) {
   933               pthread_mutexattr_t attr;
   934               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
   935               return 0;
   936             }" HAVE_RECURSIVE_MUTEXES_NP)
   937         if(HAVE_RECURSIVE_MUTEXES_NP)
   938           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   939         endif()
   940       endif()
   941 
   942       if(PTHREADS_SEM)
   943         check_c_source_compiles("#include <pthread.h>
   944                                  #include <semaphore.h>
   945                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   946         if(HAVE_PTHREADS_SEM)
   947           check_c_source_compiles("
   948               #include <pthread.h>
   949               #include <semaphore.h>
   950               int main(int argc, char **argv) {
   951                   sem_timedwait(NULL, NULL);
   952                   return 0;
   953               }" HAVE_SEM_TIMEDWAIT)
   954         endif()
   955       endif()
   956 
   957       check_c_source_compiles("
   958           #include <pthread.h>
   959           #include <pthread_np.h>
   960           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   961       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   962       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   963 
   964       set(SOURCE_FILES ${SOURCE_FILES}
   965           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   966           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   967           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   968           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   969           )
   970       if(HAVE_PTHREADS_SEM)
   971         set(SOURCE_FILES ${SOURCE_FILES}
   972             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   973       else()
   974         set(SOURCE_FILES ${SOURCE_FILES}
   975             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   976       endif()
   977       set(HAVE_SDL_THREADS TRUE)
   978     endif()
   979     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
   980   endif()
   981 endmacro()
   982 
   983 # Requires
   984 # - nada
   985 # Optional:
   986 # Sets:
   987 # USB_LIBS
   988 # USB_CFLAGS
   989 macro(CheckUSBHID)
   990   check_library_exists(usbhid hid_init "" LIBUSBHID)
   991   if(LIBUSBHID)
   992     check_include_file(usbhid.h HAVE_USBHID_H)
   993     if(HAVE_USBHID_H)
   994       set(USB_CFLAGS "-DHAVE_USBHID_H")
   995     endif()
   996 
   997     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   998     if(HAVE_LIBUSBHID_H)
   999       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
  1000     endif()
  1001     set(USB_LIBS ${USB_LIBS} usbhid)
  1002   else()
  1003     check_include_file(usb.h HAVE_USB_H)
  1004     if(HAVE_USB_H)
  1005       set(USB_CFLAGS "-DHAVE_USB_H")
  1006     endif()
  1007     check_include_file(libusb.h HAVE_LIBUSB_H)
  1008     if(HAVE_LIBUSB_H)
  1009       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
  1010     endif()
  1011     check_library_exists(usb hid_init "" LIBUSB)
  1012     if(LIBUSB)
  1013       set(USB_LIBS ${USB_LIBS} usb)
  1014     endif()
  1015   endif()
  1016 
  1017   set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1018   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  1019   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  1020   check_c_source_compiles("
  1021        #include <sys/types.h>
  1022         #if defined(HAVE_USB_H)
  1023         #include <usb.h>
  1024         #endif
  1025         #ifdef __DragonFly__
  1026         # include <bus/usb/usb.h>
  1027         # include <bus/usb/usbhid.h>
  1028         #else
  1029         # include <dev/usb/usb.h>
  1030         # include <dev/usb/usbhid.h>
  1031         #endif
  1032         #if defined(HAVE_USBHID_H)
  1033         #include <usbhid.h>
  1034         #elif defined(HAVE_LIBUSB_H)
  1035         #include <libusb.h>
  1036         #elif defined(HAVE_LIBUSBHID_H)
  1037         #include <libusbhid.h>
  1038         #endif
  1039         int main(int argc, char **argv) {
  1040           struct report_desc *repdesc;
  1041           struct usb_ctl_report *repbuf;
  1042           hid_kind_t hidkind;
  1043           return 0;
  1044         }" HAVE_USBHID)
  1045   if(HAVE_USBHID)
  1046     check_c_source_compiles("
  1047           #include <sys/types.h>
  1048           #if defined(HAVE_USB_H)
  1049           #include <usb.h>
  1050           #endif
  1051           #ifdef __DragonFly__
  1052           # include <bus/usb/usb.h>
  1053           # include <bus/usb/usbhid.h>
  1054           #else
  1055           # include <dev/usb/usb.h>
  1056           # include <dev/usb/usbhid.h>
  1057           #endif
  1058           #if defined(HAVE_USBHID_H)
  1059           #include <usbhid.h>
  1060           #elif defined(HAVE_LIBUSB_H)
  1061           #include <libusb.h>
  1062           #elif defined(HAVE_LIBUSBHID_H)
  1063           #include <libusbhid.h>
  1064           #endif
  1065           int main(int argc, char** argv) {
  1066             struct usb_ctl_report buf;
  1067             if (buf.ucr_data) { }
  1068             return 0;
  1069           }" HAVE_USBHID_UCR_DATA)
  1070     if(HAVE_USBHID_UCR_DATA)
  1071       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  1072     endif()
  1073 
  1074     check_c_source_compiles("
  1075           #include <sys/types.h>
  1076           #if defined(HAVE_USB_H)
  1077           #include <usb.h>
  1078           #endif
  1079           #ifdef __DragonFly__
  1080           #include <bus/usb/usb.h>
  1081           #include <bus/usb/usbhid.h>
  1082           #else
  1083           #include <dev/usb/usb.h>
  1084           #include <dev/usb/usbhid.h>
  1085           #endif
  1086           #if defined(HAVE_USBHID_H)
  1087           #include <usbhid.h>
  1088           #elif defined(HAVE_LIBUSB_H)
  1089           #include <libusb.h>
  1090           #elif defined(HAVE_LIBUSBHID_H)
  1091           #include <libusbhid.h>
  1092           #endif
  1093           int main(int argc, char **argv) {
  1094             report_desc_t d;
  1095             hid_start_parse(d, 1, 1);
  1096             return 0;
  1097           }" HAVE_USBHID_NEW)
  1098     if(HAVE_USBHID_NEW)
  1099       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  1100     endif()
  1101 
  1102     check_c_source_compiles("
  1103         #include <machine/joystick.h>
  1104         int main(int argc, char** argv) {
  1105             struct joystick t;
  1106             return 0;
  1107         }" HAVE_MACHINE_JOYSTICK)
  1108     if(HAVE_MACHINE_JOYSTICK)
  1109       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  1110     endif()
  1111     set(SDL_JOYSTICK_USBHID 1)
  1112     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  1113     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  1114     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  1115     list(APPEND EXTRA_LIBS ${USB_LIBS})
  1116     set(HAVE_SDL_JOYSTICK TRUE)
  1117 
  1118     set(CMAKE_REQUIRED_LIBRARIES)
  1119     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1120   endif()
  1121 endmacro()
  1122 
  1123 # Requires:
  1124 # - n/a
  1125 macro(CheckRPI)
  1126   if(VIDEO_RPI)
  1127     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1128     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1129     set(VIDEO_RPI_LIBS bcm_host )
  1130     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1131     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1132 
  1133     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1134     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1135     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
  1136     check_c_source_compiles("
  1137         #include <bcm_host.h>
  1138         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1139     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1140     set(CMAKE_REQUIRED_LIBRARIES)
  1141 
  1142     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1143       set(HAVE_SDL_VIDEO TRUE)
  1144       set(SDL_VIDEO_DRIVER_RPI 1)
  1145       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1146       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1147       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
  1148       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1149     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1150   endif(VIDEO_RPI)
  1151 endmacro(CheckRPI)
  1152 
  1153 # Requires:
  1154 # - EGL
  1155 # - PkgCheckModules
  1156 # Optional:
  1157 # - KMSDRM_SHARED opt
  1158 # - HAVE_DLOPEN opt
  1159 macro(CheckKMSDRM)
  1160   if(VIDEO_KMSDRM)
  1161     pkg_check_modules(KMSDRM libdrm gbm egl)
  1162     if(KMSDRM_FOUND)
  1163       link_directories(
  1164         ${KMSDRM_LIBRARY_DIRS}
  1165       )
  1166       include_directories(
  1167         ${KMSDRM_INCLUDE_DIRS}
  1168       )
  1169       set(HAVE_VIDEO_KMSDRM TRUE)
  1170       set(HAVE_SDL_VIDEO TRUE)
  1171 
  1172       file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1173       set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1174 
  1175       list(APPEND EXTRA_CFLAGS ${KMSDRM_CLFLAGS})
  1176 
  1177       set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1178 
  1179       if(KMSDRM_SHARED)
  1180         if(NOT HAVE_DLOPEN)
  1181           message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1182         else()
  1183           FindLibraryAndSONAME(drm)
  1184           FindLibraryAndSONAME(gbm)
  1185           set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1186           set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1187           set(HAVE_KMSDRM_SHARED TRUE)
  1188         endif()
  1189       else()
  1190         set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1191       endif()
  1192     endif()
  1193   endif()
  1194 endmacro()