Browse Source

PlutoSDR: make libiio 1.x opt-in and take header and library from one install

libiio 1.0 is new and not yet packaged by distributions, so keep the
0.x API as the default and add ENABLE_LIBIIO_V1 (default OFF) to build
against 1.x explicitly.

The finder used to look for the 1.x header in IIO_DIR and in the system
paths before falling back to 0.x, independently of where it found the
library. With 1.x installed system-wide and IIO_DIR pointing at 0.26,
it combined 1.x headers with the 0.26 library and the link failed. Now
each candidate install (IIO_DIR, then the one pkg-config reports, then
the system paths) must provide both the header and the library for the
requested API; an install with the other API is skipped with a message.
Changing ENABLE_LIBIIO_V1 triggers detection again in an existing build
directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chirpmodem-v8.0.0
Marcel 1 month ago
parent
commit
0819619a2d
  1. 1
      CMakeLists.txt
  2. 117
      cmake/Modules/FindLibIIO.cmake

1
CMakeLists.txt

@ -120,6 +120,7 @@ option(ENABLE_BLADERF "Enable bladeRF support" ON) @@ -120,6 +120,7 @@ option(ENABLE_BLADERF "Enable bladeRF support" ON)
option(ENABLE_FUNCUBE "Enable FUNcube support" ON)
option(ENABLE_HACKRF "Enable HackRF support" ON)
option(ENABLE_IIO "Enable liniio support like PlutoSDR" ON)
option(ENABLE_LIBIIO_V1 "Build PlutoSDR support against the libiio 1.x API (default: 0.x)" OFF)
option(ENABLE_LIMESUITE "Enable limesuite support" ON)
option(ENABLE_METIS "Enable Metis support" ON)
option(ENABLE_MIRISDR "Enable LibMiri for old SDRPlay" ON)

117
cmake/Modules/FindLibIIO.cmake

