cmake: Restore finding installed resources in their real path

In commit 0994bc7929 (cmake: Preserve symlinks in references to itself
when possible, 2024-11-11) we stopped looking for resources using the
real path of the directory containing `cmake`.  Restore it as a fallback
to support layouts like `/{bin -> usr/bin}/cmake`.

Fixes: #26570
This commit is contained in:
Brad King
2025-01-09 15:56:40 -05:00
parent 52b31ff751
commit 6d9ab7964d

View File

@@ -2984,9 +2984,19 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
// Find resources relative to our own executable.
std::string exe_dir = cmSystemTools::GetFilenamePath(exe);
bool found = false;
// When running through a symlink to our own executable,
// preserve symlinks in directory components if possible.
do {
found = FindCMakeResourcesInInstallTree(exe_dir);
} while (!found && ResolveSymlinkToOwnExecutable(exe, exe_dir));
// If we have not yet found the resources, the above loop will
// have left 'exe' referring to a real file, not a symlink, so
// all our binaries should exist under 'exe_dir'. However, the
// resources may be discoverable only in the real path.
if (!found) {
found =
FindCMakeResourcesInInstallTree(cmSystemTools::GetRealPath(exe_dir));
}
if (!found) {
FindCMakeResourcesInBuildTree(exe_dir);
}