We can achieve this with multiple `find_package` calls. I tested the following (suggested by a LLM), and it worked for me:
commit 20319236a4b8cb4d2caedaea8f79d7c3d55cc91b Author: Doron Behar doron.behar@gmail.com Date: Tue Mar 3 21:34:38 2026 +0200
cmake: require boost's system component conditionally on versiondiff --git a/CMakeLists.txt b/CMakeLists.txt index 3a6b0da..98838df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,12 +119,22 @@ endif() ######################################################################## # Find boost ######################################################################## -find_package(Boost "1.65" REQUIRED chrono thread system)
+# First, probe Boost to discover its version (no components required yet) +find_package(Boost "1.65" REQUIRED)
if(NOT Boost_FOUND) message(FATAL_ERROR "Boost required to compile osmosdr") endif()
+# system is a compiled library before 1.69; header-only from 1.69 onward +set(BOOST_COMPONENTS chrono thread) +if(Boost_VERSION VERSION_LESS "1.69")
- list(APPEND BOOST_COMPONENTS system)
+endif()
+find_package(Boost "1.65" REQUIRED ${BOOST_COMPONENTS})
######################################################################## # Find build dependencies and setup options ########################################################################
Best, Doron.
On Fri, Mar 27, 2026 at 03:39:48PM +0100, Sylvain Munaut wrote:
But we don't really depend on 1.69 ...
Ideally we'd still work with 1.65 and if you happen to have 1.69 or above, then it wouldn't request the system component.
No clue how to do that though.
On Tue, Mar 3, 2026 at 9:48 PM doron.behar@gmail.com wrote:
From: Doron Behar doron.behar@gmail.com
boost_system is a header only library in Boost 1.69, so the version constraint is bumped too.
CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a6b0da..eefd442 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ endif() ######################################################################## # Find boost ######################################################################## -find_package(Boost "1.65" REQUIRED chrono thread system) +find_package(Boost "1.69" REQUIRED chrono thread)
if(NOT Boost_FOUND) message(FATAL_ERROR "Boost required to compile osmosdr") -- 2.28.0