Fixed building with libusb not dynamicaly loaded
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 7e25075..80f31c7 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -1186,7 +1186,7 @@ macro(CheckHIDAPI)
set(HAVE_LIBUSB TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBUSB_CFLAGS}")
if(HIDAPI_ONLY_LIBUSB)
- list(APPEND EXTRA_LIBS ${LIBUSB_LIBS})
+ list(APPEND EXTRA_LIBS ${LIBUSB_LIBRARIES})
elseif(OS2)
set(SDL_LIBUSB_DYNAMIC "\"usb100.dll\"")
else()
diff --git a/configure.ac b/configure.ac
index b539f61..d27fa9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3581,6 +3581,7 @@ CheckHIDAPI()
if test x$hidapi_support = xyes; then
if test x$have_libusb_h = xyes; then
+ AC_DEFINE(HAVE_LIBUSB)
EXTRA_CFLAGS="$EXTRA_CFLAGS $LIBUSB_CFLAGS"
if test x$require_hidapi_libusb = xyes; then
EXTRA_LDFLAGS="$EXTRA_LDFLAGS $LIBUSB_LIBS"
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 2d21b37..204a12e 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -224,6 +224,7 @@
#cmakedefine HAVE_INOTIFY_INIT 1
#cmakedefine HAVE_INOTIFY_INIT1 1
#cmakedefine HAVE_INOTIFY 1
+#cmakedefine HAVE_LIBUSB 1
#cmakedefine HAVE_O_CLOEXEC 1
/* Apple platforms might be building universal binaries, where Intel builds
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 7b6eb5d..56b5302 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -227,6 +227,7 @@
#undef HAVE_IBUS_IBUS_H
#undef HAVE_IMMINTRIN_H
#undef HAVE_LIBUDEV_H
+#undef HAVE_LIBUSB
#undef HAVE_LIBSAMPLERATE_H
#undef HAVE_LIBDECOR_H
#undef HAVE_LSXINTRIN_H
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index 82abcbd..b668396 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -682,7 +682,7 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
#endif /* HAVE_DRIVER_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
/* libusb HIDAPI Implementation */
/* Include this now, for our dynamically-loaded libusb context */
@@ -817,6 +817,33 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
#undef HIDAPI_H__
#include "libusb/hid.c"
+#undef libusb_init
+#undef libusb_exit
+#undef libusb_get_device_list
+#undef libusb_free_device_list
+#undef libusb_get_device_descriptor
+#undef libusb_get_active_config_descriptor
+#undef libusb_get_config_descriptor
+#undef libusb_free_config_descriptor
+#undef libusb_get_bus_number
+#undef libusb_get_device_address
+#undef libusb_open
+#undef libusb_close
+#undef libusb_claim_interface
+#undef libusb_release_interface
+#undef libusb_kernel_driver_active
+#undef libusb_detach_kernel_driver
+#undef libusb_attach_kernel_driver
+#undef libusb_set_interface_alt_setting
+#undef libusb_alloc_transfer
+#undef libusb_submit_transfer
+#undef libusb_cancel_transfer
+#undef libusb_free_transfer
+#undef libusb_control_transfer
+#undef libusb_interrupt_transfer
+#undef libusb_handle_events
+#undef libusb_handle_events_completed
+
#undef hid_device
#undef hid_device_
#undef hid_init
@@ -844,7 +871,7 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
#undef make_path
#undef read_thread
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
#endif /* !SDL_HIDAPI_DISABLED */
@@ -899,7 +926,7 @@ static const struct hidapi_backend DRIVER_Backend = {
};
#endif /* HAVE_DRIVER_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
static const struct hidapi_backend LIBUSB_Backend = {
(void*)LIBUSB_hid_write,
(void*)LIBUSB_hid_read_timeout,
@@ -914,7 +941,7 @@ static const struct hidapi_backend LIBUSB_Backend = {
(void*)LIBUSB_hid_get_indexed_string,
(void*)LIBUSB_hid_error
};
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
struct SDL_hid_device_
{
@@ -924,7 +951,7 @@ struct SDL_hid_device_
};
static char device_magic;
-#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
+#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
static SDL_hid_device *
CreateHIDDeviceWrapper(void *device, const struct hidapi_backend *backend)
@@ -936,7 +963,7 @@ CreateHIDDeviceWrapper(void *device, const struct hidapi_backend *backend)
return wrapper;
}
-#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || HAVE_LIBUSB */
static void
DeleteHIDDeviceWrapper(SDL_hid_device *device)
@@ -952,7 +979,7 @@ DeleteHIDDeviceWrapper(SDL_hid_device *device)
}
#if !SDL_HIDAPI_DISABLED
-#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
+#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
#define COPY_IF_EXISTS(var) \
if (pSrc->var != NULL) { \
@@ -989,7 +1016,7 @@ CopyHIDDeviceInfo(struct SDL_hid_device_info *pSrc, struct SDL_hid_device_info *
#undef COPY_IF_EXISTS
#undef WCOPY_IF_EXISTS
-#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || HAVE_LIBUSB */
#endif /* !SDL_HIDAPI_DISABLED */
static int SDL_hidapi_refcount = 0;
@@ -1030,23 +1057,32 @@ int SDL_hid_init(void)
}
#endif
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (SDL_getenv("SDL_HIDAPI_DISABLE_LIBUSB") != NULL) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"libusb disabled by SDL_HIDAPI_DISABLE_LIBUSB");
libusb_ctx.libhandle = NULL;
} else {
++attempts;
+#ifdef SDL_LIBUSB_DYNAMIC
libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
+#else
+ libusb_ctx.libhandle = (void *)1;
+#endif
if (libusb_ctx.libhandle != NULL) {
SDL_bool loaded = SDL_TRUE;
#ifdef __OS2__
+#ifdef SDL_LIBUSB_DYNAMIC
#define LOAD_LIBUSB_SYMBOL(func) \
if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle,"_libusb_" #func))) {loaded = SDL_FALSE;}
#else
#define LOAD_LIBUSB_SYMBOL(func) \
if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
#endif
+#else
+ #define LOAD_LIBUSB_SYMBOL(func) \
+ libusb_ctx.func = libusb_##func;
+#endif
LOAD_LIBUSB_SYMBOL(init)
LOAD_LIBUSB_SYMBOL(exit)
LOAD_LIBUSB_SYMBOL(get_device_list)
@@ -1076,18 +1112,22 @@ int SDL_hid_init(void)
#undef LOAD_LIBUSB_SYMBOL
if (!loaded) {
+#ifdef SDL_LIBUSB_DYNAMIC
SDL_UnloadObject(libusb_ctx.libhandle);
+#endif
libusb_ctx.libhandle = NULL;
/* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
} else if (LIBUSB_hid_init() < 0) {
+#ifdef SDL_LIBUSB_DYNAMIC
SDL_UnloadObject(libusb_ctx.libhandle);
+#endif
libusb_ctx.libhandle = NULL;
} else {
++success;
}
}
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
#if HAVE_PLATFORM_BACKEND
++attempts;
@@ -1133,13 +1173,15 @@ int SDL_hid_exit(void)
#endif /* __LINUX __ */
#endif /* HAVE_PLATFORM_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle) {
result |= LIBUSB_hid_exit();
+#ifdef SDL_LIBUSB_DYNAMIC
SDL_UnloadObject(libusb_ctx.libhandle);
+#endif
libusb_ctx.libhandle = NULL;
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
return result;
}
@@ -1168,8 +1210,8 @@ Uint32 SDL_hid_device_change_count(void)
struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
-#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
-#ifdef SDL_LIBUSB_DYNAMIC
+#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
+#ifdef HAVE_LIBUSB
struct SDL_hid_device_info *usb_devs = NULL;
struct SDL_hid_device_info *usb_dev;
#endif
@@ -1187,7 +1229,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
return NULL;
}
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle) {
usb_devs = LIBUSB_hid_enumerate(vendor_id, product_id);
#ifdef DEBUG_HIDAPI
@@ -1216,7 +1258,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
last = new_dev;
}
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
#ifdef HAVE_DRIVER_BACKEND
driver_devs = DRIVER_hid_enumerate(vendor_id, product_id);
@@ -1246,7 +1288,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
raw_dev->manufacturer_string, raw_dev->product_string,
raw_dev->vendor_id, raw_dev->product_id);
#endif
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
if (raw_dev->vendor_id == usb_dev->vendor_id &&
raw_dev->product_id == usb_dev->product_id &&
@@ -1269,7 +1311,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
if (!bFound) {
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
if (!new_dev) {
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle) {
LIBUSB_hid_free_enumeration(usb_devs);
}
@@ -1294,7 +1336,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
}
#endif /* HAVE_PLATFORM_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle) {
LIBUSB_hid_free_enumeration(usb_devs);
}
@@ -1303,7 +1345,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
#else
return NULL;
-#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || HAVE_LIBUSB */
}
void SDL_hid_free_enumeration(struct SDL_hid_device_info *devs)
@@ -1321,7 +1363,7 @@ void SDL_hid_free_enumeration(struct SDL_hid_device_info *devs)
SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
{
-#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
+#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
void *pDevice = NULL;
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
@@ -1341,21 +1383,21 @@ SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id
}
#endif /* HAVE_DRIVER_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle &&
(pDevice = LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) {
return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
-#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || HAVE_LIBUSB */
return NULL;
}
SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */)
{
-#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
+#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
void *pDevice = NULL;
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
@@ -1375,14 +1417,14 @@ SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */
}
#endif /* HAVE_DRIVER_BACKEND */
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
if (libusb_ctx.libhandle &&
(pDevice = LIBUSB_hid_open_path(path, bExclusive)) != NULL) {
return CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
-#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || HAVE_LIBUSB */
return NULL;
}
@@ -1536,7 +1578,7 @@ void SDL_hid_ble_scan(SDL_bool active)
/* This is needed to enable input for Nyko and EVORETRO GameCube adaptors */
void SDL_EnableGameCubeAdaptors(void)
{
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
libusb_context *context = NULL;
libusb_device **devs = NULL;
libusb_device_handle *handle = NULL;
@@ -1585,7 +1627,7 @@ void SDL_EnableGameCubeAdaptors(void)
libusb_exit(context);
}
-#endif /* SDL_LIBUSB_DYNAMIC */
+#endif /* HAVE_LIBUSB */
}
#endif /* HAVE_ENABLE_GAMECUBE_ADAPTORS */
diff --git a/src/hidapi/SDL_hidapi_c.h b/src/hidapi/SDL_hidapi_c.h
index 1b40942..c7343b1 100644
--- a/src/hidapi/SDL_hidapi_c.h
+++ b/src/hidapi/SDL_hidapi_c.h
@@ -22,7 +22,7 @@
#ifdef SDL_JOYSTICK_HIDAPI
-#ifdef SDL_LIBUSB_DYNAMIC
+#ifdef HAVE_LIBUSB
#define HAVE_ENABLE_GAMECUBE_ADAPTORS
#endif