cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 Oct 2018 10:31:06 -0700
changeset 12364 351a67dbe9c6
parent 12035 1a7dec71e8e0
child 12391 ca6e41ade79a
permissions -rw-r--r--
Updated Android project files and documentation
     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 # Requires:
   568 # - EGL
   569 # - PkgCheckModules
   570 # Optional:
   571 # - MIR_SHARED opt
   572 # - HAVE_DLOPEN opt
   573 macro(CheckMir)
   574     if(VIDEO_MIR)
   575         find_library(MIR_LIB mirclient mircommon egl)
   576         pkg_check_modules(MIR_TOOLKIT mirclient>=0.26 mircommon)
   577         pkg_check_modules(EGL egl)
   578         pkg_check_modules(XKB xkbcommon)
   579 
   580         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   581             set(HAVE_VIDEO_MIR TRUE)
   582             set(HAVE_SDL_VIDEO TRUE)
   583 
   584             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   585             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   586             set(SDL_VIDEO_DRIVER_MIR 1)
   587 
   588             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CFLAGS} ${XKB_CFLAGS})
   589 
   590             if(MIR_SHARED)
   591                 if(NOT HAVE_DLOPEN)
   592                     message_warn("You must have SDL_LoadObject() support for dynamic Mir loading")
   593                 else()
   594                     FindLibraryAndSONAME(mirclient)
   595                     FindLibraryAndSONAME(xkbcommon)
   596                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC "\"${MIRCLIENT_LIB_SONAME}\"")
   597                     set(SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   598                     set(HAVE_MIR_SHARED TRUE)
   599                 endif()
   600             else()
   601                 set(EXTRA_LIBS ${MIR_TOOLKIT_LIBRARIES} ${EXTRA_LIBS})
   602             endif()
   603         endif()
   604     endif()
   605 endmacro()
   606 
   607 macro(WaylandProtocolGen _SCANNER _XML _PROTL)
   608     set(_WAYLAND_PROT_C_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-protocol.c")
   609     set(_WAYLAND_PROT_H_CODE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols/${_PROTL}-client-protocol.h")
   610 
   611     add_custom_command(
   612         OUTPUT "${_WAYLAND_PROT_H_CODE}"
   613         DEPENDS "${_XML}"
   614         COMMAND "${_SCANNER}"
   615         ARGS client-header "${_XML}" "${_WAYLAND_PROT_H_CODE}"
   616     )
   617 
   618     add_custom_command(
   619         OUTPUT "${_WAYLAND_PROT_C_CODE}"
   620         DEPENDS "${_WAYLAND_PROT_H_CODE}"
   621         COMMAND "${_SCANNER}"
   622         ARGS code "${_XML}" "${_WAYLAND_PROT_C_CODE}"
   623     )
   624 
   625     set(SOURCE_FILES ${SOURCE_FILES} "${_WAYLAND_PROT_C_CODE}")
   626 endmacro()
   627 
   628 # Requires:
   629 # - EGL
   630 # - PkgCheckModules
   631 # Optional:
   632 # - WAYLAND_SHARED opt
   633 # - HAVE_DLOPEN opt
   634 macro(CheckWayland)
   635   if(VIDEO_WAYLAND)
   636     pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-protocols wayland-egl wayland-cursor egl xkbcommon)
   637 
   638     if(WAYLAND_FOUND)
   639       execute_process(
   640         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
   641         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
   642         RESULT_VARIABLE WAYLAND_SCANNER_RC
   643         OUTPUT_VARIABLE WAYLAND_SCANNER
   644         ERROR_QUIET
   645         OUTPUT_STRIP_TRAILING_WHITESPACE
   646       )
   647       if(NOT WAYLAND_SCANNER_RC EQUAL 0)
   648         set(WAYLAND_FOUND FALSE)
   649       endif()
   650     endif()
   651 
   652     if(WAYLAND_FOUND)
   653       link_directories(
   654           ${WAYLAND_LIBRARY_DIRS}
   655       )
   656       include_directories(
   657           ${WAYLAND_INCLUDE_DIRS}
   658       )
   659       set(HAVE_VIDEO_WAYLAND TRUE)
   660       set(HAVE_SDL_VIDEO TRUE)
   661 
   662       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   663       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   664 
   665       # We have to generate some protocol interface code for some unstable Wayland features.
   666       file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   667       include_directories("${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols")
   668 
   669       file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL2_SOURCE_DIR}/wayland-protocols/" "${SDL2_SOURCE_DIR}/wayland-protocols/*.xml")
   670       foreach(_XML ${WAYLAND_PROTOCOLS_XML})
   671         string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}")
   672         WaylandProtocolGen("${WAYLAND_SCANNER}" "${SDL2_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}")
   673       endforeach()
   674 
   675       if(VIDEO_WAYLAND_QT_TOUCH)
   676           set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1)
   677       endif()
   678 
   679       if(WAYLAND_SHARED)
   680         if(NOT HAVE_DLOPEN)
   681           message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading")
   682         else()
   683           FindLibraryAndSONAME(wayland-client)
   684           FindLibraryAndSONAME(wayland-egl)
   685           FindLibraryAndSONAME(wayland-cursor)
   686           FindLibraryAndSONAME(xkbcommon)
   687           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"")
   688           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"")
   689           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"")
   690           set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"")
   691           set(HAVE_WAYLAND_SHARED TRUE)
   692         endif()
   693       else()
   694         set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   695       endif()
   696 
   697       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   698     endif()
   699   endif()
   700 endmacro()
   701 
   702 # Requires:
   703 # - n/a
   704 #
   705 macro(CheckCOCOA)
   706   if(VIDEO_COCOA)
   707     if(APPLE) # Apple always has Cocoa.
   708       set(HAVE_VIDEO_COCOA TRUE)
   709     endif()
   710     if(HAVE_VIDEO_COCOA)
   711       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   712       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   713       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   714       set(SDL_VIDEO_DRIVER_COCOA 1)
   715       set(HAVE_SDL_VIDEO TRUE)
   716     endif()
   717   endif()
   718 endmacro()
   719 
   720 # Requires:
   721 # - PkgCheckModules
   722 # Optional:
   723 # - DIRECTFB_SHARED opt
   724 # - HAVE_DLOPEN opt
   725 macro(CheckDirectFB)
   726   if(VIDEO_DIRECTFB)
   727     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   728     if(PKG_DIRECTFB_FOUND)
   729       set(HAVE_VIDEO_DIRECTFB TRUE)
   730       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   731       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   732       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   733       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   734       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   735       if(DIRECTFB_SHARED)
   736         if(NOT HAVE_DLOPEN)
   737           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   738         else()
   739           FindLibraryAndSONAME("directfb")
   740           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   741           set(HAVE_DIRECTFB_SHARED TRUE)
   742         endif()
   743       else()
   744         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   745       endif()
   746       set(HAVE_SDL_VIDEO TRUE)
   747     endif()
   748   endif()
   749 endmacro()
   750 
   751 # Requires:
   752 # - n/a
   753 macro(CheckVivante)
   754   if(VIDEO_VIVANTE)
   755     check_c_source_compiles("
   756         #include <gc_vdk.h>
   757         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
   758     check_c_source_compiles("
   759         #define LINUX
   760         #define EGL_API_FB
   761         #include <EGL/eglvivante.h>
   762         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_EGL_FB)
   763     if(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   764       set(HAVE_VIDEO_VIVANTE TRUE)
   765       set(HAVE_SDL_VIDEO TRUE)
   766 
   767       file(GLOB VIVANTE_SOURCES ${SDL2_SOURCE_DIR}/src/video/vivante/*.c)
   768       set(SOURCE_FILES ${SOURCE_FILES} ${VIVANTE_SOURCES})
   769       set(SDL_VIDEO_DRIVER_VIVANTE 1)
   770       if(HAVE_VIDEO_VIVANTE_VDK)
   771         set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1)
   772         list(APPEND EXTRA_LIBS VDK VIVANTE)
   773       else()
   774         set(SDL_CFLAGS "${SDL_CFLAGS} -DLINUX -DEGL_API_FB")
   775         list(APPEND EXTRA_LIBS EGL)
   776       endif(HAVE_VIDEO_VIVANTE_VDK)
   777     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
   778   endif(VIDEO_VIVANTE)
   779 endmacro(CheckVivante)
   780 
   781 # Requires:
   782 # - nada
   783 macro(CheckOpenGLX11)
   784   if(VIDEO_OPENGL)
   785     check_c_source_compiles("
   786         #include <GL/gl.h>
   787         #include <GL/glx.h>
   788         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   789 
   790     if(HAVE_VIDEO_OPENGL)
   791       set(HAVE_VIDEO_OPENGL TRUE)
   792       set(SDL_VIDEO_OPENGL 1)
   793       set(SDL_VIDEO_OPENGL_GLX 1)
   794       set(SDL_VIDEO_RENDER_OGL 1)
   795     endif()
   796   endif()
   797 endmacro()
   798 
   799 # Requires:
   800 # - nada
   801 macro(CheckOpenGLESX11)
   802   if(VIDEO_OPENGLES)
   803     check_c_source_compiles("
   804         #define EGL_API_FB
   805         #include <EGL/egl.h>
   806         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   807     if(HAVE_VIDEO_OPENGL_EGL)
   808         set(SDL_VIDEO_OPENGL_EGL 1)
   809     endif()
   810     check_c_source_compiles("
   811       #include <GLES/gl.h>
   812       #include <GLES/glext.h>
   813       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   814     if(HAVE_VIDEO_OPENGLES_V1)
   815         set(HAVE_VIDEO_OPENGLES TRUE)
   816         set(SDL_VIDEO_OPENGL_ES 1)
   817         set(SDL_VIDEO_RENDER_OGL_ES 1)
   818     endif()
   819     check_c_source_compiles("
   820       #include <GLES2/gl2.h>
   821       #include <GLES2/gl2ext.h>
   822       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   823     if(HAVE_VIDEO_OPENGLES_V2)
   824         set(HAVE_VIDEO_OPENGLES TRUE)
   825         set(SDL_VIDEO_OPENGL_ES2 1)
   826         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   827     endif()
   828 
   829   endif()
   830 endmacro()
   831 
   832 # Requires:
   833 # - nada
   834 # Optional:
   835 # - THREADS opt
   836 # Sets:
   837 # PTHREAD_CFLAGS
   838 # PTHREAD_LIBS
   839 macro(CheckPTHREAD)
   840   if(PTHREADS)
   841     if(ANDROID)
   842       # the android libc provides built-in support for pthreads, so no
   843       # additional linking or compile flags are necessary
   844     elseif(LINUX)
   845       set(PTHREAD_CFLAGS "-D_REENTRANT")
   846       set(PTHREAD_LDFLAGS "-pthread")
   847     elseif(BSDI)
   848       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   849       set(PTHREAD_LDFLAGS "")
   850     elseif(DARWIN)
   851       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   852       # causes Carbon.p complaints?
   853       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   854       set(PTHREAD_LDFLAGS "")
   855     elseif(FREEBSD)
   856       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   857       set(PTHREAD_LDFLAGS "-pthread")
   858     elseif(NETBSD)
   859       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   860       set(PTHREAD_LDFLAGS "-lpthread")
   861     elseif(OPENBSD)
   862       set(PTHREAD_CFLAGS "-D_REENTRANT")
   863       set(PTHREAD_LDFLAGS "-pthread")
   864     elseif(SOLARIS)
   865       set(PTHREAD_CFLAGS "-D_REENTRANT")
   866       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   867     elseif(SYSV5)
   868       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   869       set(PTHREAD_LDFLAGS "")
   870     elseif(AIX)
   871       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   872       set(PTHREAD_LDFLAGS "-pthread")
   873     elseif(HPUX)
   874       set(PTHREAD_CFLAGS "-D_REENTRANT")
   875       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   876     elseif(HAIKU)
   877       set(PTHREAD_CFLAGS "-D_REENTRANT")
   878       set(PTHREAD_LDFLAGS "")
   879     else()
   880       set(PTHREAD_CFLAGS "-D_REENTRANT")
   881       set(PTHREAD_LDFLAGS "-lpthread")
   882     endif()
   883 
   884     # Run some tests
   885     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
   886     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   887     if(CMAKE_CROSSCOMPILING)
   888       set(HAVE_PTHREADS 1)
   889     else()
   890       check_c_source_runs("
   891         #include <pthread.h>
   892         int main(int argc, char** argv) {
   893           pthread_attr_t type;
   894           pthread_attr_init(&type);
   895           return 0;
   896         }" HAVE_PTHREADS)
   897     endif()
   898     if(HAVE_PTHREADS)
   899       set(SDL_THREAD_PTHREAD 1)
   900       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   901       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   902       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   903       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   904 
   905       check_c_source_compiles("
   906         #include <pthread.h>
   907         int main(int argc, char **argv) {
   908           pthread_mutexattr_t attr;
   909           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   910           return 0;
   911         }" HAVE_RECURSIVE_MUTEXES)
   912       if(HAVE_RECURSIVE_MUTEXES)
   913         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   914       else()
   915         check_c_source_compiles("
   916             #include <pthread.h>
   917             int main(int argc, char **argv) {
   918               pthread_mutexattr_t attr;
   919               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
   920               return 0;
   921             }" HAVE_RECURSIVE_MUTEXES_NP)
   922         if(HAVE_RECURSIVE_MUTEXES_NP)
   923           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   924         endif()
   925       endif()
   926 
   927       if(PTHREADS_SEM)
   928         check_c_source_compiles("#include <pthread.h>
   929                                  #include <semaphore.h>
   930                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   931         if(HAVE_PTHREADS_SEM)
   932           check_c_source_compiles("
   933               #include <pthread.h>
   934               #include <semaphore.h>
   935               int main(int argc, char **argv) {
   936                   sem_timedwait(NULL, NULL);
   937                   return 0;
   938               }" HAVE_SEM_TIMEDWAIT)
   939         endif()
   940       endif()
   941 
   942       check_c_source_compiles("
   943           #include <pthread.h>
   944           #include <pthread_np.h>
   945           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   946       check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
   947       check_function_exists(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
   948 
   949       set(SOURCE_FILES ${SOURCE_FILES}
   950           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   951           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   952           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   953           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   954           )
   955       if(HAVE_PTHREADS_SEM)
   956         set(SOURCE_FILES ${SOURCE_FILES}
   957             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   958       else()
   959         set(SOURCE_FILES ${SOURCE_FILES}
   960             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   961       endif()
   962       set(HAVE_SDL_THREADS TRUE)
   963     endif()
   964     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
   965   endif()
   966 endmacro()
   967 
   968 # Requires
   969 # - nada
   970 # Optional:
   971 # Sets:
   972 # USB_LIBS
   973 # USB_CFLAGS
   974 macro(CheckUSBHID)
   975   check_library_exists(usbhid hid_init "" LIBUSBHID)
   976   if(LIBUSBHID)
   977     check_include_file(usbhid.h HAVE_USBHID_H)
   978     if(HAVE_USBHID_H)
   979       set(USB_CFLAGS "-DHAVE_USBHID_H")
   980     endif()
   981 
   982     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   983     if(HAVE_LIBUSBHID_H)
   984       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   985     endif()
   986     set(USB_LIBS ${USB_LIBS} usbhid)
   987   else()
   988     check_include_file(usb.h HAVE_USB_H)
   989     if(HAVE_USB_H)
   990       set(USB_CFLAGS "-DHAVE_USB_H")
   991     endif()
   992     check_include_file(libusb.h HAVE_LIBUSB_H)
   993     if(HAVE_LIBUSB_H)
   994       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   995     endif()
   996     check_library_exists(usb hid_init "" LIBUSB)
   997     if(LIBUSB)
   998       set(USB_LIBS ${USB_LIBS} usb)
   999     endif()
  1000   endif()
  1001 
  1002   set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1003   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}")
  1004   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
  1005   check_c_source_compiles("
  1006        #include <sys/types.h>
  1007         #if defined(HAVE_USB_H)
  1008         #include <usb.h>
  1009         #endif
  1010         #ifdef __DragonFly__
  1011         # include <bus/usb/usb.h>
  1012         # include <bus/usb/usbhid.h>
  1013         #else
  1014         # include <dev/usb/usb.h>
  1015         # include <dev/usb/usbhid.h>
  1016         #endif
  1017         #if defined(HAVE_USBHID_H)
  1018         #include <usbhid.h>
  1019         #elif defined(HAVE_LIBUSB_H)
  1020         #include <libusb.h>
  1021         #elif defined(HAVE_LIBUSBHID_H)
  1022         #include <libusbhid.h>
  1023         #endif
  1024         int main(int argc, char **argv) {
  1025           struct report_desc *repdesc;
  1026           struct usb_ctl_report *repbuf;
  1027           hid_kind_t hidkind;
  1028           return 0;
  1029         }" HAVE_USBHID)
  1030   if(HAVE_USBHID)
  1031     check_c_source_compiles("
  1032           #include <sys/types.h>
  1033           #if defined(HAVE_USB_H)
  1034           #include <usb.h>
  1035           #endif
  1036           #ifdef __DragonFly__
  1037           # include <bus/usb/usb.h>
  1038           # include <bus/usb/usbhid.h>
  1039           #else
  1040           # include <dev/usb/usb.h>
  1041           # include <dev/usb/usbhid.h>
  1042           #endif
  1043           #if defined(HAVE_USBHID_H)
  1044           #include <usbhid.h>
  1045           #elif defined(HAVE_LIBUSB_H)
  1046           #include <libusb.h>
  1047           #elif defined(HAVE_LIBUSBHID_H)
  1048           #include <libusbhid.h>
  1049           #endif
  1050           int main(int argc, char** argv) {
  1051             struct usb_ctl_report buf;
  1052             if (buf.ucr_data) { }
  1053             return 0;
  1054           }" HAVE_USBHID_UCR_DATA)
  1055     if(HAVE_USBHID_UCR_DATA)
  1056       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
  1057     endif()
  1058 
  1059     check_c_source_compiles("
  1060           #include <sys/types.h>
  1061           #if defined(HAVE_USB_H)
  1062           #include <usb.h>
  1063           #endif
  1064           #ifdef __DragonFly__
  1065           #include <bus/usb/usb.h>
  1066           #include <bus/usb/usbhid.h>
  1067           #else
  1068           #include <dev/usb/usb.h>
  1069           #include <dev/usb/usbhid.h>
  1070           #endif
  1071           #if defined(HAVE_USBHID_H)
  1072           #include <usbhid.h>
  1073           #elif defined(HAVE_LIBUSB_H)
  1074           #include <libusb.h>
  1075           #elif defined(HAVE_LIBUSBHID_H)
  1076           #include <libusbhid.h>
  1077           #endif
  1078           int main(int argc, char **argv) {
  1079             report_desc_t d;
  1080             hid_start_parse(d, 1, 1);
  1081             return 0;
  1082           }" HAVE_USBHID_NEW)
  1083     if(HAVE_USBHID_NEW)
  1084       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
  1085     endif()
  1086 
  1087     check_c_source_compiles("
  1088         #include <machine/joystick.h>
  1089         int main(int argc, char** argv) {
  1090             struct joystick t;
  1091             return 0;
  1092         }" HAVE_MACHINE_JOYSTICK)
  1093     if(HAVE_MACHINE_JOYSTICK)
  1094       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
  1095     endif()
  1096     set(SDL_JOYSTICK_USBHID 1)
  1097     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
  1098     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
  1099     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
  1100     list(APPEND EXTRA_LIBS ${USB_LIBS})
  1101     set(HAVE_SDL_JOYSTICK TRUE)
  1102 
  1103     set(CMAKE_REQUIRED_LIBRARIES)
  1104     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1105   endif()
  1106 endmacro()
  1107 
  1108 # Requires:
  1109 # - n/a
  1110 macro(CheckRPI)
  1111   if(VIDEO_RPI)
  1112     pkg_check_modules(VIDEO_RPI bcm_host brcmegl)
  1113     if (NOT VIDEO_RPI_FOUND)
  1114       set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
  1115       set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
  1116       set(VIDEO_RPI_LIBRARIES bcm_host )
  1117       set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib")
  1118     endif()
  1119     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
  1120     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
  1121 
  1122     set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  1123     set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1124     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBRARIES}")
  1125     check_c_source_compiles("
  1126         #include <bcm_host.h>
  1127         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
  1128     set(CMAKE_REQUIRED_FLAGS "${ORIG_CMAKE_REQUIRED_FLAGS}")
  1129     set(CMAKE_REQUIRED_LIBRARIES)
  1130 
  1131     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1132       set(HAVE_SDL_VIDEO TRUE)
  1133       set(SDL_VIDEO_DRIVER_RPI 1)
  1134       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
  1135       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
  1136       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBRARIES})
  1137       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
  1138       list(APPEND EXTRA_LDFLAGS ${VIDEO_RPI_LDFLAGS})
  1139     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
  1140   endif(VIDEO_RPI)
  1141 endmacro(CheckRPI)
  1142 
  1143 # Requires:
  1144 # - EGL
  1145 # - PkgCheckModules
  1146 # Optional:
  1147 # - KMSDRM_SHARED opt
  1148 # - HAVE_DLOPEN opt
  1149 macro(CheckKMSDRM)
  1150   if(VIDEO_KMSDRM)
  1151     pkg_check_modules(KMSDRM libdrm gbm egl)
  1152     if(KMSDRM_FOUND)
  1153       link_directories(
  1154         ${KMSDRM_LIBRARY_DIRS}
  1155       )
  1156       include_directories(
  1157         ${KMSDRM_INCLUDE_DIRS}
  1158       )
  1159       set(HAVE_VIDEO_KMSDRM TRUE)
  1160       set(HAVE_SDL_VIDEO TRUE)
  1161 
  1162       file(GLOB KMSDRM_SOURCES ${SDL2_SOURCE_DIR}/src/video/kmsdrm/*.c)
  1163       set(SOURCE_FILES ${SOURCE_FILES} ${KMSDRM_SOURCES})
  1164 
  1165       list(APPEND EXTRA_CFLAGS ${KMSDRM_CFLAGS})
  1166 
  1167       set(SDL_VIDEO_DRIVER_KMSDRM 1)
  1168 
  1169       if(KMSDRM_SHARED)
  1170         if(NOT HAVE_DLOPEN)
  1171           message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading")
  1172         else()
  1173           FindLibraryAndSONAME(drm)
  1174           FindLibraryAndSONAME(gbm)
  1175           set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"")
  1176           set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"")
  1177           set(HAVE_KMSDRM_SHARED TRUE)
  1178         endif()
  1179       else()
  1180         set(EXTRA_LIBS ${KMSDRM_LIBRARIES} ${EXTRA_LIBS})
  1181       endif()
  1182     endif()
  1183   endif()
  1184 endmacro()