aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Markgraf <steve@steve-m.de>2014-01-24 03:57:53 +0100
committerSteve Markgraf <steve@steve-m.de>2014-01-24 03:57:53 +0100
commita2bc5b511765b29eb0ebabbc72fa6705fde7c6f7 (patch)
tree13cc04ac2e6c97011e99a4a2e407379f356c56a7
parent929972f8351622a584f0935f7c4de44f67919b80 (diff)
lib/cmake: check for libusb_handle_events_timeout_completed()
libusb < 1.0.9 doesn't have libusb_handle_events_timeout_completed(), but libusb <= 1.0.8 doesn't have version.h, so we need to check for the function. The cmake-code was borrowed from UHD, which also checks for libusb_error_name(), we add that as well since it might come handy later on. Signed-off-by: Steve Markgraf <steve@steve-m.de>
-rw-r--r--cmake/Modules/FindLibUSB.cmake18
-rw-r--r--src/librtlsdr.c8
2 files changed, 26 insertions, 0 deletions
diff --git a/cmake/Modules/FindLibUSB.cmake b/cmake/Modules/FindLibUSB.cmake
index 54d57a5..c2c3f63 100644
--- a/cmake/Modules/FindLibUSB.cmake
+++ b/cmake/Modules/FindLibUSB.cmake
@@ -24,6 +24,24 @@ endif()
/usr/local/lib
)
+include(CheckFunctionExists)
+if(LIBUSB_INCLUDE_DIRS)
+ set(CMAKE_REQUIRED_INCLUDES ${LIBUSB_INCLUDE_DIRS})
+endif()
+if(LIBUSB_LIBRARIES)
+ set(CMAKE_REQUIRED_LIBRARIES ${LIBUSB_LIBRARIES})
+endif()
+
+CHECK_FUNCTION_EXISTS("libusb_handle_events_timeout_completed" HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED)
+if(HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED)
+ add_definitions(-DHAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED=1)
+endif(HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED)
+
+CHECK_FUNCTION_EXISTS("libusb_error_name" HAVE_LIBUSB_ERROR_NAME)
+if(HAVE_LIBUSB_ERROR_NAME)
+ add_definitions(-DHAVE_LIBUSB_ERROR_NAME=1)
+endif(HAVE_LIBUSB_ERROR_NAME)
+
if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found")
message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}")
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index f8dbc13..527f007 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -1775,7 +1775,11 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
}
while (RTLSDR_INACTIVE != dev->async_status) {
+#ifdef HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED
r = libusb_handle_events_timeout_completed(dev->ctx, &tv, &dev->async_cancel);
+#else
+ r = libusb_handle_events_timeout(dev->ctx, &tv);
+#endif
if (r < 0) {
/*fprintf(stderr, "handle_events returned: %d\n", r);*/
if (r == LIBUSB_ERROR_INTERRUPTED) /* stray signal */
@@ -1807,7 +1811,11 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
/* handle any events that still need to
* be handled before exiting after we
* just cancelled all transfers */
+#ifdef HAVE_LIBUSB_HANDLE_EVENTS_TIMEOUT_COMPLETED
libusb_handle_events_timeout_completed(dev->ctx, &zerotv, NULL);
+#else
+ libusb_handle_events_timeout(dev->ctx, &zerotv);
+#endif
break;
}
}