浏览代码

find_program: Fix regression in finding an already-known path

Changes in commit v3.4.0-rc1~124^2~1 (cmFindProgramCommand: Re-implement
search using more flexible approach, 2015-09-01) did not preserve the
behavior of looking for the given name with no search path at all.
Fix this and add a test case covering finding an absolute path with
no search directories.
Brad King 10 年之前
父节点
当前提交
31e6571cca

+ 13 - 0
Source/cmFindProgramCommand.cxx

@@ -176,6 +176,13 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir()
     {
     {
     helper.AddName(*ni);
     helper.AddName(*ni);
     }
     }
+
+  // Check for the names themselves (e.g. absolute paths).
+  if (helper.CheckDirectory(std::string()))
+    {
+    return helper.BestPath;
+    }
+
   // Search every directory.
   // Search every directory.
   for (std::vector<std::string>::const_iterator
   for (std::vector<std::string>::const_iterator
          p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p)
          p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p)
@@ -200,6 +207,12 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName()
     // Switch to searching for this name.
     // Switch to searching for this name.
     helper.SetName(*ni);
     helper.SetName(*ni);
 
 
+    // Check for the name by itself (e.g. an absolute path).
+    if (helper.CheckDirectory(std::string()))
+      {
+      return helper.BestPath;
+      }
+
     // Search every directory.
     // Search every directory.
     for (std::vector<std::string>::const_iterator
     for (std::vector<std::string>::const_iterator
            p = this->SearchPaths.begin();
            p = this->SearchPaths.begin();

+ 1 - 0
Tests/RunCMake/find_program/DirsPerName-stdout.txt

@@ -1 +1,2 @@
 -- PROG='[^']*/Tests/RunCMake/find_program/B/testB'
 -- PROG='[^']*/Tests/RunCMake/find_program/B/testB'
+-- PROG_ABS='[^']*/Tests/RunCMake/find_program/A/testA'

+ 6 - 0
Tests/RunCMake/find_program/DirsPerName.cmake

@@ -4,3 +4,9 @@ find_program(PROG
   NO_DEFAULT_PATH
   NO_DEFAULT_PATH
   )
   )
 message(STATUS "PROG='${PROG}'")
 message(STATUS "PROG='${PROG}'")
+
+find_program(PROG_ABS
+  NAMES ${CMAKE_CURRENT_SOURCE_DIR}/A/testA
+  NO_DEFAULT_PATH
+  )
+message(STATUS "PROG_ABS='${PROG_ABS}'")

+ 1 - 0
Tests/RunCMake/find_program/NamesPerDir-stdout.txt

@@ -1 +1,2 @@
 -- PROG='[^']*/Tests/RunCMake/find_program/A/testA'
 -- PROG='[^']*/Tests/RunCMake/find_program/A/testA'
+-- PROG_ABS='[^']*/Tests/RunCMake/find_program/A/testA'

+ 6 - 0
Tests/RunCMake/find_program/NamesPerDir.cmake

@@ -4,3 +4,9 @@ find_program(PROG
   NO_DEFAULT_PATH
   NO_DEFAULT_PATH
   )
   )
 message(STATUS "PROG='${PROG}'")
 message(STATUS "PROG='${PROG}'")
+
+find_program(PROG_ABS
+  NAMES ${CMAKE_CURRENT_SOURCE_DIR}/A/testA NAMES_PER_DIR
+  NO_DEFAULT_PATH
+  )
+message(STATUS "PROG_ABS='${PROG_ABS}'")