build: fix libusb-1.0 config

This commit is contained in:
Christian W. Zuckschwerdt 2021-02-01 12:50:53 +01:00
parent 10bd7dc107
commit 9514e167d0
4 changed files with 28 additions and 4 deletions

View file

@ -124,11 +124,21 @@ if(ENABLE_RTLSDR) # AUTO / ON
find_package(PkgConfig)
find_package(LibRTLSDR)
find_package(LibUSB)
if(LIBRTLSDR_FOUND AND LIBUSB_FOUND)
if(LIBRTLSDR_FOUND)
message(STATUS "RTL-SDR device input will be compiled.")
include_directories(${LIBRTLSDR_INCLUDE_DIRS} ${LIBUSB_INCLUDE_DIRS})
list(APPEND SDR_LIBRARIES ${LIBRTLSDR_LIBRARIES} ${LIBUSB_LIBRARIES})
include_directories(${LIBRTLSDR_INCLUDE_DIRS})
list(APPEND SDR_LIBRARIES ${LIBRTLSDR_LIBRARIES})
ADD_DEFINITIONS(-DRTLSDR)
if(LIBUSB_FOUND)
message(STATUS "libusb-1.0 error messages are available.")
include_directories(${LIBUSB_INCLUDE_DIRS})
list(APPEND SDR_LIBRARIES ${LIBUSB_LIBRARIES})
ADD_DEFINITIONS(-DLIBUSB1)
else()
message(STATUS "libusb-1.0 error messages are not available.")
endif()
elseif(ENABLE_RTLSDR STREQUAL "AUTO")
message(STATUS "RTL-SDR development files not found, RTL-SDR device input won't be possible.")
else()

View file

@ -1,4 +1,4 @@
# - Try to find LibUSB
# - Try to find LibUSB-1.0
# Once done this will define
# LIBUSB_FOUND - System has LibUSB
# LIBUSB_INCLUDE_DIRS - The LibUSB include directories

View file

@ -23,6 +23,12 @@ AM_COND_IF([USE_LIBRTLSDR],
[ LIBS="$LIBS $LIBRTLSDR_LIBS"
CFLAGS="$CFLAGS $LIBRTLSDR_CFLAGS -DRTLSDR" ])
PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [HAVE_LIBUSB1=1], [HAVE_LIBUSB1=0])
AM_CONDITIONAL([USE_LIBUSB1], [test "$HAVE_LIBUSB1" -eq 1])
AM_COND_IF([USE_LIBUSB1],
[ LIBS="$LIBS $LIBUSB1_LIBS"
CFLAGS="$CFLAGS $LIBUSB1_CFLAGS -DLIBUSB1" ])
PKG_CHECK_MODULES([SOAPYSDR], [SoapySDR], [HAVE_SOAPYSDR=1], [HAVE_SOAPYSDR=0])
AM_CONDITIONAL([USE_SOAPYSDR], [test "$HAVE_SOAPYSDR" -eq 1])
AM_COND_IF([USE_SOAPYSDR],

View file

@ -22,8 +22,10 @@
#include "fatal.h"
#ifdef RTLSDR
#include <rtl-sdr.h>
#ifdef LIBUSB1
#include <libusb.h> /* libusb_error_name(), libusb_strerror() */
#endif
#endif
#ifdef SOAPYSDR
#include <SoapySDR/Version.h>
#include <SoapySDR/Device.h>
@ -508,9 +510,15 @@ static int rtlsdr_read_loop(sdr_dev_t *dev, sdr_event_cb_t cb, void *ctx, uint32
// r = libusb_cancel_transfer(dev->xfer[i]);
// We can safely assume it's an libusb error.
if (r < 0) {
#ifdef LIBUSB1
fprintf(stderr, "\n%s: %s!\n"
"Check your RTL-SDR dongle, USB cables, and power supply.\n\n",
libusb_error_name(r), libusb_strerror(r));
#else
fprintf(stderr, "\nLIBUSB_ERROR: %d\n"
"Check your RTL-SDR dongle, USB cables, and power supply.\n\n",
r);
#endif
dev->running = 0;
}
dev->polling = 0;