From 230e5ec17259706ccb0fb469fc51be3a0414b7bf Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Tue, 29 Oct 2024 13:49:04 -0400 Subject: [PATCH] find_package: Don't test _DIR against ignored paths Tweak `find_package` to not compare an already-specified `_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 `_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. --- Source/cmFindPackageCommand.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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) {