Browse Source

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
Brad King 11 months ago
parent
commit
6d9ab7964d
1 changed files with 10 additions and 0 deletions
  1. 10 0
      Source/cmSystemTools.cxx

+ 10 - 0
Source/cmSystemTools.cxx

@@ -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);
   }