Browse Source

cmSystemTools: Restore FindProgram look-up of on-disk case on Windows

KWSys's `FindProgram` no longer looks up the actual case on disk.  This
behavior change was inherited from the change to `CollapseFullPath`.
Extend commit 773b75e4ed (cmake: Explicitly look up on-disk case of
input paths on Windows, 2024-10-23, v4.0.0-rc1~589^2) to cover this by
wrapping `FindProgram` in a CMake-specific layer.

Issue: #20214
Brad King 8 months ago
parent
commit
db0e2574cb
2 changed files with 18 additions and 0 deletions
  1. 10 0
      Source/cmSystemTools.cxx
  2. 8 0
      Source/cmSystemTools.h

+ 10 - 0
Source/cmSystemTools.cxx

@@ -2992,6 +2992,16 @@ unsigned int cmSystemTools::RandomNumber()
   return static_cast<unsigned int>(gen());
 }
 
+std::string cmSystemTools::FindProgram(std::string const& name,
+                                       std::vector<std::string> const& path)
+{
+  std::string exe = cmsys::SystemTools::FindProgram(name, path);
+  if (!exe.empty()) {
+    exe = cmSystemTools::ToNormalizedPathOnDisk(std::move(exe));
+  }
+  return exe;
+}
+
 namespace {
 std::string InitLogicalWorkingDirectory()
 {

+ 8 - 0
Source/cmSystemTools.h

@@ -560,6 +560,14 @@ public:
   static unsigned int RandomSeed();
   static unsigned int RandomNumber();
 
+  /**
+   * Find an executable in the system PATH, with optional extra paths.
+   * This wraps KWSys's FindProgram to add ToNormalizedPathOnDisk.
+   */
+  static std::string FindProgram(
+    std::string const& name,
+    std::vector<std::string> const& path = std::vector<std::string>());
+
   /** Find the directory containing CMake executables.  */
   static void FindCMakeResources(char const* argv0);