浏览代码

find_package: Don't test <name>_DIR against ignored paths

Tweak `find_package` to not compare an already-specified `<name>_DIR`
against the set of ignored paths. This is a minor behavior change in
that, if a previously found package is in a location that is NEWLY
ignored (i.e. because the user modified the ignored paths since the
previous run of CMake), we won't throw out the old result. However, it
also means that a user specifying `<name>_DIR` takes precedence over the
set of ignored paths, which seems like the desired behavior.

Note that the current behavior was introduced in commit 11f97d1968
(find_package: Refactor CMAKE_[SYSTEM_]IGNORE_PATH, 2022-01-28,
v3.23.0-rc1~31^2) and appears to have been unintentional.
Matthew Woehlke 11 月之前
父节点
当前提交
230e5ec172
共有 1 个文件被更改,包括 6 次插入5 次删除
  1. 6 5
      Source/cmFindPackageCommand.cxx

+ 6 - 5
Source/cmFindPackageCommand.cxx

@@ -12,6 +12,7 @@
 #include <utility>
 #include <utility>
 
 
 #include <cm/optional>
 #include <cm/optional>
+#include <cmext/algorithm>
 #include <cmext/string_view>
 #include <cmext/string_view>
 
 
 #include "cmsys/Directory.hxx"
 #include "cmsys/Directory.hxx"
@@ -2422,8 +2423,12 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
 {
 {
   assert(!dir.empty() && dir.back() == '/');
   assert(!dir.empty() && dir.back() == '/');
 
 
-  // Look for the file in this directory.
   std::string const d = dir.substr(0, dir.size() - 1);
   std::string const d = dir.substr(0, dir.size() - 1);
+  if (cm::contains(this->IgnoredPaths, d)) {
+    return false;
+  }
+
+  // Look for the file in this directory.
   if (this->FindConfigFile(d, this->FileFound)) {
   if (this->FindConfigFile(d, this->FileFound)) {
     // Remove duplicate slashes.
     // Remove duplicate slashes.
     cmSystemTools::ConvertToUnixSlashes(this->FileFound);
     cmSystemTools::ConvertToUnixSlashes(this->FileFound);
@@ -2435,10 +2440,6 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
 bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
 bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
                                           std::string& file)
                                           std::string& file)
 {
 {
-  if (this->IgnoredPaths.count(dir)) {
-    return false;
-  }
-
   for (std::string const& c : this->Configs) {
   for (std::string const& c : this->Configs) {
     file = cmStrCat(dir, '/', c);
     file = cmStrCat(dir, '/', c);
     if (this->DebugMode) {
     if (this->DebugMode) {