cmake/sdlchecks.cmake
changeset 6674 45a21e50ba5e
child 7078 a2bddc1fb02f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cmake/sdlchecks.cmake	Fri Nov 16 09:23:18 2012 -0300
     1.3 @@ -0,0 +1,808 @@
     1.4 +macro(CheckDLOPEN)
     1.5 +  check_function_exists(dlopen HAVE_DLOPEN)
     1.6 +  if(NOT HAVE_DLOPEN)
     1.7 +    foreach(_LIBNAME dl tdl)
     1.8 +      check_library_exists("${_LIBNAME}" "dlopen" "" DLOPEN_LIB)
     1.9 +      if(DLOPEN_LIB)
    1.10 +        list(APPEND EXTRA_LIBS ${_LIBNAME})
    1.11 +        set(_DLLIB ${_LIBNAME})
    1.12 +        set(HAVE_DLOPEN TRUE)
    1.13 +        break()
    1.14 +      endif(DLOPEN_LIB)
    1.15 +    endforeach()
    1.16 +  endif()
    1.17 +
    1.18 +  if(HAVE_DLOPEN)
    1.19 +    if(_DLLIB)
    1.20 +      set(CMAKE_REQUIRED_LIBRARIES ${_DLLIB})
    1.21 +    endif()
    1.22 +    check_c_source_compiles("
    1.23 +       #include <dlfcn.h>
    1.24 +       #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 1020
    1.25 +       #error Use dlcompat for Mac OS X 10.2 compatibility
    1.26 +       #endif
    1.27 +       int main(int argc, char **argv) {}" HAVE_DLOPEN)
    1.28 +    set(CMAKE_REQUIRED_LIBRARIES)
    1.29 +  endif()
    1.30 +
    1.31 +  if (HAVE_DLOPEN)
    1.32 +    set(SDL_LOADSO_DLOPEN 1)
    1.33 +    set(HAVE_SDL_DLOPEN TRUE)
    1.34 +    file(GLOB DLOPEN_SOURCES ${SDL2_SOURCE_DIR}/src/loadso/dlopen/*.c)
    1.35 +    set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
    1.36 +    set(HAVE_SDL_LOADSO TRUE)
    1.37 +  endif()
    1.38 +endmacro(CheckDLOPEN)
    1.39 +
    1.40 +# Requires:
    1.41 +# - n/a
    1.42 +macro(CheckOSS)
    1.43 +  if(OSS)
    1.44 +    set(OSS_HEADER_FILE "sys/soundcard.h")
    1.45 +    check_c_source_compiles("
    1.46 +        #include <sys/soundcard.h>
    1.47 +        int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
    1.48 +    if(NOT OSS_FOUND)
    1.49 +      set(OSS_HEADER_FILE "soundcard.h")
    1.50 +      check_c_source_compiles("
    1.51 +          #include <soundcard.h>
    1.52 +          int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
    1.53 +    endif(NOT OSS_FOUND)
    1.54 +
    1.55 +    if(OSS_FOUND)
    1.56 +      set(HAVE_OSS TRUE)
    1.57 +      file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
    1.58 +      if(OSS_HEADER_FILE STREQUAL "soundcard.h")
    1.59 +        set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
    1.60 +      endif(OSS_HEADER_FILE STREQUAL "soundcard.h")
    1.61 +      set(SDL_AUDIO_DRIVER_OSS 1)
    1.62 +      set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
    1.63 +      if(NETBSD OR OPENBSD)
    1.64 +        list(APPEND EXTRA_LIBS ossaudio)
    1.65 +      endif(NETBSD OR OPENBSD)
    1.66 +      set(HAVE_SDL_AUDIO TRUE)
    1.67 +    endif(OSS_FOUND)
    1.68 +  endif(OSS)
    1.69 +endmacro(CheckOSS)
    1.70 +
    1.71 +# Requires:
    1.72 +# - n/a
    1.73 +# Optional:
    1.74 +# - ALSA_SHARED opt
    1.75 +# - HAVE_DLOPEN opt
    1.76 +macro(CheckALSA)
    1.77 +  if(ALSA)
    1.78 +    CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ASOUNDLIB_H)
    1.79 +    if(HAVE_ASOUNDLIB_H)
    1.80 +      CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
    1.81 +      set(HAVE_ALSA TRUE)
    1.82 +      file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
    1.83 +      set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
    1.84 +      set(SDL_AUDIO_DRIVER_ALSA 1)
    1.85 +      if(ALSA_SHARED)
    1.86 +        if(NOT HAVE_DLOPEN)
    1.87 +          message_warn("You must have SDL_LoadObject() support for dynamic ALSA loading")
    1.88 +        else()
    1.89 +          find_library(_ALSA_LIB asound)
    1.90 +          get_filename_component(F_ALSA_LIB ${_ALSA_LIB} NAME)
    1.91 +          set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${F_ALSA_LIB}\"")
    1.92 +          set(HAVE_ALSA_SHARED TRUE)
    1.93 +        endif(NOT HAVE_DLOPEN)
    1.94 +      else(ALSA_SHARED)
    1.95 +        list(APPEND EXTRA_LIBS asound)
    1.96 +      endif(ALSA_SHARED)
    1.97 +      set(HAVE_SDL_AUDIO TRUE)
    1.98 +    endif(HAVE_ASOUNDLIB_H)
    1.99 +  endif(ALSA)
   1.100 +endmacro(CheckALSA)
   1.101 +
   1.102 +# Requires:
   1.103 +# - PkgCheckModules
   1.104 +# Optional:
   1.105 +# - PULSEAUDIO_SHARED opt
   1.106 +# - HAVE_DLOPEN opt
   1.107 +macro(CheckPulseAudio)
   1.108 +  if(PULSEAUDIO)
   1.109 +    pkg_check_modules(PKG_PULSEAUDIO libpulse-simple)
   1.110 +    if(PKG_PULSEAUDIO_FOUND)
   1.111 +      set(HAVE_PULSEAUDIO TRUE)
   1.112 +      file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
   1.113 +      set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
   1.114 +      set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
   1.115 +      list(APPEND EXTRA_CFLAGS ${PKG_PULSEAUDIO_CFLAGS})
   1.116 +      if(PULSEAUDIO_SHARED)
   1.117 +        if(NOT HAVE_DLOPEN)
   1.118 +          message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
   1.119 +        else()
   1.120 +          find_library(D_PULSE_LIB pulse-simple)
   1.121 +          get_filename_component(F_PULSE_LIB ${D_PULSE_LIB} NAME)
   1.122 +          set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${F_PULSE_LIB}\"")
   1.123 +          set(HAVE_PULSEAUDIO_SHARED TRUE)
   1.124 +        endif(NOT HAVE_DLOPEN)
   1.125 +      else(PULSEAUDIO_SHARED)
   1.126 +        list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
   1.127 +      endif(PULSEAUDIO_SHARED)
   1.128 +      set(HAVE_SDL_AUDIO TRUE)
   1.129 +    endif(PKG_PULSEAUDIO_FOUND)
   1.130 +  endif(PULSEAUDIO)
   1.131 +endmacro(CheckPulseAudio)
   1.132 +
   1.133 +# Requires:
   1.134 +# - PkgCheckModules
   1.135 +# Optional:
   1.136 +# - ESD_SHARED opt
   1.137 +# - HAVE_DLOPEN opt
   1.138 +macro(CheckESD)
   1.139 +  if(ESD)
   1.140 +    pkg_check_modules(PKG_ESD esound)
   1.141 +    if(PKG_ESD_FOUND)
   1.142 +      set(HAVE_ESD TRUE)
   1.143 +      file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
   1.144 +      set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
   1.145 +      set(SDL_AUDIO_DRIVER_ESD 1)
   1.146 +      list(APPEND EXTRA_CFLAGS ${PKG_ESD_CFLAGS})
   1.147 +      if(ESD_SHARED)
   1.148 +        if(NOT HAVE_DLOPEN)
   1.149 +          message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
   1.150 +        else()
   1.151 +          find_library(D_ESD_LIB esd)
   1.152 +          get_filename_component(F_ESD_LIB ${D_ESD_LIB} NAME)
   1.153 +          set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${F_ESD_LIB}\"")
   1.154 +          set(HAVE_ESD_SHARED TRUE)
   1.155 +        endif(NOT HAVE_DLOPEN)
   1.156 +      else(ESD_SHARED)
   1.157 +        list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
   1.158 +      endif(ESD_SHARED)
   1.159 +      set(HAVE_SDL_AUDIO TRUE)
   1.160 +    endif(PKG_ESD_FOUND)
   1.161 +  endif(ESD)
   1.162 +endmacro(CheckESD)
   1.163 +
   1.164 +# Requires:
   1.165 +# - n/a
   1.166 +# Optional:
   1.167 +# - ARTS_SHARED opt
   1.168 +# - HAVE_DLOPEN opt
   1.169 +macro(CheckARTS)
   1.170 +  if(ARTS)
   1.171 +    find_program(ARTS_CONFIG arts-config)
   1.172 +    if(ARTS_CONFIG)
   1.173 +      execute_process(CMD_ARTSCFLAGS ${ARTS_CONFIG} --cflags
   1.174 +        OUTPUT_VARIABLE ARTS_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   1.175 +      list(APPEND EXTRA_CFLAGS ${ARTS_CFLAGS})
   1.176 +      execute_process(CMD_ARTSLIBS ${ARTS_CONFIG} --libs
   1.177 +        OUTPUT_VARIABLE ARTS_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
   1.178 +      file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
   1.179 +      set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
   1.180 +      set(SDL_AUDIO_DRIVER_ARTS 1)
   1.181 +      set(HAVE_ARTS TRUE)
   1.182 +      if(ARTS_SHARED)
   1.183 +        if(NOT HAVE_DLOPEN)
   1.184 +          message_warn("You must have SDL_LoadObject() support for dynamic ARTS loading")
   1.185 +        else()
   1.186 +          # TODO
   1.187 +          find_library(D_ARTS_LIB artsc)
   1.188 +          get_filename_component(F_ARTS_LIB ${D_ARTS_LIB} NAME)
   1.189 +          set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${F_ARTS_LIB}\"")
   1.190 +          set(HAVE_ARTS_SHARED TRUE)
   1.191 +        endif(NOT HAVE_DLOPEN)
   1.192 +      else(ARTS_SHARED)
   1.193 +        list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
   1.194 +      endif(ARTS_SHARED)
   1.195 +      set(HAVE_SDL_AUDIO TRUE)
   1.196 +    endif(ARTS_CONFIG)
   1.197 +  endif(ARTS)
   1.198 +endmacro(CheckARTS)
   1.199 +
   1.200 +# Requires:
   1.201 +# - n/a
   1.202 +# Optional:
   1.203 +# - NAS_SHARED opt
   1.204 +# - HAVE_DLOPEN opt
   1.205 +macro(CheckNAS)
   1.206 +  if(NAS)
   1.207 +    # TODO: set include paths properly, so the NAS headers are found
   1.208 +    check_include_file(audio/audiolib.h HAVE_NAS_H)
   1.209 +    find_library(D_NAS_LIB audio)
   1.210 +    if(HAVE_NAS_H AND D_NAS_LIB)
   1.211 +      set(HAVE_NAS TRUE)
   1.212 +      file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
   1.213 +      set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
   1.214 +      set(SDL_AUDIO_DRIVER_NAS 1)
   1.215 +      if(NAS_SHARED)
   1.216 +        if(NOT HAVE_DLOPEN)
   1.217 +          message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
   1.218 +        else()
   1.219 +          get_filename_component(F_NAS_LIB ${D_NAS_LIB} NAME)
   1.220 +          set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${F_NAS_LIB}\"")
   1.221 +          set(HAVE_NAS_SHARED TRUE)
   1.222 +        endif(NOT HAVE_DLOPEN)
   1.223 +      else(NAS_SHARED)
   1.224 +        list(APPEND EXTRA_LIBS ${D_NAS_LIB})
   1.225 +      endif(NAS_SHARED)
   1.226 +      set(HAVE_SDL_AUDIO TRUE)
   1.227 +    endif(HAVE_NAS_H AND D_NAS_LIB)
   1.228 +  endif(NAS)
   1.229 +endmacro(CheckNAS)
   1.230 +
   1.231 +# Requires:
   1.232 +# - PkgCheckModules
   1.233 +# Optional:
   1.234 +# - FUSIONSOUND_SHARED opt
   1.235 +# - HAVE_DLOPEN opt
   1.236 +macro(CheckFusionSound)
   1.237 +  if(FUSIONSOUND)
   1.238 +    pkg_check_modules(PKG_FUSIONSOUND fusionsound>=1.0.0)
   1.239 +    if(PKG_FUSIONSOUND_FOUND)
   1.240 +      set(HAVE_FUSIONSOUND TRUE)
   1.241 +      file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
   1.242 +      set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
   1.243 +      set(SDL_AUDIO_DRIVER_FUSIONSOUND 1)
   1.244 +      list(APPEND EXTRA_CFLAGS ${PKG_FUSIONSOUND_CFLAGS})
   1.245 +      if(FUSIONSOUND_SHARED)
   1.246 +        if(NOT HAVE_DLOPEN)
   1.247 +          message_warn("You must have SDL_LoadObject() support for dynamic FusionSound loading")
   1.248 +        else()
   1.249 +          find_library(D_FUSIONSOUND_LIB fusionsound)
   1.250 +          get_filename_component(F_FUSIONSOUND_LIB ${D_FUSIONSOUND_LIB} NAME)
   1.251 +          set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${F_FUSIONSOUND_LIB}\"")
   1.252 +          set(HAVE_FUSIONSOUND_SHARED TRUE)
   1.253 +        endif(NOT HAVE_DLOPEN)
   1.254 +      else(FUSIONSOUND_SHARED)
   1.255 +        list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
   1.256 +      endif(FUSIONSOUND_SHARED)
   1.257 +      set(HAVE_SDL_AUDIO TRUE)
   1.258 +    endif(PKG_FUSIONSOUND_FOUND)
   1.259 +  endif(FUSIONSOUND)
   1.260 +endmacro(CheckFusionSound)
   1.261 +
   1.262 +# Requires:
   1.263 +# - n/a
   1.264 +# Optional:
   1.265 +# - X11_SHARED opt
   1.266 +# - HAVE_DLOPEN opt
   1.267 +macro(CheckX11)
   1.268 +  if(VIDEO_X11)
   1.269 +    foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
   1.270 +      string(TOUPPER ${_LIB} _LNAME)
   1.271 +      find_library(${_LNAME}_LIB ${_LIB})
   1.272 +      if(${_LNAME}_LIB)
   1.273 +        # reduce the library name for shared linking
   1.274 +        get_filename_component(_TMP ${${_LNAME}_LIB} NAME)
   1.275 +        set(${_LNAME}_LIB ${_TMP})
   1.276 +      endif()
   1.277 +    endforeach()
   1.278 +
   1.279 +    check_include_file(X11/Xcursor/Xcursor.h HAVE_XCURSOR_H)
   1.280 +    check_include_file(X11/extensions/Xinerama.h HAVE_XINERAMA_H)
   1.281 +    check_include_file(X11/extensions/XInput2.h HAVE_XINPUT_H)
   1.282 +    check_include_file(X11/extensions/Xrandr.h HAVE_XRANDR_H)
   1.283 +    check_include_file(X11/extensions/Xrender.h HAVE_XRENDER_H)
   1.284 +    check_include_file(X11/extensions/scrnsaver.h HAVE_XSS_H)
   1.285 +    check_include_file(X11/extensions/shape.h HAVE_XSHAPE_H)
   1.286 +    check_include_files("X11/Xlib.h;X11/extensions/xf86vmode.h" HAVE_XF86VM_H)
   1.287 +
   1.288 +    if(X11_LIB)
   1.289 +      set(HAVE_VIDEO_X11 TRUE)
   1.290 +      set(HAVE_SDL_VIDEO TRUE)
   1.291 +
   1.292 +      file(GLOB X11_SOURCES ${SDL2_SOURCE_DIR}/src/video/x11/*.c)
   1.293 +      set(SOURCE_FILES ${SOURCE_FILES} ${X11_SOURCES})
   1.294 +      set(SDL_VIDEO_DRIVER_X11 1)
   1.295 +
   1.296 +      if(HAVE_GCC_FVISIBILITY)
   1.297 +        set(X11_SYMBOLS_PRIVATE TRUE)
   1.298 +      else()
   1.299 +        set(X11_SYMBOLS_PRIVATE FALSE)
   1.300 +      endif(HAVE_GCC_FVISIBILITY)
   1.301 +
   1.302 +      if(APPLE)
   1.303 +        set(X11_SHARED OFF)
   1.304 +        set(X11_SYMBOLS_PRIVATE TRUE)
   1.305 +      endif(APPLE)
   1.306 +
   1.307 +      check_function_exists("shmat" HAVE_SHMAT)
   1.308 +      if(NOT HAVE_SHMAT)
   1.309 +        check_library_exists(ipc shmat "" HAVE_SHMAT)
   1.310 +        if(HAVE_SHMAT)
   1.311 +          list(APPEND EXTRA_LIBS ipc)
   1.312 +        endif(HAVE_SHMAT)
   1.313 +        if(NOT HAVE_SHMAT)
   1.314 +          add_definitions(-DNO_SHARED_MEMORY)
   1.315 +        endif(NOT HAVE_SHMAT)
   1.316 +      endif(NOT HAVE_SHMAT)
   1.317 +
   1.318 +      if(X11_SHARED)
   1.319 +        if(NOT HAVE_DLOPEN)
   1.320 +          message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
   1.321 +          set(HAVE_X11_SHARED FALSE)
   1.322 +          if(X11_SYMBOLS_PRIVATE)
   1.323 +            message_warn("You must have gcc4 (-fvisibility=hidden) for dynamic X11 loading")
   1.324 +            set(HAVE_X11_SHARED TRUE)
   1.325 +          endif(X11_SYMBOLS_PRIVATE)
   1.326 +        else(NOT HAVE_DLOPEN)
   1.327 +          set(HAVE_X11_SHARED TRUE)
   1.328 +        endif()
   1.329 +        if(HAVE_X11_SHARED)
   1.330 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB}\"")
   1.331 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB}\"")
   1.332 +        else(HAVE_X11_SHARED)
   1.333 +          list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
   1.334 +        endif(HAVE_X11_SHARED)
   1.335 +      endif(X11_SHARED)
   1.336 +
   1.337 +      set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
   1.338 +      check_c_source_compiles("
   1.339 +          #include <X11/Xlib.h>
   1.340 +          #include <X11/Xproto.h>
   1.341 +          #include <X11/extensions/Xext.h>
   1.342 +          #include <X11/extensions/extutil.h>
   1.343 +          extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
   1.344 +          int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
   1.345 +      if(HAVE_CONST_XEXT_ADDDISPLAY)
   1.346 +        set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
   1.347 +      endif(HAVE_CONST_XEXT_ADDDISPLAY)
   1.348 +
   1.349 +      check_c_source_compiles("
   1.350 +          #include <X11/Xlib.h>
   1.351 +          int main(int argc, char **argv) {
   1.352 +            Display *display;
   1.353 +            XEvent event;
   1.354 +            XGenericEventCookie *cookie = &event.xcookie;
   1.355 +            XNextEvent(display, &event);
   1.356 +            XGetEventData(display, cookie);
   1.357 +            XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
   1.358 +      if(HAVE_XGENERICEVENT)
   1.359 +        set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
   1.360 +      endif(HAVE_XGENERICEVENT)
   1.361 +
   1.362 +      check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
   1.363 +
   1.364 +      if(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   1.365 +        set(HAVE_VIDEO_X11_XCURSOR TRUE)
   1.366 +        if(HAVE_X11_SHARED AND XCURSOR_LIB)
   1.367 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB}\"")
   1.368 +        else(HAVE_X11_SHARED AND XCURSOR_LIB)
   1.369 +          list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
   1.370 +        endif(HAVE_X11_SHARED AND XCURSOR_LIB)
   1.371 +        set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
   1.372 +      endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
   1.373 +
   1.374 +      if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   1.375 +        set(HAVE_VIDEO_X11_XINERAMA TRUE)
   1.376 +        if(HAVE_X11_SHARED AND XINERAMA_LIB)
   1.377 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB}\"")
   1.378 +        else(HAVE_X11_SHARED AND XINERAMA_LIB)
   1.379 +          list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
   1.380 +        endif(HAVE_X11_SHARED AND XINERAMA_LIB)
   1.381 +        set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
   1.382 +      endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
   1.383 +
   1.384 +      if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   1.385 +        set(HAVE_VIDEO_X11_XINPUT TRUE)
   1.386 +        if(HAVE_X11_SHARED AND XI_LIB)
   1.387 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB}\"")
   1.388 +        else(HAVE_X11_SHARED AND XI_LIB)
   1.389 +          list(APPEND EXTRA_LIBS ${XI_LIB})
   1.390 +        endif(HAVE_X11_SHARED AND XI_LIB)
   1.391 +        set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
   1.392 +
   1.393 +        # Check for multitouch
   1.394 +        check_c_source_compiles("
   1.395 +            #include <X11/Xlib.h>
   1.396 +            #include <X11/Xproto.h>
   1.397 +            #include <X11/extensions/XInput2.h>
   1.398 +            int event_type = XI_TouchBegin;
   1.399 +            XITouchClassInfo *t;
   1.400 +            Status XIAllowTouchEvents(Display *a,int b,unsigned int c,Window d,int f)
   1.401 +            {
   1.402 +              return (Status)0;
   1.403 +            }
   1.404 +            int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
   1.405 +        if(HAVE_XINPUT2_MULTITOUCH)
   1.406 +          set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
   1.407 +        endif(HAVE_XINPUT2_MULTITOUCH)
   1.408 +      endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
   1.409 +
   1.410 +      if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   1.411 +        if(HAVE_X11_SHARED AND XRANDR_LIB)
   1.412 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB}\"")
   1.413 +        else(HAVE_X11_SHARED AND XRANDR_LIB)
   1.414 +          list(APPEND EXTRA_LIBS ${XRANDR_LIB})
   1.415 +        endif(HAVE_X11_SHARED AND XRANDR_LIB)
   1.416 +        set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
   1.417 +        set(HAVE_VIDEO_X11_XRANDR TRUE)
   1.418 +      endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
   1.419 +
   1.420 +      if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   1.421 +        if(HAVE_X11_SHARED AND XSS_LIB)
   1.422 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB}\"")
   1.423 +        else(HAVE_X11_SHARED AND XSS_LIB)
   1.424 +          list(APPEND EXTRA_LIBS ${XSS_LIB})
   1.425 +        endif(HAVE_X11_SHARED AND XSS_LIB)
   1.426 +        set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
   1.427 +        set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
   1.428 +      endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
   1.429 +
   1.430 +      if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   1.431 +        set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
   1.432 +        set(HAVE_VIDEO_X11_XSHAPE TRUE)
   1.433 +      endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
   1.434 +
   1.435 +      if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   1.436 +        if(HAVE_X11_SHARED AND XF86VMODE_LIB)
   1.437 +          set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XF86VMODE_LIB}\"")
   1.438 +        else(HAVE_X11_SHARED AND XF86VMODE_LIB)
   1.439 +          list(APPEND EXTRA_LIBS ${XF86VMODE_LIB})
   1.440 +        endif(HAVE_X11_SHARED AND XF86VMODE_LIB)
   1.441 +        set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
   1.442 +        set(HAVE_VIDEO_X11_XVM TRUE)
   1.443 +      endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
   1.444 +
   1.445 +      set(CMAKE_REQUIRED_LIBRARIES)
   1.446 +    endif(X11_LIB)
   1.447 +  endif(VIDEO_X11)
   1.448 +endmacro(CheckX11)
   1.449 +
   1.450 +# Requires:
   1.451 +# - n/a
   1.452 +#
   1.453 +macro(CheckCOCOA)
   1.454 +  if(VIDEO_COCOA)
   1.455 +    check_c_source_compiles("
   1.456 +        #import <Cocoa/Cocoa.h>
   1.457 +        int main (int argc, char** argv) {}" HAVE_VIDEO_COCOA)
   1.458 +    if(HAVE_VIDEO_COCOA)
   1.459 +      file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
   1.460 +      set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
   1.461 +      set(SDL_VIDEO_DRIVER_COCOA 1)
   1.462 +      set(HAVE_SDL_VIDEO TRUE)
   1.463 +    endif(HAVE_VIDEO_COCOA)
   1.464 +  endif(VIDEO_COCOA)
   1.465 +endmacro(CheckCOCOA)
   1.466 +
   1.467 +# Requires:
   1.468 +# - PkgCheckModules
   1.469 +# Optional:
   1.470 +# - DIRECTFB_SHARED opt
   1.471 +# - HAVE_DLOPEN opt
   1.472 +macro(CheckDirectFB)
   1.473 +  if(VIDEO_DIRECTFB)
   1.474 +    pkg_check_modules(PKG_DIRECTFB directfb>=1.0.0)
   1.475 +    if(PKG_DIRECTFB_FOUND)
   1.476 +      set(HAVE_VIDEO_DIRECTFB TRUE)
   1.477 +      file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
   1.478 +      set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
   1.479 +      set(SDL_VIDEO_DRIVER_DIRECTFB 1)
   1.480 +      set(SDL_VIDEO_RENDER_DIRECTFB 1)
   1.481 +      list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
   1.482 +      if(DIRECTFB_SHARED)
   1.483 +        if(NOT HAVE_DLOPEN)
   1.484 +          message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
   1.485 +        else()
   1.486 +          find_library(D_DIRECTFB_LIB directfb)
   1.487 +          get_filename_component(F_DIRECTFB_LIB ${D_DIRECTFB_LIB} NAME)
   1.488 +          set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${F_DIRECTFB_LIB}\"")
   1.489 +          set(HAVE_DIRECTFB_SHARED TRUE)
   1.490 +        endif(NOT HAVE_DLOPEN)
   1.491 +      else(DIRECTFB_SHARED)
   1.492 +        list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
   1.493 +      endif(DIRECTFB_SHARED)
   1.494 +      set(HAVE_SDL_VIDEO TRUE)
   1.495 +    endif(PKG_DIRECTFB_FOUND)
   1.496 +  endif(VIDEO_DIRECTFB)
   1.497 +endmacro(CheckDirectFB)
   1.498 +
   1.499 +# Requires:
   1.500 +# - nada
   1.501 +macro(CheckOpenGLX11)
   1.502 +  if(VIDEO_OPENGL)
   1.503 +    check_c_source_compiles("
   1.504 +        #include <GL/gl.h>
   1.505 +        #include <GL/glx.h>
   1.506 +        int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
   1.507 +
   1.508 +    if(HAVE_VIDEO_OPENGL)
   1.509 +      set(HAVE_VIDEO_OPENGL TRUE)
   1.510 +      set(SDL_VIDEO_OPENGL 1)
   1.511 +      set(SDL_VIDEO_OPENGL_GLX 1)
   1.512 +      set(SDL_VIDEO_RENDER_OGL 1)
   1.513 +      list(APPEND EXTRA_LIBS GL)
   1.514 +    endif(HAVE_VIDEO_OPENGL)
   1.515 +  endif(VIDEO_OPENGL)
   1.516 +endmacro(CheckOpenGLX11)
   1.517 +
   1.518 +# Requires:
   1.519 +# - nada
   1.520 +macro(CheckOpenGLESX11)
   1.521 +  if(VIDEO_OPENGLES)
   1.522 +    check_c_source_compiles("
   1.523 +        #include <EGL/egl.h>
   1.524 +        int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES)
   1.525 +    if(HAVE_VIDEO_OPENGLES)
   1.526 +      check_c_source_compiles("
   1.527 +          #include <GLES/gl.h>
   1.528 +          #include <GLES/glext.h>
   1.529 +          int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
   1.530 +      if(HAVE_VIDEO_OPENGLES_V1)
   1.531 +        set(SDL_VIDEO_OPENGL_ES 1)
   1.532 +        set(SDL_VIDEO_RENDER_OGL_ES 1)
   1.533 +      endif(HAVE_VIDEO_OPENGLES_V1)
   1.534 +      check_c_source_compiles("
   1.535 +          #include <GLES2/gl2.h>
   1.536 +          #include <GLES2/gl2ext.h>
   1.537 +          int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
   1.538 +      if(HAVE_VIDEO_OPENGLES_V2)
   1.539 +        set(SDL_VIDEO_OPENGL_ES2 1)
   1.540 +        set(SDL_VIDEO_RENDER_OGL_ES2 1)
   1.541 +      endif(HAVE_VIDEO_OPENGLES_V2)
   1.542 +    endif(HAVE_VIDEO_OPENGLES)
   1.543 +  endif(VIDEO_OPENGLES)
   1.544 +endmacro(CheckOpenGLESX11)
   1.545 +
   1.546 +# Rquires:
   1.547 +# - nada
   1.548 +# Optional:
   1.549 +# - THREADS opt
   1.550 +# Sets:
   1.551 +# PTHREAD_CFLAGS
   1.552 +# PTHREAD_LIBS
   1.553 +macro(CheckPTHREAD)
   1.554 +  if(PTHREADS)
   1.555 +    if(LINUX)
   1.556 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
   1.557 +      set(PTHREAD_LDFLAGS "-lpthread")
   1.558 +    elseif(BSDI)
   1.559 +      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   1.560 +      set(PTHREAD_LDFLAGS "")
   1.561 +    elseif(DARWIN)
   1.562 +      set(PTHREAD_CFLAGS "-D_THREAD_SAFE")
   1.563 +      # causes Carbon.p complaints?
   1.564 +      # set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   1.565 +      set(PTHREAD_LDFLAGS "")
   1.566 +    elseif(FREEBSD)
   1.567 +      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   1.568 +      set(PTHREAD_LDFLAGS "-pthread")
   1.569 +    elseif(NETBSD)
   1.570 +      set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE")
   1.571 +      set(PTHREAD_LDFLAGS "-lpthread")
   1.572 +    elseif(OPENBSD)
   1.573 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
   1.574 +      set(PTHREAD_LDFLAGS "-pthread")
   1.575 +    elseif(SOLARIS)
   1.576 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
   1.577 +      set(PTHREAD_LDFLAGS "-pthread -lposix4")
   1.578 +    elseif(SYSV5)
   1.579 +      set(PTHREAD_CFLAGS "-D_REENTRANT -Kthread")
   1.580 +      set(PTHREAD_LDFLAGS "")
   1.581 +    elseif(AIX)
   1.582 +      set(PTHREAD_CFLAGS "-D_REENTRANT -mthreads")
   1.583 +      set(PTHREAD_LDFLAGS "-pthread")
   1.584 +    elseif(HPUX)
   1.585 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
   1.586 +      set(PTHREAD_LDFLAGS "-L/usr/lib -pthread")
   1.587 +    else()
   1.588 +      set(PTHREAD_CFLAGS "-D_REENTRANT")
   1.589 +      set(PTHREAD_LDFLAGS "-lpthread")
   1.590 +    endif(LINUX)
   1.591 +
   1.592 +    # Run some tests
   1.593 +    set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
   1.594 +    check_c_source_runs("
   1.595 +        #include <pthread.h>
   1.596 +        int main(int argc, char** argv) {
   1.597 +          pthread_attr_t type;
   1.598 +          pthread_attr_init(&type);
   1.599 +          return 0;
   1.600 +        }" HAVE_PTHREADS)
   1.601 +    if(HAVE_PTHREADS)
   1.602 +      set(SDL_THREAD_PTHREAD 1)
   1.603 +      list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
   1.604 +      list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
   1.605 +      set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
   1.606 +      list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
   1.607 +
   1.608 +      check_c_source_compiles("
   1.609 +        #include <pthread.h>
   1.610 +        int main(int argc, char **argv) {
   1.611 +          pthread_mutexattr_t attr;
   1.612 +          pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   1.613 +        }" HAVE_RECURSIVE_MUTEXES)
   1.614 +      if(HAVE_RECURSIVE_MUTEXES)
   1.615 +        set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
   1.616 +      else(HAVE_RECURSIVE_MUTEXES)
   1.617 +        check_c_source_compiles("
   1.618 +            #include <pthread.h>
   1.619 +            int main(int argc, char **argv) {
   1.620 +              pthread_mutexattr_t attr;
   1.621 +              pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
   1.622 +            }" HAVE_RECURSIVE_MUTEXES_NP)
   1.623 +        if(HAVE_RECURSIVE_MUTEXES_NP)
   1.624 +          set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
   1.625 +        endif(HAVE_RECURSIVE_MUTEXES_NP)
   1.626 +      endif(HAVE_RECURSIVE_MUTEXES)
   1.627 +
   1.628 +      if(PTHREADS_SEM)
   1.629 +        check_c_source_compiles("#include <pthread.h>
   1.630 +                                 #include <semaphore.h>" HAVE_PTHREADS_SEM)
   1.631 +        if(HAVE_PTHREADS_SEM)
   1.632 +          check_c_source_compiles("
   1.633 +              #include <pthread.h>
   1.634 +              #include <semaphore.h>
   1.635 +              int main(int argc, char **argv) {
   1.636 +                  sem_timedwait(NULL, NULL);
   1.637 +                  return 0;
   1.638 +              }" HAVE_SEM_TIMEDWAIT)
   1.639 +        endif(HAVE_PTHREADS_SEM)
   1.640 +      endif(PTHREADS_SEM)
   1.641 +
   1.642 +      check_c_source_compiles("
   1.643 +          #include <pthread.h>
   1.644 +          int main(int argc, char** argv) {
   1.645 +              pthread_spin_trylock(NULL);
   1.646 +              return 0;
   1.647 +          }" HAVE_PTHREAD_SPINLOCK)
   1.648 +
   1.649 +      check_c_source_compiles("
   1.650 +          #include <pthread.h>
   1.651 +          #include <pthread_np.h>
   1.652 +          int main(int argc, char** argv) { return 0; }" HAVE_PTHREAD_NP_H)
   1.653 +      check_function_exists(pthread_setname_np HAVE_PTHREAD_setNAME_NP)
   1.654 +      check_function_exists(pthread_set_name_np HAVE_PTHREAD_set_NAME_NP)
   1.655 +      set(CMAKE_REQUIRED_FLAGS)
   1.656 +
   1.657 +      set(SOURCE_FILES ${SOURCE_FILES}
   1.658 +          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c
   1.659 +          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c   # Can be faked, if necessary
   1.660 +          ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c    # Can be faked, if necessary
   1.661 +          )
   1.662 +      if(HAVE_PTHREADS_SEM)
   1.663 +        set(SOURCE_FILES ${SOURCE_FILES}
   1.664 +            ${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
   1.665 +      else(HAVE_PTHREADS_SEM)
   1.666 +        set(SOURCE_FILES ${SOURCE_FILES}
   1.667 +            ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
   1.668 +      endif(HAVE_PTHREADS_SEM)
   1.669 +      set(HAVE_SDL_THREADS TRUE)
   1.670 +    endif(HAVE_PTHREADS)
   1.671 +  endif(PTHREADS)
   1.672 +endmacro(CheckPTHREAD)
   1.673 +
   1.674 +# Requires
   1.675 +# - nada
   1.676 +# Optional:
   1.677 +# Sets:
   1.678 +# USB_LIBS
   1.679 +# USB_CFLAGS
   1.680 +macro(CheckUSBHID)
   1.681 +  check_library_exists(usbhid hid_init "" LIBUSBHID)
   1.682 +  if(LIBUSBHID)
   1.683 +    check_include_file(usbhid.h HAVE_USBHID_H)
   1.684 +    if(HAVE_USBHID_H)
   1.685 +      set(USB_CFLAGS "-DHAVE_USBHID_H")
   1.686 +    endif(HAVE_USBHID_H)
   1.687 +
   1.688 +    check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
   1.689 +    if(HAVE_LIBUSBHID_H)
   1.690 +      set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
   1.691 +    endif(HAVE_LIBUSBHID_H)
   1.692 +    set(USB_LIBS ${USB_LIBS} usbhid)
   1.693 +  else(LIBUSBHID)
   1.694 +    check_include_file(usb.h HAVE_USB_H)
   1.695 +    if(HAVE_USB_H)
   1.696 +      set(USB_CFLAGS "-DHAVE_USB_H")
   1.697 +    endif(HAVE_USB_H)
   1.698 +    check_include_file(libusb.h HAVE_LIBUSB_H)
   1.699 +    if(HAVE_LIBUSB_H)
   1.700 +      set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
   1.701 +    endif(HAVE_LIBUSB_H)
   1.702 +    check_library_exists(usb hid_init "" LIBUSB)
   1.703 +    if(LIBUSB)
   1.704 +      set(USB_LIBS ${USB_LIBS} usb)
   1.705 +    endif(LIBUSB)
   1.706 +  endif(LIBUSBHID)
   1.707 +
   1.708 +  set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
   1.709 +  set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
   1.710 +  check_c_source_compiles("
   1.711 +       #include <sys/types.h>
   1.712 +        #if defined(HAVE_USB_H)
   1.713 +        #include <usb.h>
   1.714 +        #endif
   1.715 +        #ifdef __DragonFly__
   1.716 +        # include <bus/usb/usb.h>
   1.717 +        # include <bus/usb/usbhid.h>
   1.718 +        #else
   1.719 +        # include <dev/usb/usb.h>
   1.720 +        # include <dev/usb/usbhid.h>
   1.721 +        #endif
   1.722 +        #if defined(HAVE_USBHID_H)
   1.723 +        #include <usbhid.h>
   1.724 +        #elif defined(HAVE_LIBUSB_H)
   1.725 +        #include <libusb.h>
   1.726 +        #elif defined(HAVE_LIBUSBHID_H)
   1.727 +        #include <libusbhid.h>
   1.728 +        #endif
   1.729 +        int main(int argc, char **argv) {
   1.730 +          struct report_desc *repdesc;
   1.731 +          struct usb_ctl_report *repbuf;
   1.732 +          hid_kind_t hidkind;
   1.733 +          return 0;
   1.734 +        }" HAVE_USBHID)
   1.735 +  if(HAVE_USBHID)
   1.736 +    check_c_source_compiles("
   1.737 +          #include <sys/types.h>
   1.738 +          #if defined(HAVE_USB_H)
   1.739 +          #include <usb.h>
   1.740 +          #endif
   1.741 +          #ifdef __DragonFly__
   1.742 +          # include <bus/usb/usb.h>
   1.743 +          # include <bus/usb/usbhid.h>
   1.744 +          #else
   1.745 +          # include <dev/usb/usb.h>
   1.746 +          # include <dev/usb/usbhid.h>
   1.747 +          #endif
   1.748 +          #if defined(HAVE_USBHID_H)
   1.749 +          #include <usbhid.h>
   1.750 +          #elif defined(HAVE_LIBUSB_H)
   1.751 +          #include <libusb.h>
   1.752 +          #elif defined(HAVE_LIBUSBHID_H)
   1.753 +          #include <libusbhid.h>
   1.754 +          #endif
   1.755 +          int main(int argc, char** argv) {
   1.756 +            struct usb_ctl_report buf;
   1.757 +            if (buf.ucr_data) { }
   1.758 +            return 0;
   1.759 +          }" HAVE_USBHID_UCR_DATA)
   1.760 +    if(HAVE_USBHID_UCR_DATA)
   1.761 +      set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
   1.762 +    endif(HAVE_USBHID_UCR_DATA)
   1.763 +
   1.764 +    check_c_source_compiles("
   1.765 +          #include <sys/types.h>
   1.766 +          #if defined(HAVE_USB_H)
   1.767 +          #include <usb.h>
   1.768 +          #endif
   1.769 +          #ifdef __DragonFly__
   1.770 +          #include <bus/usb/usb.h>
   1.771 +          #include <bus/usb/usbhid.h>
   1.772 +          #else
   1.773 +          #include <dev/usb/usb.h>
   1.774 +          #include <dev/usb/usbhid.h>
   1.775 +          #endif
   1.776 +          #if defined(HAVE_USBHID_H)
   1.777 +          #include <usbhid.h>
   1.778 +          #elif defined(HAVE_LIBUSB_H)
   1.779 +          #include <libusb.h>
   1.780 +          #elif defined(HAVE_LIBUSBHID_H)
   1.781 +          #include <libusbhid.h>
   1.782 +          #endif
   1.783 +          int main(int argc, char **argv) {
   1.784 +            report_desc_t d;
   1.785 +            hid_start_parse(d, 1, 1);
   1.786 +            return 0;
   1.787 +          }" HAVE_USBHID_NEW)
   1.788 +    if(HAVE_USBHID_NEW)
   1.789 +      set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
   1.790 +    endif(HAVE_USBHID_NEW)
   1.791 +
   1.792 +    check_c_source_compiles("
   1.793 +        #include <machine/joystick.h>
   1.794 +        int main(int argc, char** argv) {
   1.795 +            struct joystick t;
   1.796 +            return 0;
   1.797 +        }" HAVE_MACHINE_JOYSTICK)
   1.798 +    if(HAVE_MACHINE_JOYSTICK)
   1.799 +      set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
   1.800 +    endif(HAVE_MACHINE_JOYSTICK)
   1.801 +    set(SDL_JOYSTICK_USBHID 1)
   1.802 +    file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
   1.803 +    set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
   1.804 +    list(APPEND EXTRA_CFLAGS ${USB_CFLAGS})
   1.805 +    list(APPEND EXTRA_LIBS ${USB_LIBS})
   1.806 +    set(HAVE_SDL_JOYSTICK TRUE)
   1.807 +
   1.808 +    set(CMAKE_REQUIRED_LIBRARIES)
   1.809 +    set(CMAKE_REQUIRED_FLAGS)
   1.810 +  endif(HAVE_USBHID)
   1.811 +endmacro(CheckUSBHID)