cmake/sdlchecks.cmake
author Sylvain Becker <sylvain.becker@gmail.com>
Mon, 21 Jan 2019 19:53:06 +0100
changeset 12567 92b9d6f10a29
parent 12391 ca6e41ade79a
permissions -rw-r--r--
Fixed bug 3827 - issue with MapRGB, palette and colorkey

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