From 73d45c3e24d559c2a398739ed939a803cf1bb031 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 18 Oct 2026 18:06:33 -0400 Subject: [PATCH] PlutoSDR: find libiio 1.x headers and flag the 1.x API libiio 1.x installs its header as include/iio/iio.h instead of include/iio.h. Look for the 1.x layout first and fall back to the 0.x one, and set LIBIIO_V1 so plutosdrdevice can select the API at compile time. The bundled external build (v0.26) keeps the 0.x path. The input and output plugin headers only need the iio_buffer type, so forward-declare it instead of including iio.h. Co-Authored-By: Claude Opus 5.5 --- cmake/Modules/FindLibIIO.cmake | 28 ++++++++++++++++--- devices/plutosdr/CMakeLists.txt | 4 +++ .../plutosdroutput/plutosdroutput.h | 3 +- .../plutosdrinput/plutosdrinput.h | 3 +- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cmake/Modules/FindLibIIO.cmake b/cmake/Modules/FindLibIIO.cmake index 29bb5d8c9..b6afa651f 100644 --- a/cmake/Modules/FindLibIIO.cmake +++ b/cmake/Modules/FindLibIIO.cmake @@ -3,14 +3,30 @@ if(NOT LIBIIO_FOUND) pkg_check_modules (LIBIIO_PKG libiio>=0.7) if(LIBIIO_PKG_FOUND OR (DEFINED IIO_DIR)) - find_path(LIBIIO_INCLUDE_DIR - NAMES iio.h + # libiio 1.x installs its header as /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 /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") + endif() + find_library(LIBIIO_LIBRARIES NAMES iio HINTS ${IIO_DIR}/lib @@ -21,13 +37,17 @@ if(NOT LIBIIO_FOUND) if(LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARIES) set(LIBIIO_FOUND TRUE CACHE INTERNAL "libiio found") - message(STATUS "Found libiio: ${LIBIIO_INCLUDE_DIR}, ${LIBIIO_LIBRARIES}") + 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) set(LIBIIO_FOUND FALSE CACHE INTERNAL "libiio found") message(STATUS "libiio not found.") endif(LIBIIO_INCLUDE_DIR AND LIBIIO_LIBRARIES) - mark_as_advanced(LIBIIO_INCLUDE_DIR LIBIIO_LIBRARIES) + mark_as_advanced(LIBIIO_INCLUDE_DIR LIBIIO_V1_INCLUDE_DIR LIBIIO_LIBRARIES) endif(LIBIIO_PKG_FOUND OR (DEFINED IIO_DIR)) diff --git a/devices/plutosdr/CMakeLists.txt b/devices/plutosdr/CMakeLists.txt index db56a61d0..2a0e14ba6 100644 --- a/devices/plutosdr/CMakeLists.txt +++ b/devices/plutosdr/CMakeLists.txt @@ -35,6 +35,10 @@ target_link_libraries(plutosdrdevice ${ICONV_LIBRARY} ) +if(LIBIIO_V1) + target_compile_definitions(plutosdrdevice PRIVATE LIBIIO_V1) +endif() + if(LIBIIO_EXTERNAL) add_dependencies(plutosdrdevice libiio) endif() diff --git a/plugins/samplesink/plutosdroutput/plutosdroutput.h b/plugins/samplesink/plutosdroutput/plutosdroutput.h index aa94aecb8..717f7c3bf 100644 --- a/plugins/samplesink/plutosdroutput/plutosdroutput.h +++ b/plugins/samplesink/plutosdroutput/plutosdroutput.h @@ -25,13 +25,14 @@ #include #include -#include "iio.h" #include "dsp/devicesamplesink.h" #include "util/message.h" #include "plutosdr/deviceplutosdrshared.h" #include "plutosdr/deviceplutosdrbox.h" #include "plutosdroutputsettings.h" +struct iio_buffer; + class QNetworkAccessManager; class QNetworkReply; class DeviceAPI; diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.h b/plugins/samplesource/plutosdrinput/plutosdrinput.h index 099ce7396..387f8a50b 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.h +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.h @@ -26,13 +26,14 @@ #include #include -#include "iio.h" #include "dsp/devicesamplesource.h" #include "util/message.h" #include "plutosdr/deviceplutosdrshared.h" #include "plutosdr/deviceplutosdrbox.h" #include "plutosdrinputsettings.h" +struct iio_buffer; + class QNetworkAccessManager; class QNetworkReply; class DeviceAPI;