summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-01-28 16:15:17 -0500
committerKyle Edwards <kyle.edwards@kitware.com>2022-01-31 10:41:04 -0500
commit11f97d196880e78717211ab68138e9ff922ec826 (patch)
tree400e8f63b976ecc00afd03b4ce66ca44c27040c7 /Source
parent30e5c1d92baf6e5ac0daed4e4debcdf208968a65 (diff)
downloadcmake-11f97d196880e78717211ab68138e9ff922ec826.tar.gz
find_package(): Refactor CMAKE_[SYSTEM_]IGNORE_PATH
In the old implementation, CMAKE_[SYSTEM_]IGNORE_PATH was handled in cmFindCommon. Move it into cmFindPackageCommand.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFindBase.cxx2
-rw-r--r--Source/cmFindCommon.cxx17
-rw-r--r--Source/cmFindCommon.h9
-rw-r--r--Source/cmFindPackageCommand.cxx11
4 files changed, 28 insertions, 11 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index a123e4408d..efc4e3a957 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -168,7 +168,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
}
this->ExpandPaths();
- this->ComputeFinalPaths();
+ this->ComputeFinalPaths(IgnorePaths::Yes);
return true;
}
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index 7631583d4f..c58db1e67e 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -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();
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
index 1a49aff84f..49d64e4711 100644
--- a/Source/cmFindCommon.h
+++ b/Source/cmFindCommon.h
@@ -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();
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 6d788e4790..c468a3cbed 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -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;