cmake/sdlchecks.cmake
author Sam Lantinga <slouken@libsdl.org>
Sun, 17 Aug 2014 14:57:52 -0700
changeset 9086 c5e33f9a0d03
parent 9077 28e6de55eb07
child 9127 a8c38ed1a674
permissions -rw-r--r--
Fixed bug 2655 - OSX: Window position and global mouse coord spaces are different

Tim McDaniel

On OSX, with revision 8729, the coordinate space for window position and the coordinate space for global mouse position don't match. For a non-fullscreen window, the window position is global relative to the bottom of the menubar. The global mouse position is relative to the top of the screen. This affects Cocoa_WarpMouse and potentially other things as well. Further, the coordinate system for window position is now affected by what screen it is on. For example, if I have two equal size screens oriented side by side such that the tops of the screens are equal in global space, with the menubar on one screen, and a window straddles the two screens, the window's y position makes no sense. The window's y position depends on what screen "most" of the window is on. So if I move the window horizontally just a bit, the y position of my window is now different by the size of the menubar, even though the window was not moved vertically.

I'd like to reiterate that this was a fairly fundamental change (and a breaking change for us). If SDL OSX is to really support multi-display configurations, this is especially problematic.

If the real concern is preventing windows from going under the menubar, then perhaps a solution involving something like overriding [NSWindow constrainFrameRect] would be less problematic than redefining the global window coord space for the main display.
     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(DLOPEN_LIB)
    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(CheckDLOPEN)
    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(NOT OSS_FOUND)
    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(OSS_HEADER_FILE STREQUAL "soundcard.h")
    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(NETBSD OR OPENBSD)
    94       set(HAVE_SDL_AUDIO TRUE)
    95     endif(OSS_FOUND)
    96   endif(OSS)
    97 endmacro(CheckOSS)
    98 
    99 # Requires:
   100 # - n/a
   101 # Optional:
   102 # - ALSA_SHARED opt
   103 # - HAVE_DLOPEN opt
   104 macro(CheckALSA)
   105   if(ALSA)
   106     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H)
   107     if(HAVE_ASOUNDLIB_H)
   108       CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
   109       set(HAVE_ALSA TRUE)
   110       file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
   111       set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
   112       set(SDL_AUDIO_DRIVER_ALSA 1)
   113       if(ALSA_SHARED)
   114         if(NOT HAVE_DLOPEN)
   115           message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
   116         else()
   117           FindLibraryAndSONAME("asound")
   118           set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
   119           set(HAVE_ALSA_SHARED TRUE)
   120         endif(NOT HAVE_DLOPEN)
   121       else(ALSA_SHARED)
   122         list(APPEND EXTRA_LIBS asound)
   123       endif(ALSA_SHARED)
   124       set(HAVE_SDL_AUDIO TRUE)
   125     endif(HAVE_ASOUNDLIB_H)
   126   endif(ALSA)
   127 endmacro(CheckALSA)
   128 
   129 # Requires:
   130 # - PkgCheckModules
   131 # Optional:
   132 # - PULSEAUDIO_SHARED opt
   133 # - HAVE_DLOPEN opt
   134 macro(CheckPulseAudio)
   135   if(PULSEAUDIO)
   136     pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
   137     if(PKG_PULSEAUDIO_FOUND)
   138       set(HAVE_PULSEAUDIO TRUE)
   139       file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
   140       set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
   141       set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
   142       list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
   143       if(PULSEAUDIO_SHARED)
   144         if(NOT HAVE_DLOPEN)
   145           message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
   146         else()
   147           FindLibraryAndSONAME("pulse-simple")
   148           set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
   149           set(HAVE_PULSEAUDIO_SHARED TRUE)
   150         endif(NOT HAVE_DLOPEN)
   151       else(PULSEAUDIO_SHARED)
   152         list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
   153       endif(PULSEAUDIO_SHARED)
   154       set(HAVE_SDL_AUDIO TRUE)
   155     endif(PKG_PULSEAUDIO_FOUND)
   156   endif(PULSEAUDIO)
   157 endmacro(CheckPulseAudio)
   158 
   159 # Requires:
   160 # - PkgCheckModules
   161 # Optional:
   162 # - ESD_SHARED opt
   163 # - HAVE_DLOPEN opt
   164 macro(CheckESD)
   165   if(ESD)
   166     pkg_check_modules(PKG_ESD esound)
   167     if(PKG_ESD_FOUND)
   168       set(HAVE_ESD TRUE)
   169       file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
   170       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
   171       set(SDL_AUDIO_DRIVER_ESD 1)
   172       list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
   173       if(ESD_SHARED)
   174         if(NOT HAVE_DLOPEN)
   175           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
   176         else()
   177           FindLibraryAndSONAME(esd)
   178           set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
   179           set(HAVE_ESD_SHARED TRUE)
   180         endif(NOT HAVE_DLOPEN)
   181       else(ESD_SHARED)
   182         list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   183       endif(ESD_SHARED)
   184       set(HAVE_SDL_AUDIO TRUE)
   185     endif(PKG_ESD_FOUND)
   186   endif(ESD)
   187 endmacro(CheckESD)
   188 
   189 # Requires:
   190 # - n/a
   191 # Optional:
   192 # - ARTS_SHARED opt
   193 # - HAVE_DLOPEN opt
   194 macro(CheckARTS)
   195   if(ARTS)
   196     find_program(ARTS_CONFIG arts-config)
   197     if(ARTS_CONFIG)
   198       execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
   199         OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   200       list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
   201       execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
   202         OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
   203       file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
   204       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
   205       set(SDL_AUDIO_DRIVER_ARTS 1)
   206       set(HAVE_ARTS TRUE)
   207       if(ARTS_SHARED)
   208         if(NOT HAVE_DLOPEN)
   209           message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
   210         else()
   211           # TODO
   212           FindLibraryAndSONAME(artsc)
   213           set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
   214           set(HAVE_ARTS_SHARED TRUE)
   215         endif(NOT HAVE_DLOPEN)
   216       else(ARTS_SHARED)
   217         list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   218       endif(ARTS_SHARED)
   219       set(HAVE_SDL_AUDIO TRUE)
   220     endif(ARTS_CONFIG)
   221   endif(ARTS)
   222 endmacro(CheckARTS)
   223 
   224 # Requires:
   225 # - n/a
   226 # Optional:
   227 # - NAS_SHARED opt
   228 # - HAVE_DLOPEN opt
   229 macro(CheckNAS)
   230   if(NAS)
   231     # TODO: set include paths properly, so the NAS headers are found
   232     check_include_file(audio/audiolib.h HAVE_NAS_H)
   233     find_library(D_NAS_LIB audio)
   234     if(HAVE_NAS_H AND D_NAS_LIB)
   235       set(HAVE_NAS TRUE)
   236       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
   237       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
   238       set(SDL_AUDIO_DRIVER_NAS 1)
   239       if(NAS_SHARED)
   240         if(NOT HAVE_DLOPEN)
   241           message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
   242         else()
   243           FindLibraryAndSONAME("audio")
   244           set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
   245           set(HAVE_NAS_SHARED TRUE)
   246         endif(NOT HAVE_DLOPEN)
   247       else(NAS_SHARED)
   248         list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   249       endif(NAS_SHARED)
   250       set(HAVE_SDL_AUDIO TRUE)
   251     endif(HAVE_NAS_H AND D_NAS_LIB)
   252   endif(NAS)
   253 endmacro(CheckNAS)
   254 
   255 # Requires:
   256 # - n/a
   257 # Optional:
   258 # - SNDIO_SHARED opt
   259 # - HAVE_DLOPEN opt
   260 macro(CheckSNDIO)
   261   if(SNDIO)
   262     # TODO: set include paths properly, so the sndio headers are found
   263     check_include_file(sndio.h HAVE_SNDIO_H)
   264     find_library(D_SNDIO_LIB sndio)
   265     if(HAVE_SNDIO_H AND D_SNDIO_LIB)
   266       set(HAVE_SNDIO TRUE)
   267       file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
   268       set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
   269       set(SDL_AUDIO_DRIVER_SNDIO 1)
   270       if(SNDIO_SHARED)
   271         if(NOT HAVE_DLOPEN)
   272           message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
   273         else()
   274           FindLibraryAndSONAME("sndio")
   275           set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
   276           set(HAVE_SNDIO_SHARED TRUE)
   277         endif(NOT HAVE_DLOPEN)
   278       else(SNDIO_SHARED)
   279         list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
   280       endif(SNDIO_SHARED)
   281       set(HAVE_SDL_AUDIO TRUE)
   282     endif(HAVE_SNDIO_H AND D_SNDIO_LIB)
   283   endif(SNDIO)
   284 endmacro(CheckSNDIO)
   285 
   286 # Requires:
   287 # - PkgCheckModules
   288 # Optional:
   289 # - FUSIONSOUND_SHARED opt
   290 # - HAVE_DLOPEN opt
   291 macro(CheckFusionSound)
   292   if(FUSIONSOUND)
   293     pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
   294     if(PKG_FUSIONSOUND_FOUND)
   295       set(HAVE_FUSIONSOUND TRUE)
   296       file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
   297       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
   298       set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
   299       list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
   300       if(FUSIONSOUND_SHARED)
   301         if(NOT HAVE_DLOPEN)
   302           message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
   303         else()
   304           FindLibraryAndSONAME("fusionsound")
   305           set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
   306           set(HAVE_FUSIONSOUND_SHARED TRUE)
   307         endif(NOT HAVE_DLOPEN)
   308       else(FUSIONSOUND_SHARED)
   309         list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   310       endif(FUSIONSOUND_SHARED)
   311       set(HAVE_SDL_AUDIO TRUE)
   312     endif(PKG_FUSIONSOUND_FOUND)
   313   endif(FUSIONSOUND)
   314 endmacro(CheckFusionSound)
   315 
   316 # Requires:
   317 # - n/a
   318 # Optional:
   319 # - X11_SHARED opt
   320 # - HAVE_DLOPEN opt
   321 macro(CheckX11)
   322   if(VIDEO_X11)
   323     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   324         FindLibraryAndSONAME("${_LIB}")
   325     endforeach()
   326 
   327     find_path(X_INCLUDEDIR X11/Xlib.h)
   328     if(X_INCLUDEDIR)
   329       set(X_CFLAGS "-I${X_INCLUDEDIR}")
   330     endif()
   331 
   332     check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   333     check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   334     check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   335     check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   336     check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   337     check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   338     check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   339     check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   340     check_include_files("X11/Xlib.h;X11/Xproto.h;X11/extensions/Xext.h" HAVE_XEXT_H)
   341 
   342     if(X11_LIB)
   343       if(NOT HAVE_XEXT_H)
   344         message_error("Missing Xext.h, maybe you need to install the libxext-dev package?")
   345       endif()
   346 
   347       set(HAVE_VIDEO_X11 TRUE)
   348       set(HAVE_SDL_VIDEO TRUE)
   349 
   350       file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   351       set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   352       set(SDL_VIDEO_DRIVER_X11 1)
   353 
   354       if(APPLE)
   355         set(X11_SHARED OFF)
   356       endif(APPLE)
   357 
   358       check_function_exists("shmat" HAVE_SHMAT)
   359       if(NOT HAVE_SHMAT)
   360         check_library_exists(ipc shmat "" HAVE_SHMAT)
   361         if(HAVE_SHMAT)
   362           list(APPEND EXTRA_LIBS ipc)
   363         endif(HAVE_SHMAT)
   364         if(NOT HAVE_SHMAT)
   365           add_definitions(-DNO_SHARED_MEMORY)
   366           set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
   367         endif(NOT HAVE_SHMAT)
   368       endif(NOT HAVE_SHMAT)
   369 
   370       if(X11_SHARED)
   371         if(NOT HAVE_DLOPEN)
   372           message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   373           set(HAVE_X11_SHARED FALSE)
   374         else(NOT HAVE_DLOPEN)
   375           set(HAVE_X11_SHARED TRUE)
   376         endif()
   377         if(HAVE_X11_SHARED)
   378           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
   379           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
   380         else(HAVE_X11_SHARED)
   381           list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   382         endif(HAVE_X11_SHARED)
   383       endif(X11_SHARED)
   384 
   385       set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
   386 
   387       set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   388       check_c_source_compiles("
   389           #include <X11/Xlib.h>
   390           #include <X11/Xproto.h>
   391           #include <X11/extensions/Xext.h>
   392           #include <X11/extensions/extutil.h>
   393           extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   394           int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   395       if(HAVE_CONST_XEXT_ADDDISPLAY)
   396         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   397       endif(HAVE_CONST_XEXT_ADDDISPLAY)
   398 
   399       check_c_source_compiles("
   400           #include <X11/Xlib.h>
   401           int main(int argc, char **argv) {
   402             Display *display;
   403             XEvent event;
   404             XGenericEventCookie *cookie = &event.xcookie;
   405             XNextEvent(display, &event);
   406             XGetEventData(display, cookie);
   407             XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   408       if(HAVE_XGENERICEVENT)
   409         set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   410       endif(HAVE_XGENERICEVENT)
   411 
   412       check_c_source_compiles("
   413           #include <X11/Xlibint.h>
   414           extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
   415           int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
   416       if(HAVE_CONST_XDATA32)
   417         set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 1)
   418       endif(HAVE_CONST_XDATA32)
   419 
   420       check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   421 
   422       if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   423         set(HAVE_VIDEO_X11_XCURSOR TRUE)
   424         if(HAVE_X11_SHARED AND XCURSOR_LIB)
   425           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
   426         else(HAVE_X11_SHARED AND XCURSOR_LIB)
   427           list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   428         endif(HAVE_X11_SHARED AND XCURSOR_LIB)
   429         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   430       endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   431 
   432       if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   433         set(HAVE_VIDEO_X11_XINERAMA TRUE)
   434         if(HAVE_X11_SHARED AND XINERAMA_LIB)
   435           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
   436         else(HAVE_X11_SHARED AND XINERAMA_LIB)
   437           list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   438         endif(HAVE_X11_SHARED AND XINERAMA_LIB)
   439         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   440       endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   441 
   442       if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   443         set(HAVE_VIDEO_X11_XINPUT TRUE)
   444         if(HAVE_X11_SHARED AND XI_LIB)
   445           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
   446         else(HAVE_X11_SHARED AND XI_LIB)
   447           list(APPEND EXTRA_LIBS ${XI_LIB})
   448         endif(HAVE_X11_SHARED AND XI_LIB)
   449         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   450 
   451         # Check for multitouch
   452         check_c_source_compiles("
   453             #include <X11/Xlib.h>
   454             #include <X11/Xproto.h>
   455             #include <X11/extensions/XInput2.h>
   456             int event_type = XI_TouchBegin;
   457             XITouchClassInfo *t;
   458             Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   459             {
   460               return (Status)0;
   461             }
   462             int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   463         if(HAVE_XINPUT2_MULTITOUCH)
   464           set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   465         endif(HAVE_XINPUT2_MULTITOUCH)
   466       endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   467 
   468       if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   469         if(HAVE_X11_SHARED AND XRANDR_LIB)
   470           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
   471         else(HAVE_X11_SHARED AND XRANDR_LIB)
   472           list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   473         endif(HAVE_X11_SHARED AND XRANDR_LIB)
   474         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   475         set(HAVE_VIDEO_X11_XRANDR TRUE)
   476       endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   477 
   478       if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   479         if(HAVE_X11_SHARED AND XSS_LIB)
   480           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
   481         else(HAVE_X11_SHARED AND XSS_LIB)
   482           list(APPEND EXTRA_LIBS ${XSS_LIB})
   483         endif(HAVE_X11_SHARED AND XSS_LIB)
   484         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   485         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   486       endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   487 
   488       if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   489         set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   490         set(HAVE_VIDEO_X11_XSHAPE TRUE)
   491       endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   492 
   493       if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   494         if(HAVE_X11_SHARED AND XXF86VM_LIB)
   495           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
   496         else(HAVE_X11_SHARED AND XXF86VM_LIB)
   497           list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
   498         endif(HAVE_X11_SHARED AND XXF86VM_LIB)
   499         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   500         set(HAVE_VIDEO_X11_XVM TRUE)
   501       endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   502 
   503       set(CMAKE_REQUIRED_LIBRARIES)
   504     endif(X11_LIB)
   505   endif(VIDEO_X11)
   506 endmacro(CheckX11)
   507 
   508 macro(CheckMir)
   509 # !!! FIXME: hook up dynamic loading here.
   510     if(VIDEO_MIR)
   511         find_library(MIR_LIB mirclient mircommon egl)
   512         pkg_check_modules(MIR_TOOLKIT mirclient mircommon)
   513         pkg_check_modules(EGL egl)
   514         pkg_check_modules(XKB xkbcommon)
   515 
   516         if (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   517             set(HAVE_VIDEO_MIR TRUE)
   518             set(HAVE_SDL_VIDEO TRUE)
   519 
   520             file(GLOB MIR_SOURCES ${SDL2_SOURCE_DIR}/src/video/mir/*.c)
   521             set(SOURCE_FILES ${SOURCE_FILES} ${MIR_SOURCES})
   522             set(SDL_VIDEO_DRIVER_MIR 1)
   523 
   524             list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
   525             list(APPEND EXTRA_LDFLAGS ${MIR_TOOLKIT_LDFLAGS} ${EGL_LDLAGS} ${XKB_LDLAGS})
   526         endif (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
   527     endif(VIDEO_MIR)
   528 endmacro(CheckMir)
   529 
   530 # Requires:
   531 # - EGL
   532 macro(CheckWayland)
   533 # !!! FIXME: hook up dynamic loading here.
   534   if(VIDEO_WAYLAND)
   535     pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
   536     if(WAYLAND_FOUND)
   537       link_directories(
   538           ${WAYLAND_LIBRARY_DIRS}
   539       )
   540       include_directories(
   541           ${WAYLAND_INCLUDE_DIRS}
   542       )
   543       set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
   544       set(HAVE_VIDEO_WAYLAND TRUE)
   545       set(HAVE_SDL_VIDEO TRUE)
   546 
   547       file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
   548       set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
   549       set(SDL_VIDEO_DRIVER_WAYLAND 1)
   550     endif(WAYLAND_FOUND)
   551   endif(VIDEO_WAYLAND)
   552 endmacro(CheckWayland)
   553 
   554 # Requires:
   555 # - n/a
   556 #
   557 macro(CheckCOCOA)
   558   if(VIDEO_COCOA)
   559     if(APPLE) # Apple always has Cocoa.
   560       set(HAVE_VIDEO_COCOA TRUE)
   561     endif(APPLE)
   562     if(HAVE_VIDEO_COCOA)
   563       file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   564       set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
   565       set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   566       set(SDL_VIDEO_DRIVER_COCOA 1)
   567       set(HAVE_SDL_VIDEO TRUE)
   568     endif(HAVE_VIDEO_COCOA)
   569   endif(VIDEO_COCOA)
   570 endmacro(CheckCOCOA)
   571 
   572 # Requires:
   573 # - PkgCheckModules
   574 # Optional:
   575 # - DIRECTFB_SHARED opt
   576 # - HAVE_DLOPEN opt
   577 macro(CheckDirectFB)
   578   if(VIDEO_DIRECTFB)
   579     pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   580     if(PKG_DIRECTFB_FOUND)
   581       set(HAVE_VIDEO_DIRECTFB TRUE)
   582       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   583       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   584       set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   585       set(SDL_VIDEO_RENDER_DIRECTFB 1)
   586       list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   587       if(DIRECTFB_SHARED)
   588         if(NOT HAVE_DLOPEN)
   589           message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   590         else()
   591           FindLibraryAndSONAME("directfb")
   592           set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
   593           set(HAVE_DIRECTFB_SHARED TRUE)
   594         endif(NOT HAVE_DLOPEN)
   595       else(DIRECTFB_SHARED)
   596         list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   597       endif(DIRECTFB_SHARED)
   598       set(HAVE_SDL_VIDEO TRUE)
   599     endif(PKG_DIRECTFB_FOUND)
   600   endif(VIDEO_DIRECTFB)
   601 endmacro(CheckDirectFB)
   602 
   603 # Requires:
   604 # - nada
   605 macro(CheckOpenGLX11)
   606   if(VIDEO_OPENGL)
   607     check_c_source_compiles("
   608         #include <GL/gl.h>
   609         #include <GL/glx.h>
   610         int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   611 
   612     if(HAVE_VIDEO_OPENGL)
   613       set(HAVE_VIDEO_OPENGL TRUE)
   614       set(SDL_VIDEO_OPENGL 1)
   615       set(SDL_VIDEO_OPENGL_GLX 1)
   616       set(SDL_VIDEO_RENDER_OGL 1)
   617       list(APPEND EXTRA_LIBS GL)
   618     endif(HAVE_VIDEO_OPENGL)
   619   endif(VIDEO_OPENGL)
   620 endmacro(CheckOpenGLX11)
   621 
   622 # Requires:
   623 # - nada
   624 macro(CheckOpenGLESX11)
   625   if(VIDEO_OPENGLES)
   626     check_c_source_compiles("
   627         #include <EGL/egl.h>
   628         int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
   629     if(HAVE_VIDEO_OPENGL_EGL)
   630         set(SDL_VIDEO_OPENGL_EGL 1)
   631     endif(HAVE_VIDEO_OPENGL_EGL) 
   632     check_c_source_compiles("
   633       #include <GLES/gl.h>
   634       #include <GLES/glext.h>
   635       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   636     if(HAVE_VIDEO_OPENGLES_V1)
   637         set(HAVE_VIDEO_OPENGLES TRUE)
   638         set(SDL_VIDEO_OPENGL_ES 1)
   639         set(SDL_VIDEO_RENDER_OGL_ES 1)
   640     endif(HAVE_VIDEO_OPENGLES_V1)
   641     check_c_source_compiles("
   642       #include <GLES2/gl2.h>
   643       #include <GLES2/gl2ext.h>
   644       int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   645     if(HAVE_VIDEO_OPENGLES_V2)
   646         set(HAVE_VIDEO_OPENGLES TRUE)
   647         set(SDL_VIDEO_OPENGL_ES2 1)
   648         set(SDL_VIDEO_RENDER_OGL_ES2 1)
   649     endif(HAVE_VIDEO_OPENGLES_V2)
   650 
   651   endif(VIDEO_OPENGLES)
   652 endmacro(CheckOpenGLESX11)
   653 
   654 # Rquires:
   655 # - nada
   656 # Optional:
   657 # - THREADS opt
   658 # Sets:
   659 # PTHREAD_CFLAGS
   660 # PTHREAD_LIBS
   661 macro(CheckPTHREAD)
   662   if(PTHREADS)
   663     if(LINUX)
   664       set(PTHREAD_CFLAGS "-D_REENTRANT")
   665       set(PTHREAD_LDFLAGS "-pthread")
   666     elseif(BSDI)
   667       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   668       set(PTHREAD_LDFLAGS "")
   669     elseif(DARWIN)
   670       set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   671       # causes Carbon.p complaints?
   672       # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   673       set(PTHREAD_LDFLAGS "")
   674     elseif(FREEBSD)
   675       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   676       set(PTHREAD_LDFLAGS "-pthread")
   677     elseif(NETBSD)
   678       set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   679       set(PTHREAD_LDFLAGS "-lpthread")
   680     elseif(OPENBSD)
   681       set(PTHREAD_CFLAGS "-D_REENTRANT")
   682       set(PTHREAD_LDFLAGS "-pthread")
   683     elseif(SOLARIS)
   684       set(PTHREAD_CFLAGS "-D_REENTRANT")
   685       set(PTHREAD_LDFLAGS "-pthread -lposix4")
   686     elseif(SYSV5)
   687       set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   688       set(PTHREAD_LDFLAGS "")
   689     elseif(AIX)
   690       set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   691       set(PTHREAD_LDFLAGS "-pthread")
   692     elseif(HPUX)
   693       set(PTHREAD_CFLAGS "-D_REENTRANT")
   694       set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   695     elseif(HAIKU)
   696       set(PTHREAD_CFLAGS "-D_REENTRANT")
   697       set(PTHREAD_LDFLAGS "")
   698     else()
   699       set(PTHREAD_CFLAGS "-D_REENTRANT")
   700       set(PTHREAD_LDFLAGS "-lpthread")
   701     endif(LINUX)
   702 
   703     # Run some tests
   704     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   705     check_c_source_runs("
   706         #include <pthread.h>
   707         int main(int argc, char** argv) {
   708           pthread_attr_t type;
   709           pthread_attr_init(&type);
   710           return 0;
   711         }" HAVE_PTHREADS)
   712     if(HAVE_PTHREADS)
   713       set(SDL_THREAD_PTHREAD 1)
   714       list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   715       list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   716       set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   717       list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   718 
   719       check_c_source_compiles("
   720         #include <pthread.h>
   721         int main(int argc, char **argv) {
   722           pthread_mutexattr_t attr;
   723           pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   724           return 0;
   725         }" HAVE_RECURSIVE_MUTEXES)
   726       if(HAVE_RECURSIVE_MUTEXES)
   727         set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   728       else(HAVE_RECURSIVE_MUTEXES)
   729         check_c_source_compiles("
   730             #include <pthread.h>
   731             int main(int argc, char **argv) {
   732               pthread_mutexattr_t attr;
   733               pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   734               return 0;
   735             }" HAVE_RECURSIVE_MUTEXES_NP)
   736         if(HAVE_RECURSIVE_MUTEXES_NP)
   737           set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   738         endif(HAVE_RECURSIVE_MUTEXES_NP)
   739       endif(HAVE_RECURSIVE_MUTEXES)
   740 
   741       if(PTHREADS_SEM)
   742         check_c_source_compiles("#include <pthread.h>
   743                                  #include <semaphore.h>
   744                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
   745         if(HAVE_PTHREADS_SEM)
   746           check_c_source_compiles("
   747               #include <pthread.h>
   748               #include <semaphore.h>
   749               int main(int argc, char **argv) {
   750                   sem_timedwait(NULL, NULL);
   751                   return 0;
   752               }" HAVE_SEM_TIMEDWAIT)
   753         endif(HAVE_PTHREADS_SEM)
   754       endif(PTHREADS_SEM)
   755 
   756       check_c_source_compiles("
   757           #include <pthread.h>
   758           #include <pthread_np.h>
   759           int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   760       check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   761       check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   762       set(CMAKE_REQUIRED_FLAGS)
   763 
   764       set(SOURCE_FILES ${SOURCE_FILES}
   765           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   766           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   767           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   768           ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systls.c
   769           )
   770       if(HAVE_PTHREADS_SEM)
   771         set(SOURCE_FILES ${SOURCE_FILES}
   772             ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   773       else(HAVE_PTHREADS_SEM)
   774         set(SOURCE_FILES ${SOURCE_FILES}
   775             ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   776       endif(HAVE_PTHREADS_SEM)
   777       set(HAVE_SDL_THREADS TRUE)
   778     endif(HAVE_PTHREADS)
   779   endif(PTHREADS)
   780 endmacro(CheckPTHREAD)
   781 
   782 # Requires
   783 # - nada
   784 # Optional:
   785 # Sets:
   786 # USB_LIBS
   787 # USB_CFLAGS
   788 macro(CheckUSBHID)
   789   check_library_exists(usbhid hid_init "" LIBUSBHID)
   790   if(LIBUSBHID)
   791     check_include_file(usbhid.h HAVE_USBHID_H)
   792     if(HAVE_USBHID_H)
   793       set(USB_CFLAGS "-DHAVE_USBHID_H")
   794     endif(HAVE_USBHID_H)
   795 
   796     check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   797     if(HAVE_LIBUSBHID_H)
   798       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   799     endif(HAVE_LIBUSBHID_H)
   800     set(USB_LIBS ${USB_LIBS} usbhid)
   801   else(LIBUSBHID)
   802     check_include_file(usb.h HAVE_USB_H)
   803     if(HAVE_USB_H)
   804       set(USB_CFLAGS "-DHAVE_USB_H")
   805     endif(HAVE_USB_H)
   806     check_include_file(libusb.h HAVE_LIBUSB_H)
   807     if(HAVE_LIBUSB_H)
   808       set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   809     endif(HAVE_LIBUSB_H)
   810     check_library_exists(usb hid_init "" LIBUSB)
   811     if(LIBUSB)
   812       set(USB_LIBS ${USB_LIBS} usb)
   813     endif(LIBUSB)
   814   endif(LIBUSBHID)
   815 
   816   set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   817   set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   818   check_c_source_compiles("
   819        #include <sys/types.h>
   820         #if defined(HAVE_USB_H)
   821         #include <usb.h>
   822         #endif
   823         #ifdef __DragonFly__
   824         # include <bus/usb/usb.h>
   825         # include <bus/usb/usbhid.h>
   826         #else
   827         # include <dev/usb/usb.h>
   828         # include <dev/usb/usbhid.h>
   829         #endif
   830         #if defined(HAVE_USBHID_H)
   831         #include <usbhid.h>
   832         #elif defined(HAVE_LIBUSB_H)
   833         #include <libusb.h>
   834         #elif defined(HAVE_LIBUSBHID_H)
   835         #include <libusbhid.h>
   836         #endif
   837         int main(int argc, char **argv) {
   838           struct report_desc *repdesc;
   839           struct usb_ctl_report *repbuf;
   840           hid_kind_t hidkind;
   841           return 0;
   842         }" HAVE_USBHID)
   843   if(HAVE_USBHID)
   844     check_c_source_compiles("
   845           #include <sys/types.h>
   846           #if defined(HAVE_USB_H)
   847           #include <usb.h>
   848           #endif
   849           #ifdef __DragonFly__
   850           # include <bus/usb/usb.h>
   851           # include <bus/usb/usbhid.h>
   852           #else
   853           # include <dev/usb/usb.h>
   854           # include <dev/usb/usbhid.h>
   855           #endif
   856           #if defined(HAVE_USBHID_H)
   857           #include <usbhid.h>
   858           #elif defined(HAVE_LIBUSB_H)
   859           #include <libusb.h>
   860           #elif defined(HAVE_LIBUSBHID_H)
   861           #include <libusbhid.h>
   862           #endif
   863           int main(int argc, char** argv) {
   864             struct usb_ctl_report buf;
   865             if (buf.ucr_data) { }
   866             return 0;
   867           }" HAVE_USBHID_UCR_DATA)
   868     if(HAVE_USBHID_UCR_DATA)
   869       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   870     endif(HAVE_USBHID_UCR_DATA)
   871 
   872     check_c_source_compiles("
   873           #include <sys/types.h>
   874           #if defined(HAVE_USB_H)
   875           #include <usb.h>
   876           #endif
   877           #ifdef __DragonFly__
   878           #include <bus/usb/usb.h>
   879           #include <bus/usb/usbhid.h>
   880           #else
   881           #include <dev/usb/usb.h>
   882           #include <dev/usb/usbhid.h>
   883           #endif
   884           #if defined(HAVE_USBHID_H)
   885           #include <usbhid.h>
   886           #elif defined(HAVE_LIBUSB_H)
   887           #include <libusb.h>
   888           #elif defined(HAVE_LIBUSBHID_H)
   889           #include <libusbhid.h>
   890           #endif
   891           int main(int argc, char **argv) {
   892             report_desc_t d;
   893             hid_start_parse(d, 1, 1);
   894             return 0;
   895           }" HAVE_USBHID_NEW)
   896     if(HAVE_USBHID_NEW)
   897       set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   898     endif(HAVE_USBHID_NEW)
   899 
   900     check_c_source_compiles("
   901         #include <machine/joystick.h>
   902         int main(int argc, char** argv) {
   903             struct joystick t;
   904             return 0;
   905         }" HAVE_MACHINE_JOYSTICK)
   906     if(HAVE_MACHINE_JOYSTICK)
   907       set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   908     endif(HAVE_MACHINE_JOYSTICK)
   909     set(SDL_JOYSTICK_USBHID 1)
   910     file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   911     set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   912     list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   913     list(APPEND EXTRA_LIBS ${USB_LIBS})
   914     set(HAVE_SDL_JOYSTICK TRUE)
   915 
   916     set(CMAKE_REQUIRED_LIBRARIES)
   917     set(CMAKE_REQUIRED_FLAGS)
   918   endif(HAVE_USBHID)
   919 endmacro(CheckUSBHID)
   920 
   921 # Requires:
   922 # - n/a
   923 macro(CheckRPI)
   924   if(VIDEO_RPI)
   925     set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
   926     set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
   927     set(VIDEO_RPI_LIBS bcm_host )
   928     listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
   929     listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
   930 
   931     set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
   932     set(CMAKE_REQUIRED_LIBRARIES "${VIDEO_RPI_LIBS}")
   933     check_c_source_compiles("
   934         #include <bcm_host.h>
   935         int main(int argc, char **argv) {}" HAVE_VIDEO_RPI)
   936     set(CMAKE_REQUIRED_FLAGS)
   937     set(CMAKE_REQUIRED_LIBRARIES)
   938 
   939     if(SDL_VIDEO AND HAVE_VIDEO_RPI)
   940       set(HAVE_SDL_VIDEO TRUE)
   941       set(SDL_VIDEO_DRIVER_RPI 1)
   942       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
   943       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
   944       list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
   945       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
   946     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
   947   endif(VIDEO_RPI)
   948 endmacro(CheckRPI)