diff --git a/AGENTS.md b/AGENTS.md index 7f1648f..1fe549b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -100,7 +100,7 @@ cppcourse/ - `Materials/`: supplementary course material PDFs. - Each exercise directory holds a `CMakeLists.txt` that defines its target via `cmat_add_exercise()` (see `cmat/CMakeLists.txt`). Exercises that need a - missing dependency (e.g. Boost) are reported as not available at configure + missing dependency (e.g. curses) are reported as not available at configure time and skipped. ## Behavioral Guidelines diff --git a/cmat/CMakeLists.txt b/cmat/CMakeLists.txt index bc6e94f..76f5537 100644 --- a/cmat/CMakeLists.txt +++ b/cmat/CMakeLists.txt @@ -56,10 +56,8 @@ else() # Windows-specific; there is nothing portable to build with. endif() -# Exercises using Boost.Serialization (system install; not fetched). CONFIG -# mode uses Boost's own CMake package, since the FindBoost module was removed -# in CMake 4. -find_package(Boost CONFIG QUIET COMPONENTS serialization) +# Exercises using Boost.Serialization (fetched via deps/FindBoost.cmake). +find_package(Boost QUIET COMPONENTS serialization) # ------------------------------------------------------------------------------ # Target helpers diff --git a/cmat/SolutionEx62Bonus/Employee.h b/cmat/SolutionEx62Bonus/Employee.h index f39c0a0..985d225 100644 --- a/cmat/SolutionEx62Bonus/Employee.h +++ b/cmat/SolutionEx62Bonus/Employee.h @@ -2,6 +2,8 @@ #define EMPLYOEE_H #include "Person.h" +#include + class Employee : public Person { public: void askForInfo(); diff --git a/deps/FindBoost.cmake b/deps/FindBoost.cmake new file mode 100644 index 0000000..a4afe42 --- /dev/null +++ b/deps/FindBoost.cmake @@ -0,0 +1,89 @@ +# ============================================================================== +# 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:: - 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__FOUND - TRUE if the component is available +# Boost_LIBRARIES - The component targets (Boost::...) +# 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 +)