Fetch the Boost CMake release archive (default 1.92.0) and build only the libraries requested via find_package(Boost COMPONENTS ...), plus their dependencies. Each component is exposed as Boost::<name>, e.g. Boost::serialization. cmat now uses this module instead of a system Boost install, so the Boost exercises are always available. Also fix SolutionEx62Bonus: Employee.h used base_object without including <boost/serialization/base_object.hpp>. This was not an intentional exercise bug; it likely relied on a transitive include in older Boost versions. Co-authored-by: Claude Opus 5.5 <claude.opus5.5@anthropic.com>
90 lines
3.4 KiB
CMake
90 lines
3.4 KiB
CMake
# ==============================================================================
|
|
# Find Boost
|
|
# ==============================================================================
|
|
# This module fetches the Boost libraries (CMake release archive) and builds
|
|
# only the requested components and their dependencies.
|
|
#
|
|
# Usage:
|
|
# find_package(Boost REQUIRED COMPONENTS serialization program_options)
|
|
# target_link_libraries(app PRIVATE Boost::serialization Boost::program_options)
|
|
#
|
|
# Components are Boost library names as they appear under libs/ (lowercase),
|
|
# e.g. serialization, filesystem, json, asio. Header-only libraries work too.
|
|
# Without components every Boost library is configured (slower configure);
|
|
# targets are only built when linked.
|
|
#
|
|
# All components must be requested in the first find_package(Boost) call:
|
|
# Boost is configured once, later calls can only use what was configured.
|
|
#
|
|
# Targets provided:
|
|
# Boost::<component> - One target per requested component
|
|
# Boost::headers - All configured header-only libraries
|
|
#
|
|
# Variables set:
|
|
# Boost_FOUND - TRUE if Boost and all required components are available
|
|
# Boost_<component>_FOUND - TRUE if the component is available
|
|
# Boost_LIBRARIES - The component targets (Boost::<component>...)
|
|
# Boost_VERSION - Version of Boost
|
|
# ==============================================================================
|
|
|
|
# Use the version passed to find_package(), or default to 1.92.0
|
|
# The version must be the full x.y.z form used by the release archive names
|
|
if (DEFINED Boost_FIND_VERSION AND NOT Boost_FIND_VERSION STREQUAL "")
|
|
set(BOOST_VERSION "${Boost_FIND_VERSION}")
|
|
else()
|
|
set(BOOST_VERSION "1.92.0")
|
|
endif()
|
|
|
|
if (NOT DEFINED _FINDBOOST_INCLUDED)
|
|
set(_FINDBOOST_INCLUDED TRUE)
|
|
|
|
message(STATUS "Fetching Boost ${BOOST_VERSION} (components: ${Boost_FIND_COMPONENTS})")
|
|
|
|
include(FetchContent)
|
|
|
|
# Mark Boost includes as SYSTEM to suppress warnings from its headers
|
|
set(_boost_fetch_options "")
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25)
|
|
list(APPEND _boost_fetch_options SYSTEM)
|
|
endif()
|
|
|
|
FetchContent_Declare(
|
|
boost
|
|
URL https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-cmake.tar.xz
|
|
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
|
EXCLUDE_FROM_ALL
|
|
${_boost_fetch_options}
|
|
)
|
|
|
|
# Read by the Boost superproject: build only these libraries (and their
|
|
# dependencies). Empty means all libraries.
|
|
set(BOOST_INCLUDE_LIBRARIES ${Boost_FIND_COMPONENTS})
|
|
FetchContent_MakeAvailable(boost)
|
|
unset(BOOST_INCLUDE_LIBRARIES)
|
|
|
|
set(BOOST_LICENSE_FILE "${boost_SOURCE_DIR}/LICENSE_1_0.txt" CACHE FILEPATH "Path to Boost license file")
|
|
endif()
|
|
|
|
set(Boost_LIBRARIES "")
|
|
foreach (_boost_comp IN LISTS Boost_FIND_COMPONENTS)
|
|
if (TARGET Boost::${_boost_comp})
|
|
set(Boost_${_boost_comp}_FOUND TRUE)
|
|
list(APPEND Boost_LIBRARIES Boost::${_boost_comp})
|
|
else()
|
|
set(Boost_${_boost_comp}_FOUND FALSE)
|
|
if (NOT Boost_FIND_QUIETLY)
|
|
message(STATUS "Boost component '${_boost_comp}' is not available: "
|
|
"unknown library, or not requested in the first find_package(Boost) call")
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
|
|
set(Boost_VERSION "${BOOST_VERSION}")
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
find_package_handle_standard_args(Boost
|
|
REQUIRED_VARS boost_SOURCE_DIR
|
|
VERSION_VAR Boost_VERSION
|
|
HANDLE_COMPONENTS
|
|
)
|