FindBoost.cmake doesn't use default installation path if EXACT in provided
Description
Given a call like
find_package(Boost 1.66.0 EXACT REQUIRED COMPONENTS filesystem)
The boost find cmake ignores the default installation location for boost on windows (meaning starting the boost installer and only clicking "next").
If EXACT
is not set the default installation path is correctly found.
Adding EXACT
means boost no longer finds the requested version.
The behaviour I would expect is for EXACT
not to fail to find the requested boost version in its default installation path.
Reason for this behaviour
(lines from file version at (45bf6f62)):
The block to test if an exact version should be found
finishes by setting _boost_TEST_VERSIONS
to the accepted versions based on the argument to find_package
.
If EXACT
isn't supplied it adds all versions equal and greater and if no version is supplied does set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}"
.
After this point _boost_TEST_VERSIONS
either is equal to _Boost_KNOWN_VERSIONS
, contains the wanted subset of _Boost_KNOWN_VERSIONS
or is equal to the exact requested version. Thus _Boost_KNOWN_VERSIONS
probably shouldn't be used because it is either
-
unset if
EXACT
was used - contains versions lower than the minimum version supplied to
find_package
.
Using the wrong variable
However, in https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindBoost.cmake#L1222 and https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindBoost.cmake#L1533 where the default installation paths are added _Boost_KNOWN_VERSIONS
is used:
foreach(ver ${_Boost_KNOWN_VERSIONS})
string(REPLACE "." "_" ver "${ver}")
list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS "C:/local/boost_${ver}")
endforeach()
[...]
foreach(ver ${_Boost_KNOWN_VERSIONS})
string(REPLACE "." "_" ver "${ver}")
_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "C:/local/boost_${ver}")
endforeach()
Proposed solutions:
_Boost_KNOWN_VERSIONS
with _Boost_TEST_VERSIONS
a. Replace these uses of This would however introduce a new behaviour: If the requested version is higher than all installed versions the older versions wouldn't be added to the search path (because _Boost_TEST_VERSIONS
is a subset of _Boost_KNOWN_VERSIONS
) and the user will no longer get the
Detected version of Boost is too old.
message.
C:/local
to the _boost_INCLUDE_SEARCH_DIRS
and also loop over _Boost_TEST_VERSIONS
here
or b. Add The code using _boost_INCLUDE_SEARCH_DIRS
already has provisions to add search paths from _Boost_TEST_VERSIONS
via find_path( PATH_SUFFIXES)
.
The code setting _boost_LIBRARY_SEARCH_DIRS
however, doesn't.