Separated the HIDAPI subsystem from HIDAPI joysticks You can now disable HIDAPI joysticks while retaining the HIDAPI SDL API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d26126d..5f40063 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -186,9 +186,6 @@ if((WINDOWS AND NOT WINDOWS_STORE) OR IOS OR TVOS OR ANDROID)
else()
set(HIDAPI_SKIP_LIBUSB FALSE)
endif()
-if (HIDAPI_SKIP_LIBUSB)
- set(OPT_DEF_HIDAPI ON)
-endif()
# On the other hand, *BSD specifically uses libusb only, so we make a special
# case just for them.
@@ -424,9 +421,9 @@ set_option(SDL_METAL "Enable Metal support" ${APPLE})
set_option(SDL_KMSDRM "Use KMS DRM video driver" ${UNIX_SYS})
dep_option(SDL_KMSDRM_SHARED "Dynamically load KMS DRM support" ON "SDL_KMSDRM" OFF)
set_option(SDL_OFFSCREEN "Use offscreen video driver" OFF)
-option_string(SDL_BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
-option_string(SDL_FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" "OFF")
-set_option(SDL_HIDAPI "Use HIDAPI for low level joystick drivers" ${OPT_DEF_HIDAPI})
+option_string(SDL_BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" OFF)
+option_string(SDL_FOREGROUNDING_SIGNAL "number to use for magic foregrounding signal or 'OFF'" OFF)
+set_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON)
set_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON)
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
@@ -1053,11 +1050,10 @@ if(ANDROID)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_HAPTIC_SOURCES})
set(HAVE_SDL_HAPTIC TRUE)
endif()
- if(SDL_JOYSTICK)
+ if(SDL_HIDAPI)
CheckHIDAPI()
- if(HAVE_HIDAPI)
- set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
- endif()
+ endif()
+ if(SDL_JOYSTICK)
set(SDL_JOYSTICK_ANDROID 1)
file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES})
@@ -1380,11 +1376,14 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS AND NOT HAIKU)
# src/core/unix/*.c is included in a generic if(UNIX) section, elsewhere.
endif()
+ if(SDL_HIDAPI)
+ CheckHIDAPI()
+ endif()
+
if(SDL_JOYSTICK)
if(FREEBSD OR NETBSD OR OPENBSD OR BSDI)
CheckUSBHID()
endif()
- CheckHIDAPI()
if(LINUX AND NOT ANDROID)
set(SDL_JOYSTICK_LINUX 1)
file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/linux/*.c ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
@@ -1706,8 +1705,11 @@ elseif(WINDOWS)
endif()
endif()
- if(SDL_JOYSTICK)
+ if(SDL_HIDAPI)
CheckHIDAPI()
+ endif()
+
+ if(SDL_JOYSTICK)
if(NOT WINDOWS_STORE)
set(SDL_JOYSTICK_RAWINPUT 1)
endif()
@@ -1802,14 +1804,11 @@ elseif(APPLE)
set(SDL_FRAMEWORK_AVFOUNDATION 1)
endif()
- if(SDL_JOYSTICK)
+ if(SDL_HIDAPI)
CheckHIDAPI()
- if(HAVE_HIDAPI)
- if(IOS OR TVOS)
- set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
- set(SDL_FRAMEWORK_COREBLUETOOTH 1)
- endif()
- endif()
+ endif()
+
+ if(SDL_JOYSTICK)
if(IOS OR TVOS)
file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/iphoneos/*.m ${SDL2_SOURCE_DIR}/src/joystick/steam/*.c)
set(SDL_JOYSTICK_MFI 1)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 8d8bed9..23b8793 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -1129,29 +1129,17 @@ macro(CheckUSBHID)
endif()
endmacro()
-# Check for HIDAPI joystick drivers. This is currently a Unix thing, not Windows or macOS!
+# Check for HIDAPI support
macro(CheckHIDAPI)
- if(SDL_HIDAPI)
- if(HIDAPI_SKIP_LIBUSB)
- set(HAVE_HIDAPI TRUE)
- else()
- set(HAVE_HIDAPI FALSE)
- pkg_check_modules(LIBUSB libusb-1.0)
- if (LIBUSB_FOUND)
- check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
- if (HAVE_LIBUSB_H)
- set(HAVE_HIDAPI TRUE)
- endif()
- endif()
- endif()
-
- if(HAVE_HIDAPI)
- set(SDL_JOYSTICK_HIDAPI 1)
- set(HAVE_SDL_JOYSTICK TRUE)
- file(GLOB HIDAPI_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
- set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_SOURCES})
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS} \"-I${SDL2_SOURCE_DIR}/src/hidapi/hidapi\"")
- if(NOT HIDAPI_SKIP_LIBUSB)
+ set(HAVE_HIDAPI TRUE)
+ if(NOT HIDAPI_SKIP_LIBUSB)
+ set(HAVE_LIBUSB FALSE)
+ pkg_check_modules(LIBUSB libusb-1.0)
+ if (LIBUSB_FOUND)
+ check_include_file(libusb.h HAVE_LIBUSB_H ${LIBUSB_CFLAGS})
+ if(HAVE_LIBUSB_H)
+ set(HAVE_LIBUSB TRUE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
if(HIDAPI_ONLY_LIBUSB)
list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
else()
@@ -1161,6 +1149,30 @@ macro(CheckHIDAPI)
endif()
endif()
endif()
+ if(HIDAPI_ONLY_LIBUSB AND NOT HAVE_LIBUSB)
+ set(HAVE_HIDAPI FALSE)
+ endif()
+ endif()
+
+ if(HAVE_HIDAPI)
+ if(ANDROID)
+ set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/android/hid.cpp)
+ endif()
+ if(IOS OR TVOS)
+ set(SOURCE_FILES ${SOURCE_FILES} ${SDL2_SOURCE_DIR}/src/hidapi/ios/hid.m)
+ set(SDL_FRAMEWORK_COREBLUETOOTH 1)
+ endif()
+ set(HAVE_SDL_HIDAPI TRUE)
+
+ if(SDL_JOYSTICK AND SDL_HIDAPI_JOYSTICK)
+ set(SDL_JOYSTICK_HIDAPI 1)
+ set(HAVE_SDL_JOYSTICK TRUE)
+ set(HAVE_HIDAPI_JOYSTICK TRUE)
+ file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/hidapi/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${HIDAPI_JOYSTICK_SOURCES})
+ endif()
+ else()
+ set(SDL_HIDAPI_DISABLED 1)
endif()
endmacro()
diff --git a/configure b/configure
index c9b1952..023f26b 100755
--- a/configure
+++ b/configure
@@ -813,6 +813,7 @@ enable_render
enable_events
enable_joystick
enable_haptic
+enable_hidapi
enable_sensor
enable_power
enable_filesystem
@@ -903,7 +904,7 @@ enable_pthread_sem
enable_directx
enable_xinput
enable_wasapi
-enable_hidapi
+enable_hidapi_joystick
enable_hidapi_libusb
enable_clock_gettime
enable_rpath
@@ -1587,6 +1588,7 @@ Optional Features:
--enable-joystick Enable the joystick subsystem [default=yes]
--enable-haptic Enable the haptic (force feedback) subsystem
[default=yes]
+ --enable-hidapi Enable the HIDAPI subsystem [default=yes]
--enable-sensor Enable the sensor subsystem [default=yes]
--enable-power Enable the power subsystem [default=yes]
--enable-filesystem Enable the filesystem subsystem [default=yes]
@@ -1698,7 +1700,8 @@ Optional Features:
--enable-directx use DirectX for Windows audio/video [default=yes]
--enable-xinput use Xinput for Windows [default=yes]
--enable-wasapi use the Windows WASAPI audio driver [default=yes]
- --enable-hidapi use HIDAPI for low level joystick drivers
+ --enable-hidapi-joystick
+ use HIDAPI for low level joystick drivers
[default=yes]
--enable-hidapi-libusb use libusb for low level joystick drivers
[default=maybe]
@@ -17430,6 +17433,20 @@ $as_echo "#define SDL_HAPTIC_DISABLED 1" >>confdefs.h
else
SUMMARY_modules="${SUMMARY_modules} haptic"
fi
+# Check whether --enable-hidapi was given.
+if test "${enable_hidapi+set}" = set; then :
+ enableval=$enable_hidapi;
+else
+ enable_hidapi=yes
+fi
+
+if test x$enable_hidapi != xyes; then
+
+$as_echo "#define SDL_HIDAPI_DISABLED 1" >>confdefs.h
+
+else
+ SUMMARY_modules="${SUMMARY_modules} hidapi"
+fi
# Check whether --enable-sensor was given.
if test "${enable_sensor+set}" = set; then :
enableval=$enable_sensor;
@@ -24618,11 +24635,11 @@ $as_echo "#define SDL_JOYSTICK_USBHID 1" >>confdefs.h
CheckHIDAPI()
{
- # Check whether --enable-hidapi was given.
-if test "${enable_hidapi+set}" = set; then :
- enableval=$enable_hidapi;
+ # Check whether --enable-hidapi-joystick was given.
+if test "${enable_hidapi_joystick+set}" = set; then :
+ enableval=$enable_hidapi_joystick;
else
- enable_hidapi=yes
+ enable_hidapi_joystick=yes
fi
# Check whether --enable-hidapi-libusb was given.
@@ -24633,13 +24650,7 @@ else
fi
- if test x$enable_hidapi != xyes; then
-
-$as_echo "#define SDL_HIDAPI_DISABLED 1" >>confdefs.h
-
- fi
-
- if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then
+ if test x$enable_hidapi = xyes; then
case "$host" in
# libusb does not support iOS
*-ios-* )
@@ -24742,11 +24753,6 @@ fi
fi
if test x$hidapi_support = xyes; then
-
-$as_echo "#define SDL_JOYSTICK_HIDAPI 1" >>confdefs.h
-
- SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c"
-
if test x$have_libusb_h = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS $LIBUSB_CFLAGS"
if test x$require_hidapi_libusb = xyes; then
@@ -24787,6 +24793,13 @@ $as_echo_n "checking for hidapi support... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hidapi_support" >&5
$as_echo "$hidapi_support" >&6; }
fi
+
+ if test x$enable_joystick = xyes -a x$hidapi_support = xyes -a x$enable_hidapi_joystick = xyes; then
+
+$as_echo "#define SDL_JOYSTICK_HIDAPI 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c"
+ fi
}
CheckClockGettime()
diff --git a/configure.ac b/configure.ac
index aeb2ccd..322f166 100644
--- a/configure.ac
+++ b/configure.ac
@@ -482,6 +482,14 @@ if test x$enable_haptic != xyes; then
else
SUMMARY_modules="${SUMMARY_modules} haptic"
fi
+AC_ARG_ENABLE(hidapi,
+[AS_HELP_STRING([--enable-hidapi], [Enable the HIDAPI subsystem [default=yes]])],
+ , enable_hidapi=yes)
+if test x$enable_hidapi != xyes; then
+ AC_DEFINE(SDL_HIDAPI_DISABLED, 1, [ ])
+else
+ SUMMARY_modules="${SUMMARY_modules} hidapi"
+fi
AC_ARG_ENABLE(sensor,
[AS_HELP_STRING([--enable-sensor], [Enable the sensor subsystem [default=yes]])],
, enable_sensor=yes)
@@ -3411,18 +3419,14 @@ CheckUSBHID()
dnl Check for HIDAPI joystick drivers
CheckHIDAPI()
{
- AC_ARG_ENABLE(hidapi,
-[AS_HELP_STRING([--enable-hidapi], [use HIDAPI for low level joystick drivers [default=yes]])],
- , enable_hidapi=yes)
+ AC_ARG_ENABLE(hidapi-joystick,
+[AS_HELP_STRING([--enable-hidapi-joystick], [use HIDAPI for low level joystick drivers [default=yes]])],
+ , enable_hidapi_joystick=yes)
AC_ARG_ENABLE(hidapi-libusb,
[AS_HELP_STRING([--enable-hidapi-libusb], [use libusb for low level joystick drivers [default=maybe]])],
, enable_hidapi_libusb=maybe)
- if test x$enable_hidapi != xyes; then
- AC_DEFINE(SDL_HIDAPI_DISABLED, 1, [ ])
- fi
-
- if test x$enable_joystick = xyes -a x$enable_hidapi = xyes; then
+ if test x$enable_hidapi = xyes; then
case "$host" in
# libusb does not support iOS
*-ios-* )
@@ -3448,9 +3452,6 @@ CheckHIDAPI()
fi
if test x$hidapi_support = xyes; then
- AC_DEFINE(SDL_JOYSTICK_HIDAPI, 1, [ ])
- SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c"
-
if test x$have_libusb_h = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS $LIBUSB_CFLAGS"
if test x$require_hidapi_libusb = xyes; then
@@ -3482,6 +3483,11 @@ CheckHIDAPI()
AC_MSG_CHECKING(for hidapi support)
AC_MSG_RESULT($hidapi_support)
fi
+
+ if test x$enable_joystick = xyes -a x$hidapi_support = xyes -a x$enable_hidapi_joystick = xyes; then
+ AC_DEFINE(SDL_JOYSTICK_HIDAPI, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/joystick/hidapi/*.c"
+ fi
}
dnl Check for clock_gettime()