@ -1,53 +1,104 @@ @@ -1,53 +1,104 @@
# Finds libiio for PlutoSDR support.
#
# The libiio 0.x API is used by default. Set ENABLE_LIBIIO_V1=ON to build
# against libiio 1.x instead. The header and the library always come from the
# same install: IIO_DIR if set, else the one pkg-config reports, else the
# system paths. An install with the other API is skipped.
#
# Sets LIBIIO_FOUND, LIBIIO_INCLUDE_DIR, LIBIIO_LIBRARIES and LIBIIO_V1.
if(ENABLE_LIBIIO_V1)
set(_LIBIIO_WANT_V1 TRUE)
else()
set(_LIBIIO_WANT_V1 FALSE)
endif()
# Detect again when ENABLE_LIBIIO_V1 changes in an existing build directory
if(LIBIIO_FOUND AND NOT LIBIIO_EXTERNAL AND NOT (LIBIIO_V1 STREQUAL _LIBIIO_WANT_V1))
unset(LIBIIO_FOUND CACHE)
unset(LIBIIO_INCLUDE_DIR CACHE)
unset(LIBIIO_LIBRARIES CACHE)
endif()
# Checks one install for the requested API: header and library must both be found there.
# Sets _LIBIIO_INSTALL_FOUND in the caller's scope.
function(libiio_check_install label include_dirs lib_dirs)
unset(_LIBIIO_INC_V1 CACHE)
unset(_LIBIIO_INC_V0 CACHE)
unset(_LIBIIO_LIB CACHE)
find_path(_LIBIIO_INC_V1 NAMES iio/iio.h PATHS ${include_dirs} NO_DEFAULT_PATH)
find_path(_LIBIIO_INC_V0 NAMES iio.h PATHS ${include_dirs} NO_DEFAULT_PATH)
find_library(_LIBIIO_LIB NAMES iio PATHS ${lib_dirs}
PATH_SUFFIXES ${CMAKE_LIBRARY_ARCHITECTURE} NO_DEFAULT_PATH)
if(_LIBIIO_WANT_V1)
set(include_dir ${_LIBIIO_INC_V1})
set(other_include_dir ${_LIBIIO_INC_V0})
set(other_api "0.x")
set(option_state "ON")
else()
set(include_dir ${_LIBIIO_INC_V0})
set(other_include_dir ${_LIBIIO_INC_V1})
set(other_api "1.x")
set(option_state "OFF")
endif()
set(found FALSE)
if(include_dir AND _LIBIIO_LIB)
set(LIBIIO_INCLUDE_DIR ${include_dir} CACHE PATH "libiio include directory" FORCE)
set(LIBIIO_LIBRARIES ${_LIBIIO_LIB} CACHE FILEPATH "libiio library" FORCE)
set(found TRUE)
elseif(other_include_dir AND _LIBIIO_LIB)
message(STATUS "Ignoring libiio ${other_api} in ${label}: ENABLE_LIBIIO_V1 is ${option_state}")
endif()
unset(_LIBIIO_INC_V1 CACHE)
unset(_LIBIIO_INC_V0 CACHE)
unset(_LIBIIO_LIB CACHE)
set(_LIBIIO_INSTALL_FOUND ${found} PARENT_SCOPE)
endfunction()
if(NOT LIBIIO_FOUND)
pkg_check_modules (LIBIIO_PKG libiio>=0.7)
set(LIBIIO_V1 FALSE CACHE INTERNAL "libiio 1.x API")
if(LIBIIO_PKG_FOUND OR (DEFINED IIO_DIR))
# libiio 1.x installs its header as <prefix>/include/iio/iio.h
find_path(LIBIIO_V1_INCLUDE_DIR
NAMES iio/iio.h
HINTS ${IIO_DIR}/include
${LIBIIO_PKG_INCLUDE_DIRS}
PATHS /usr/include
/usr/local/include
)
if(LIBIIO_V1_INCLUDE_DIR)
set(LIBIIO_INCLUDE_DIR ${LIBIIO_V1_INCLUDE_DIR} CACHE PATH "libiio include directory")
set(LIBIIO_V1 TRUE CACHE INTERNAL "libiio 1.x API")
else()
# libiio 0.x installs its header as <prefix>/include/iio.h
find_path(LIBIIO_INCLUDE_DIR
NAMES iio.h
HINTS ${IIO_DIR}/include
${LIBIIO_PKG_INCLUDE_DIRS}
PATHS /usr/include
/usr/local/include
)
set(LIBIIO_V1 FALSE CACHE INTERNAL "libiio 1.x API")
set(_LIBIIO_INSTALL_FOUND FALSE)
if(DEFINED IIO_DIR)
libiio_check_install("IIO_DIR (${IIO_DIR})"
"${IIO_DIR}/include"
"${IIO_DIR}/lib;${IIO_DIR}/lib64")
endif()
find_library(LIBIIO_LIBRARIES
NAMES iio
HINTS ${IIO_DIR}/lib
${LIBIIO_PKG_LIBRARY_DIRS}
PATHS /usr/lib
/usr/local/lib
)
if(NOT _LIBIIO_INSTALL_FOUND AND LIBIIO_PKG_FOUND)
libiio_check_install("pkg-config (libiio ${LIBIIO_PKG_VERSION})"
"${LIBIIO_PKG_INCLUDEDIR};${LIBIIO_PKG_INCLUDE_DIRS}"
"${LIBIIO_PKG_LIBDIR};${LIBIIO_PKG_LIBRARY_DIRS}")
endif()
if(NOT _LIBIIO_INSTALL_FOUND)
libiio_check_install("system paths"
"/usr/include;/usr/local/include"
"/usr/lib;/usr/local/lib")
endif()
if(LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARIES)
if(_LIBIIO_INSTALL_FOUND)
set(LIBIIO_FOUND TRUE CACHE INTERNAL "libiio found")
set(LIBIIO_V1 ${_LIBIIO_WANT_V1} CACHE INTERNAL "libiio 1.x API")
if(LIBIIO_V1)
message(STATUS "Found libiio (1.x API): ${LIBIIO_INCLUDE_DIR}, ${LIBIIO_LIBRARIES}")
else()
message(STATUS "Found libiio (0.x API): ${LIBIIO_INCLUDE_DIR}, ${LIBIIO_LIBRARIES}")
endif()
else(LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARIES)
else()
set(LIBIIO_FOUND FALSE CACHE INTERNAL "libiio found")
message(STATUS "libiio not found.")
endif(LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARIES)
endif()
mark_as_advanced(LIBIIO_INCLUDE_DIR LIBIIO_V1_INCLUDE_DIR LIBIIO_LIBRARIES)
mark_as_advanced(LIBIIO_INCLUDE_DIR LIBIIO_LIBRARIES)
endif(LIBIIO_PKG_FOUND OR (DEFINED IIO_DIR))

Loading…
Cancel
Save