[CMake] Find_Boost sets Boost_INCLUDE_DIR before making sure the right version is found
Phil Osteen
prosteen at gmail.com
Tue May 10 14:58:29 EDT 2016
I'm not sure if this is a pattern of some sort or if it is unique to
Find_Boost, but using EXACT with find_package(Boost), as described here
<https://cmake.org/cmake/help/v3.0/module/FindBoost.html>, will fail to
find the correct boost version depending on the location of other boost
versions.
In FindBoost.cmake
<https://github.com/Kitware/CMake/blob/5fdd7d21f432e7a43a0cfa1a26da2d92217c7a60/Modules/FindBoost.cmake#L998>,
a list of potential boost search directories and path suffices are used to
look for boost/config.hpp.
Once _any_ directory that contains boost/config.hpp is found,
Boost_INCLUDE_DIR is set. After which,
${Boost_INCLUDE_DIR}/boost/version.hpp is used to extract the version. If
this version does not match the one passed to find_package, cmake declares
that it cannot find the specified version.
Since find_path <https://cmake.org/cmake/help/v3.0/command/find_path.html>
has a defined search process, if any other directory that happens to be
searched first contains boost/config.hpp, the process will fail, even if
the correct directory would have be subsequently found by find_path.
One approach to resolve this would be to check the version.hpp value after
a find_path call to make sure the correct version was found, and if not, to
re-run find_path with, for example NO_CMAKE_PATH, then if that doesn't
work, with NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH, and so on.
I wanted to run this by everybody before writing the patch, perhaps a
cleaner approach could be devised. Cheers
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160510/31b622a0/attachment.html>
More information about the CMake
mailing list