Bug in cmSystemTools::RelativeIfUnder
This returns incorrect relative subdirectory when top="/"
std::string cmSystemTools::RelativeIfUnder(std::string const& top,
std::string const& in)
{
std::string out;
if (in == top) {
out = ".";
} else if (cmSystemTools::IsSubDirectory(in, top)) {
out = in.substr(top.size() + 1);
} else {
out = in;
}
return out;
}
Example:
top="/";
in="/foo/bar";
// "/foo/bar" is a subdirectory of "/"
// this line will give wrong result:
out = in.substr(top.size() + 1);
expected: out="foo/bar"; // or "/foo/bar" ?
returns: out="oo/bar";
The issue was discovered based on the following output (notice removed first two letters '/u' of the path ):
CMake Error at tils/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR filesystem system
program_options iostreams thread coroutine date_time serialization)
(Required is at least version "1.73.0")
Call Stack (most recent call first):
tils/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
tils/share/cmake-3.23/Modules/FindBoost.cmake:2375 (find_package_handle_standard_args)
CMakeLists.txt:58 (find_package)
Edited by Brad King