From dd6690b6ca7b2cf735867a55a2e92ef1f0c01639 Mon Sep 17 00:00:00 2001 From: Heikki Hannikainen Date: Mon, 1 Jun 2015 10:29:19 +0300 Subject: [PATCH] hackrf: Add cmake magic to figure out if multiple devices support is available in libhackrf, so that backwards compatibility with old libhackrf is maintained. Signed-off-by: Heikki Hannikainen --- cmake/Modules/FindLibHackRF.cmake | 9 +++++++++ lib/hackrf/hackrf_sink_c.cc | 4 +++- lib/hackrf/hackrf_source_c.cc | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/FindLibHackRF.cmake b/cmake/Modules/FindLibHackRF.cmake index 73e97f3..260d6ba 100644 --- a/cmake/Modules/FindLibHackRF.cmake +++ b/cmake/Modules/FindLibHackRF.cmake @@ -22,3 +22,12 @@ FIND_LIBRARY( INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBHACKRF DEFAULT_MSG LIBHACKRF_LIBRARIES LIBHACKRF_INCLUDE_DIRS) MARK_AS_ADVANCED(LIBHACKRF_LIBRARIES LIBHACKRF_INCLUDE_DIRS) + +INCLUDE(CheckFunctionExists) +set(CMAKE_REQUIRED_LIBRARIES ${LIBHACKRF_LIBRARIES}) +CHECK_FUNCTION_EXISTS(hackrf_device_list LIBHACKRF_HAVE_DEVICE_LIST) + +if(LIBHACKRF_HAVE_DEVICE_LIST) + message(STATUS "HackRF multiple device support enabled") +endif(LIBHACKRF_HAVE_DEVICE_LIST) + diff --git a/lib/hackrf/hackrf_sink_c.cc b/lib/hackrf/hackrf_sink_c.cc index 2c8025b..7aa864d 100644 --- a/lib/hackrf/hackrf_sink_c.cc +++ b/lib/hackrf/hackrf_sink_c.cc @@ -193,9 +193,11 @@ hackrf_sink_c::hackrf_sink_c (const std::string &args) } _dev = NULL; +#ifdef LIBHACKRF_HAVE_DEVICE_LIST if ( hackrf_serial ) ret = hackrf_open_by_serial( hackrf_serial->c_str(), &_dev ); else +#endif ret = hackrf_open( &_dev ); HACKRF_THROW_ON_ERROR(ret, "Failed to open HackRF device") @@ -484,7 +486,7 @@ std::vector hackrf_sink_c::get_devices() _usage++; } -#if 1 +#ifdef LIBHACKRF_HAVE_DEVICE_LIST hackrf_device_list_t *list = hackrf_device_list(); for (unsigned int i = 0; i < list->devicecount; i++) { diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc index 64b8f14..13df11e 100644 --- a/lib/hackrf/hackrf_source_c.cc +++ b/lib/hackrf/hackrf_source_c.cc @@ -144,6 +144,7 @@ hackrf_source_c::hackrf_source_c (const std::string &args) _dev = NULL; +#ifdef LIBHACKRF_HAVE_DEVICE_LIST if (dict.count("hackrf") && dict["hackrf"].length() > 0) { hackrf_serial = dict["hackrf"]; @@ -169,6 +170,7 @@ hackrf_source_c::hackrf_source_c (const std::string &args) hackrf_device_list_free(list); } } else +#endif ret = hackrf_open( &_dev ); HACKRF_THROW_ON_ERROR(ret, "Failed to open HackRF device") @@ -399,7 +401,7 @@ std::vector hackrf_source_c::get_devices() _usage++; } -#if 1 +#if LIBHACKRF_HAVE_DEVICE_LIST hackrf_device_list_t *list = hackrf_device_list(); for (unsigned int i = 0; i < list->devicecount; i++) {