mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-09 15:20:56 -06:00
cmFindCommon.cxx: Small optimizations
This commit is contained in:
@@ -118,20 +118,13 @@ void cmFindCommon::InitializeSearchPathGroups()
|
||||
this->PathGroupOrder.push_back(PathGroup::All);
|
||||
|
||||
// Create the individual labeled search paths
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::PackageRoot, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::CMake, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::CMakeEnvironment, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::Hints, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::SystemEnvironment, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::CMakeSystem, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::Guess, cmSearchPath(this)));
|
||||
this->LabeledPaths.emplace(PathLabel::PackageRoot, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::CMake, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::CMakeEnvironment, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::Hints, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::SystemEnvironment, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::CMakeSystem, cmSearchPath(this));
|
||||
this->LabeledPaths.emplace(PathLabel::Guess, cmSearchPath(this));
|
||||
}
|
||||
|
||||
void cmFindCommon::SelectDefaultRootPathMode()
|
||||
@@ -215,12 +208,6 @@ void cmFindCommon::SelectDefaultSearchModes()
|
||||
void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
|
||||
std::string* debugBuffer)
|
||||
{
|
||||
#if 0
|
||||
for(std::string const& p : paths)
|
||||
{
|
||||
fprintf(stderr, "[%s]\n", p.c_str());
|
||||
}
|
||||
#endif
|
||||
// Short-circuit if there is nothing to do.
|
||||
if (this->FindRootPathMode == RootPathModeNever) {
|
||||
return;
|
||||
@@ -247,13 +234,13 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
|
||||
auto debugRoot = [this, debugBuffer](const std::string& name,
|
||||
cmValue value) {
|
||||
if (this->DebugMode && debugBuffer) {
|
||||
*debugBuffer = cmStrCat(*debugBuffer, name, "\n");
|
||||
*debugBuffer = cmStrCat(*debugBuffer, name, '\n');
|
||||
cmList roots{ value };
|
||||
if (roots.empty()) {
|
||||
*debugBuffer = cmStrCat(*debugBuffer, " none\n");
|
||||
}
|
||||
for (auto const& root : roots) {
|
||||
*debugBuffer = cmStrCat(*debugBuffer, " ", root, "\n");
|
||||
*debugBuffer = cmStrCat(*debugBuffer, " ", root, '\n');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -325,10 +312,8 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
|
||||
|
||||
void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
|
||||
{
|
||||
static constexpr const char* paths[] = {
|
||||
"CMAKE_SYSTEM_IGNORE_PATH",
|
||||
"CMAKE_IGNORE_PATH",
|
||||
};
|
||||
const std::array<const char*, 2> paths = { { "CMAKE_SYSTEM_IGNORE_PATH",
|
||||
"CMAKE_IGNORE_PATH" } };
|
||||
|
||||
// Construct the list of path roots with no trailing slashes.
|
||||
for (const char* pathName : paths) {
|
||||
@@ -350,11 +335,9 @@ void cmFindCommon::GetIgnoredPaths(std::set<std::string>& ignore)
|
||||
|
||||
void cmFindCommon::GetIgnoredPrefixPaths(std::vector<std::string>& ignore)
|
||||
{
|
||||
static constexpr const char* paths[] = {
|
||||
"CMAKE_SYSTEM_IGNORE_PREFIX_PATH",
|
||||
"CMAKE_IGNORE_PREFIX_PATH",
|
||||
const std::array<const char*, 2> paths = {
|
||||
{ "CMAKE_SYSTEM_IGNORE_PREFIX_PATH", "CMAKE_IGNORE_PREFIX_PATH" }
|
||||
};
|
||||
|
||||
// Construct the list of path roots with no trailing slashes.
|
||||
for (const char* pathName : paths) {
|
||||
// Get the list of paths to ignore from the variable.
|
||||
@@ -377,31 +360,46 @@ bool cmFindCommon::CheckCommonArgument(std::string const& arg)
|
||||
{
|
||||
if (arg == "NO_DEFAULT_PATH") {
|
||||
this->NoDefaultPath = true;
|
||||
} else if (arg == "NO_PACKAGE_ROOT_PATH") {
|
||||
this->NoPackageRootPath = true;
|
||||
} else if (arg == "NO_CMAKE_PATH") {
|
||||
this->NoCMakePath = true;
|
||||
} else if (arg == "NO_CMAKE_ENVIRONMENT_PATH") {
|
||||
this->NoCMakeEnvironmentPath = true;
|
||||
} else if (arg == "NO_SYSTEM_ENVIRONMENT_PATH") {
|
||||
this->NoSystemEnvironmentPath = true;
|
||||
} else if (arg == "NO_CMAKE_SYSTEM_PATH") {
|
||||
this->NoCMakeSystemPath = true;
|
||||
} else if (arg == "NO_CMAKE_INSTALL_PREFIX") {
|
||||
this->NoCMakeInstallPath = true;
|
||||
} else if (arg == "NO_CMAKE_FIND_ROOT_PATH") {
|
||||
this->FindRootPathMode = RootPathModeNever;
|
||||
} else if (arg == "ONLY_CMAKE_FIND_ROOT_PATH") {
|
||||
this->FindRootPathMode = RootPathModeOnly;
|
||||
} else if (arg == "CMAKE_FIND_ROOT_PATH_BOTH") {
|
||||
this->FindRootPathMode = RootPathModeBoth;
|
||||
} else {
|
||||
// The argument is not one of the above.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// The argument is one of the above.
|
||||
return true;
|
||||
if (arg == "NO_PACKAGE_ROOT_PATH") {
|
||||
this->NoPackageRootPath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_CMAKE_PATH") {
|
||||
this->NoCMakePath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_CMAKE_ENVIRONMENT_PATH") {
|
||||
this->NoCMakeEnvironmentPath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_SYSTEM_ENVIRONMENT_PATH") {
|
||||
this->NoSystemEnvironmentPath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_CMAKE_SYSTEM_PATH") {
|
||||
this->NoCMakeSystemPath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_CMAKE_INSTALL_PREFIX") {
|
||||
this->NoCMakeInstallPath = true;
|
||||
return true;
|
||||
}
|
||||
if (arg == "NO_CMAKE_FIND_ROOT_PATH") {
|
||||
this->FindRootPathMode = RootPathModeNever;
|
||||
return true;
|
||||
}
|
||||
if (arg == "ONLY_CMAKE_FIND_ROOT_PATH") {
|
||||
this->FindRootPathMode = RootPathModeOnly;
|
||||
return true;
|
||||
}
|
||||
if (arg == "CMAKE_FIND_ROOT_PATH_BOTH") {
|
||||
this->FindRootPathMode = RootPathModeBoth;
|
||||
return true;
|
||||
}
|
||||
// The argument is not one of the above.
|
||||
return false;
|
||||
}
|
||||
|
||||
void cmFindCommon::AddPathSuffix(std::string const& arg)
|
||||
@@ -429,12 +427,6 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
|
||||
this->SearchPathSuffixes.push_back(std::move(suffix));
|
||||
}
|
||||
|
||||
static void AddTrailingSlash(std::string& s)
|
||||
{
|
||||
if (!s.empty() && s.back() != '/') {
|
||||
s += '/';
|
||||
}
|
||||
}
|
||||
void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths,
|
||||
std::string* debugBuffer)
|
||||
{
|
||||
@@ -459,5 +451,9 @@ void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths,
|
||||
|
||||
// Add a trailing slash to all paths to aid the search process.
|
||||
std::for_each(this->SearchPaths.begin(), this->SearchPaths.end(),
|
||||
&AddTrailingSlash);
|
||||
[](std::string& s) {
|
||||
if (!s.empty() && s.back() != '/') {
|
||||
s += '/';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user