mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-18 01:31:04 -05:00
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:
@@ -168,7 +168,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
|||||||
}
|
}
|
||||||
this->ExpandPaths();
|
this->ExpandPaths();
|
||||||
|
|
||||||
this->ComputeFinalPaths();
|
this->ComputeFinalPaths(IgnorePaths::Yes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,14 +283,15 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
|
|||||||
|
|
||||||
void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
|
void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
|
||||||
{
|
{
|
||||||
// null-terminated list of paths.
|
static constexpr const char* paths[] = {
|
||||||
static const char* paths[] = { "CMAKE_SYSTEM_IGNORE_PATH",
|
"CMAKE_SYSTEM_IGNORE_PATH",
|
||||||
"CMAKE_IGNORE_PATH", nullptr };
|
"CMAKE_IGNORE_PATH",
|
||||||
|
};
|
||||||
|
|
||||||
// Construct the list of path roots with no trailing slashes.
|
// 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.
|
// 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) {
|
for (std::string& i : ignore) {
|
||||||
@@ -365,11 +366,13 @@ static void AddTrailingSlash(std::string& s)
|
|||||||
s += '/';
|
s += '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void cmFindCommon::ComputeFinalPaths()
|
void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths)
|
||||||
{
|
{
|
||||||
// Filter out ignored paths from the prefix list
|
// Filter out ignored paths from the prefix list
|
||||||
std::set<std::string> ignored;
|
std::set<std::string> ignored;
|
||||||
this->GetIgnoredPaths(ignored);
|
if (ignorePaths == IgnorePaths::Yes) {
|
||||||
|
this->GetIgnoredPaths(ignored);
|
||||||
|
}
|
||||||
|
|
||||||
// Combine the separate path types, filtering out ignores
|
// Combine the separate path types, filtering out ignores
|
||||||
this->SearchPaths.clear();
|
this->SearchPaths.clear();
|
||||||
|
|||||||
@@ -82,12 +82,17 @@ protected:
|
|||||||
/** Place a set of search paths under the search roots. */
|
/** Place a set of search paths under the search roots. */
|
||||||
void RerootPaths(std::vector<std::string>& paths);
|
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::vector<std::string>& ignore);
|
||||||
void GetIgnoredPaths(std::set<std::string>& ignore);
|
void GetIgnoredPaths(std::set<std::string>& ignore);
|
||||||
|
|
||||||
/** Compute final search path list (reroot + trailing slash). */
|
/** 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. */
|
/** Compute the current default root path mode. */
|
||||||
void SelectDefaultRootPathMode();
|
void SelectDefaultRootPathMode();
|
||||||
|
|||||||
@@ -1346,7 +1346,7 @@ void cmFindPackageCommand::ComputePrefixes()
|
|||||||
}
|
}
|
||||||
this->FillPrefixesUserGuess();
|
this->FillPrefixesUserGuess();
|
||||||
|
|
||||||
this->ComputeFinalPaths();
|
this->ComputeFinalPaths(IgnorePaths::No);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmFindPackageCommand::FillPrefixesPackageRoot()
|
void cmFindPackageCommand::FillPrefixesPackageRoot()
|
||||||
@@ -2286,6 +2286,15 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
|
|||||||
return false;
|
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)
|
// PREFIX/ (useful on windows or in build trees)
|
||||||
if (this->SearchDirectory(prefix_in)) {
|
if (this->SearchDirectory(prefix_in)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user