cmake: omit Boost::system on Boost 1.89+ where the compiled stub is gone.

Keep linking Boost::log, and only require Boost::system on older package sets that still ship libboost_system.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-11 22:27:55 -04:00
co-authored by Cursor
parent 15ebf375ef
commit 3d23ed21be
2 changed files with 70 additions and 11 deletions
+11 -11
View File
@@ -66,13 +66,13 @@ configure_file(
@ONLY
)
# Find dependencies
# Tell CMake we're linking against the shared library (not header-only)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_HEADER_ONLY OFF)
find_package(Boost REQUIRED COMPONENTS system log)
# Define BOOST_ALL_DYN_LINK project-wide to ensure all Boost libraries use dynamic linking
add_compile_definitions(BOOST_ALL_DYN_LINK)
# Find dependencies (Boost.System optional on 1.89+; see BoostSharedDeps.cmake)
if(EXISTS ${CMAKE_SOURCE_DIR}/cmake/BoostSharedDeps.cmake
AND NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(${CMAKE_SOURCE_DIR}/cmake/BoostSharedDeps.cmake)
else()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/BoostSharedDeps.cmake)
endif()
find_package(Threads REQUIRED)
@@ -110,12 +110,12 @@ target_include_directories(spinscale PUBLIC
$<INSTALL_INTERFACE:include>
)
# Link against required dependencies for shared library
# Boost::system is PUBLIC because componentThread.h exposes Boost.Asio types
# Link against required dependencies for shared library.
# BOOST_SHARED_DEP_TARGETS is PUBLIC because componentThread.h exposes Boost.Asio
# types (and Boost::system when a compiled stub still exists).
target_link_libraries(spinscale PUBLIC
Threads::Threads
Boost::system
Boost::log
${BOOST_SHARED_DEP_TARGETS}
)
# Verify Boost dynamic dependencies after build
+59
View File
@@ -0,0 +1,59 @@
# EXPLANATION:
# Shared Boost deps for standalone or nested libspinscale builds.
# Always require Boost.Log as a shared library. Require Boost.System only on
# versions that still ship a compiled stub (Ubuntu dropped it at Boost 1.89).
#
# Sets BOOST_SHARED_DEP_TARGETS for target_link_libraries(... ${BOOST_SHARED_DEP_TARGETS}).
# Uses Boost:: imported targets (not a project INTERFACE lib) so export sets stay valid.
set(BOOST_COMPILED_SYSTEM_REMOVED_VERSION "1.89.0")
set(BOOST_SHARED_DEPS_MIN_VERSION "1.69")
function(boostSharedDepsComponentsForVersion _boostVersion _outVar)
set(_components log)
if(_boostVersion VERSION_LESS "${BOOST_COMPILED_SYSTEM_REMOVED_VERSION}")
list(APPEND _components system)
endif()
set(${_outVar} ${_components} PARENT_SCOPE)
endfunction()
function(boostSharedDepsLinkTargets _outVar)
set(_targets Boost::log)
if(TARGET Boost::system)
list(APPEND _targets Boost::system)
endif()
set(${_outVar} ${_targets} PARENT_SCOPE)
endfunction()
function(boostSharedDepsReportStatus)
if(TARGET Boost::system)
message(STATUS
"Boost ${Boost_VERSION}: linking Boost::system "
"(compiled stub still present)")
else()
message(STATUS
"Boost ${Boost_VERSION}: omitting Boost::system "
"(header-only; compiled stub removed at "
"${BOOST_COMPILED_SYSTEM_REMOVED_VERSION})")
endif()
endfunction()
if(NOT BOOST_SHARED_DEPS_RESOLVED)
# Prefer shared Boost libs where a compiled component still exists.
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_HEADER_ONLY OFF)
# Resolve version before requesting components so we can skip system on
# Boost 1.89+, where Ubuntu no longer packages libboost_system.
find_package(Boost ${BOOST_SHARED_DEPS_MIN_VERSION} REQUIRED)
boostSharedDepsComponentsForVersion("${Boost_VERSION}" _boostSharedDepsComponents)
find_package(Boost ${BOOST_SHARED_DEPS_MIN_VERSION} REQUIRED
COMPONENTS ${_boostSharedDepsComponents})
boostSharedDepsLinkTargets(BOOST_SHARED_DEP_TARGETS)
set(BOOST_SHARED_DEPS_RESOLVED TRUE)
boostSharedDepsReportStatus()
# Ensure remaining Boost libs (e.g. Log) use dynamic linking.
add_compile_definitions(BOOST_ALL_DYN_LINK)
endif()