diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 1fce4dd7f4..4f97a18482 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include "cmsys/Directory.hxx" @@ -2422,8 +2423,12 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir) { assert(!dir.empty() && dir.back() == '/'); - // Look for the file in this directory. 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)) { // Remove duplicate slashes. cmSystemTools::ConvertToUnixSlashes(this->FileFound); @@ -2435,10 +2440,6 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir) bool cmFindPackageCommand::FindConfigFile(std::string const& dir, std::string& file) { - if (this->IgnoredPaths.count(dir)) { - return false; - } - for (std::string const& c : this->Configs) { file = cmStrCat(dir, '/', c); if (this->DebugMode) {