diff options
author | Brad King <brad.king@kitware.com> | 2021-10-21 13:19:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-10-21 13:19:22 (GMT) |
commit | edd60a21885952c8cf224c534d12b745e6203ef6 (patch) | |
tree | fa07387be27b83b46cbe2d4b9223d4a2a8f67337 /Source | |
parent | 95e8d89a2995b1cfc04f8eabfdb6792d5c8c798e (diff) | |
parent | 91ec6eee58cdde3ad7994b5c7f96994427e65b68 (diff) | |
download | CMake-edd60a21885952c8cf224c534d12b745e6203ef6.zip CMake-edd60a21885952c8cf224c534d12b745e6203ef6.tar.gz CMake-edd60a21885952c8cf224c534d12b745e6203ef6.tar.bz2 |
Merge topic 'fix_reroot_paths'
91ec6eee58 find_package: Don't reroot prefix that is equal to a root path
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !6644
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFindCommon.cxx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index bdc9207..e896a87 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -240,14 +240,20 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths) std::vector<std::string> unrootedPaths = paths; paths.clear(); + auto isSameDirectoryOrSubDirectory = [](std::string const& l, + std::string const& r) { + return (cmSystemTools::GetRealPath(l) == cmSystemTools::GetRealPath(r)) || + cmSystemTools::IsSubDirectory(l, r); + }; + for (std::string const& r : roots) { for (std::string const& up : unrootedPaths) { // Place the unrooted path under the current root if it is not // already inside. Skip the unrooted path if it is relative to // a user home directory or is empty. std::string rootedDir; - if (cmSystemTools::IsSubDirectory(up, r) || - (stagePrefix && cmSystemTools::IsSubDirectory(up, *stagePrefix))) { + if (isSameDirectoryOrSubDirectory(up, r) || + (stagePrefix && isSameDirectoryOrSubDirectory(up, *stagePrefix))) { rootedDir = up; } else if (!up.empty() && up[0] != '~') { // Start with the new root. |