Skip to content

Commit 51e6624

Browse files
jcelerierclaude
andcommitted
build: find Boost in installed header trees too
The shim only probed <root>/boost/version.hpp, so a BOOST_ROOT pointing at an installed tree (<root>/include/boost/version.hpp) was rejected even though the headers were there. Probe with find_path, which covers both layouts and the default search paths, and report through find_package_handle_standard_args so the requested version is honoured. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent fad912f commit 51e6624

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

cmake/FindBoost.cmake

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#
33
# Avendish only needs Boost headers (Boost::boost / Boost::headers). Strategy:
44
# 1. defer to Boost's own BoostConfig.cmake when it is installed;
5-
# 2. otherwise, satisfy the request from a plain header tree given via
6-
# BOOST_ROOT / Boost_INCLUDE_DIR.
5+
# 2. otherwise, satisfy the request from a plain header tree, accepting both
6+
# the source layout (<root>/boost/version.hpp) and the installed one
7+
# (<root>/include/boost/version.hpp), and falling back to the default
8+
# search paths.
79

810
# 1. Prefer config mode if available.
911
find_package(Boost ${Boost_FIND_VERSION} CONFIG QUIET)
@@ -13,22 +15,36 @@ endif()
1315

1416
# 2. Header-only fallback.
1517
if(NOT Boost_INCLUDE_DIR)
16-
if(BOOST_ROOT)
17-
set(Boost_INCLUDE_DIR "${BOOST_ROOT}")
18-
elseif(DEFINED ENV{BOOST_ROOT})
19-
set(Boost_INCLUDE_DIR "$ENV{BOOST_ROOT}")
20-
endif()
18+
set(_avnd_boost_hints "")
19+
foreach(_avnd_boost_root
20+
"${BOOST_ROOT}" "$ENV{BOOST_ROOT}"
21+
"${Boost_ROOT}" "$ENV{Boost_ROOT}"
22+
"${BOOSTROOT}" "$ENV{BOOSTROOT}")
23+
if(_avnd_boost_root)
24+
list(APPEND _avnd_boost_hints "${_avnd_boost_root}")
25+
endif()
26+
endforeach()
27+
28+
# PATH_SUFFIXES covers installed trees (<root>/include/boost/version.hpp);
29+
# the bare hint covers unpacked source trees (<root>/boost/version.hpp).
30+
find_path(Boost_INCLUDE_DIR
31+
NAMES boost/version.hpp
32+
HINTS ${_avnd_boost_hints}
33+
PATH_SUFFIXES include)
34+
unset(_avnd_boost_hints)
35+
unset(_avnd_boost_root)
2136
endif()
2237

2338
if(Boost_INCLUDE_DIR AND EXISTS "${Boost_INCLUDE_DIR}/boost/version.hpp")
24-
file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_ver_line
39+
file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _avnd_boost_ver_line
2540
REGEX "#define BOOST_LIB_VERSION ")
26-
string(REGEX MATCH "\"([0-9]+)_([0-9]+)\"" _ "${_boost_ver_line}")
41+
string(REGEX MATCH "\"([0-9]+)_([0-9]+)" _ "${_avnd_boost_ver_line}")
2742
set(Boost_VERSION_MAJOR "${CMAKE_MATCH_1}")
2843
set(Boost_VERSION_MINOR "${CMAKE_MATCH_2}")
44+
set(Boost_VERSION_PATCH 0)
2945
set(Boost_VERSION_STRING "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0")
3046
set(Boost_VERSION "${Boost_VERSION_STRING}")
31-
set(Boost_FOUND TRUE)
47+
unset(_avnd_boost_ver_line)
3248

3349
if(NOT TARGET Boost::boost)
3450
add_library(Boost::boost INTERFACE IMPORTED GLOBAL)
@@ -40,11 +56,12 @@ if(Boost_INCLUDE_DIR AND EXISTS "${Boost_INCLUDE_DIR}/boost/version.hpp")
4056
set_target_properties(Boost::headers PROPERTIES
4157
INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIR}")
4258
endif()
43-
else()
44-
set(Boost_FOUND FALSE)
45-
if(Boost_FIND_REQUIRED)
46-
message(FATAL_ERROR
47-
"FindBoost shim: Boost not found. Install Boost with CMake config "
48-
"files, or pass -DBOOST_ROOT=<path to a Boost header tree>.")
49-
endif()
5059
endif()
60+
61+
include(FindPackageHandleStandardArgs)
62+
find_package_handle_standard_args(Boost
63+
REQUIRED_VARS Boost_INCLUDE_DIR
64+
VERSION_VAR Boost_VERSION_STRING
65+
FAIL_MESSAGE
66+
"Boost headers not found. Install Boost with CMake config files, or pass \
67+
-DBOOST_ROOT=<path to a Boost tree>.")

0 commit comments

Comments
 (0)