find_package(): Refactor CMAKE_[SYSTEM_]IGNORE_PATH

In the old implementation, CMAKE_[SYSTEM_]IGNORE_PATH was handled
in cmFindCommon. Move it into cmFindPackageCommand.
This commit is contained in:
Kyle Edwards
2022-01-28 16:15:17 -05:00
parent 30e5c1d92b
commit 11f97d1968
4 changed files with 28 additions and 11 deletions

View File

@@ -168,7 +168,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
}
this->ExpandPaths();
this->ComputeFinalPaths();
this->ComputeFinalPaths(IgnorePaths::Yes);
return true;
}

View File

@@ -283,14 +283,15 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
{
// null-terminated list of paths.
static const char* paths[] = { "CMAKE_SYSTEM_IGNORE_PATH",
"CMAKE_IGNORE_PATH", nullptr };
static constexpr const char* paths[] = {
"CMAKE_SYSTEM_IGNORE_PATH",
"CMAKE_IGNORE_PATH",
};
// Construct the list of path roots with no trailing slashes.
for (const char** pathName = paths; *pathName; ++pathName) {
for (const char* pathName : paths) {
// Get the list of paths to ignore from the variable.
this->Makefile->GetDefExpandList(*pathName, ignore);
this->Makefile->GetDefExpandList(pathName, ignore);
}
for (std::string& i : ignore) {
@@ -365,11 +366,13 @@ static void AddTrailingSlash(std::string& s)
s += '/';
}
}
void cmFindCommon::ComputeFinalPaths()
void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths)
{
// Filter out ignored paths from the prefix list
std::set<std::string> ignored;
this->GetIgnoredPaths(ignored);
if (ignorePaths == IgnorePaths::Yes) {
this->GetIgnoredPaths(ignored);
}
// Combine the separate path types, filtering out ignores
this->SearchPaths.clear();

View File

@@ -82,12 +82,17 @@ protected:
/** Place a set of search paths under the search roots. */
void RerootPaths(std::vector<std::string>& paths);
/** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_path variables. */
/** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PATH variables. */
void GetIgnoredPaths(std::vector<std::string>& ignore);
void GetIgnoredPaths(std::set<std::string>& ignore);
/** Compute final search path list (reroot + trailing slash). */
void ComputeFinalPaths();
enum class IgnorePaths
{
No,
Yes,
};
void ComputeFinalPaths(IgnorePaths ignorePaths);
/** Compute the current default root path mode. */
void SelectDefaultRootPathMode();

View File

@@ -1346,7 +1346,7 @@ void cmFindPackageCommand::ComputePrefixes()
}
this->FillPrefixesUserGuess();
this->ComputeFinalPaths();
this->ComputeFinalPaths(IgnorePaths::No);
}
void cmFindPackageCommand::FillPrefixesPackageRoot()
@@ -2286,6 +2286,15 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
return false;
}
// Skip this if it's in ignored paths.
std::string prefixWithoutSlash = prefix_in;
if (prefixWithoutSlash != "/" && prefixWithoutSlash.back() == '/') {
prefixWithoutSlash.erase(prefixWithoutSlash.length() - 1);
}
if (this->IgnoredPaths.count(prefixWithoutSlash)) {
return false;
}
// PREFIX/ (useful on windows or in build trees)
if (this->SearchDirectory(prefix_in)) {
return true;