Skip to content

Commit 9ca0bbb

Browse files
authored
Prefer system Boost when available (#202)
Benefits: - Avoids the > 100MB download when system Boost is available - Reduces NFS traffic and disk usage in shared environments Falls back quietly to FetchContent if system Boost is unavailable
1 parent 1f8b1e9 commit 9ca0bbb

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,21 @@ FetchContent_Declare(
3939
)
4040
FetchContent_MakeAvailable(nlohmann_json)
4141

42-
# Boost headers
43-
FetchContent_Declare(
44-
boost
45-
URL https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.gz
46-
URL_HASH SHA256=c0685b68dd44cc46574cce86c4e17c0f611b15e195be9848dfd0769a0a207628
47-
)
48-
FetchContent_MakeAvailable(boost)
49-
add_library(boost_headers INTERFACE)
50-
target_include_directories(boost_headers INTERFACE ${boost_SOURCE_DIR})
42+
# Boost headers - prefer system Boost when available
43+
find_package(Boost 1.83 QUIET)
44+
if(Boost_FOUND)
45+
add_library(boost_headers INTERFACE)
46+
target_link_libraries(boost_headers INTERFACE Boost::boost)
47+
else()
48+
FetchContent_Declare(
49+
boost
50+
URL https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.gz
51+
URL_HASH SHA256=c0685b68dd44cc46574cce86c4e17c0f611b15e195be9848dfd0769a0a207628
52+
)
53+
FetchContent_MakeAvailable(boost)
54+
add_library(boost_headers INTERFACE)
55+
target_include_directories(boost_headers INTERFACE ${boost_SOURCE_DIR})
56+
endif()
5157

5258
# pybind11
5359
FetchContent_Declare(

0 commit comments

Comments
 (0)