From 8084b26979a363f19649c66668840a0c45e62ae5 Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Thu, 27 Jun 2024 20:40:18 +0300 Subject: [PATCH] fix: Boost is now properly found using find_package (#50) --- cmake/Boost_DD.cmake | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmake/Boost_DD.cmake b/cmake/Boost_DD.cmake index 6f60cd0..391cd30 100644 --- a/cmake/Boost_DD.cmake +++ b/cmake/Boost_DD.cmake @@ -4,25 +4,33 @@ # include_guard(GLOBAL) +# Limit boost to the required libraries only +set(REQUIRED_HEADER_LIBRARIES + algorithm + scope + preprocessor + uuid +) + find_package(Boost 1.85 QUIET GLOBAL) if(NOT Boost_FOUND) message(STATUS "Boost v1.85.x package not found in the system. Falling back to FetchContent.") include(FetchContent) - # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: - if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") - cmake_policy(SET CMP0135 NEW) - endif() - - # Limit boost to the required libraries only - set(BOOST_INCLUDE_LIBRARIES - algorithm - scope - uuid) + set(BOOST_INCLUDE_LIBRARIES ${REQUIRED_HEADER_LIBRARIES}) FetchContent_Declare( Boost URL https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.xz URL_HASH MD5=BADEA970931766604D4D5F8F4090B176 + DOWNLOAD_EXTRACT_TIMESTAMP ) FetchContent_MakeAvailable(Boost) +else() + # For whatever reason the Boost::headers from find_package is not the same as the one from FetchContent + # (differ in linked targets). + # Also, FetchContent creates Boost:: targets, whereas find_package does not. Since we cannot extend + # Boost::headers as it is an ALIAS target, this is the workaround: + foreach (lib ${REQUIRED_HEADER_LIBRARIES}) + add_library(Boost::${lib} ALIAS Boost::headers) + endforeach () endif()