summaryrefslogtreecommitdiffstats
path: root/Source/cmSearchPath.cxx
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-02-01 19:42:54 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2022-02-02 16:09:00 (GMT)
commitbd805a51ae4b5be5be6bbadf4afab108fcf4ddb3 (patch)
tree9f487e27f9af0ef2b9c092919c1165c85bb4bc11 /Source/cmSearchPath.cxx
parent92459258108c0036808f29f83a8503fea18ccee9 (diff)
downloadCMake-bd805a51ae4b5be5be6bbadf4afab108fcf4ddb3.zip
CMake-bd805a51ae4b5be5be6bbadf4afab108fcf4ddb3.tar.gz
CMake-bd805a51ae4b5be5be6bbadf4afab108fcf4ddb3.tar.bz2
Refactor: Keep track of prefixes in cmSearchPath
Diffstat (limited to 'Source/cmSearchPath.cxx')
-rw-r--r--Source/cmSearchPath.cxx59
1 files changed, 37 insertions, 22 deletions
diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx
index 1bb459c..ff54a8a 100644
--- a/Source/cmSearchPath.cxx
+++ b/Source/cmSearchPath.cxx
@@ -26,16 +26,16 @@ void cmSearchPath::ExtractWithout(const std::set<std::string>& ignore,
if (clear) {
outPaths.clear();
}
- for (std::string const& path : this->Paths) {
- if (ignore.count(path) == 0) {
- outPaths.push_back(path);
+ for (auto const& path : this->Paths) {
+ if (ignore.count(path.Path) == 0) {
+ outPaths.push_back(path.Path);
}
}
}
void cmSearchPath::AddPath(const std::string& path)
{
- this->AddPathInternal(path);
+ this->AddPathInternal(path, "");
}
void cmSearchPath::AddUserPath(const std::string& path)
@@ -69,7 +69,7 @@ void cmSearchPath::AddUserPath(const std::string& path)
// Process them all from the current directory
for (std::string const& p : outPaths) {
this->AddPathInternal(
- p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
+ p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
@@ -83,7 +83,7 @@ void cmSearchPath::AddCMakePath(const std::string& variable)
for (std::string const& p : expanded) {
this->AddPathInternal(
- p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
+ p, "", this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
}
@@ -93,7 +93,7 @@ void cmSearchPath::AddEnvPath(const std::string& variable)
std::vector<std::string> expanded;
cmSystemTools::GetPath(expanded, variable.c_str());
for (std::string const& p : expanded) {
- this->AddPathInternal(p);
+ this->AddPathInternal(p, "");
}
}
@@ -132,24 +132,25 @@ void cmSearchPath::AddEnvPrefixPath(const std::string& variable, bool stripBin)
void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
{
- std::vector<std::string> inPaths;
+ std::vector<PathWithPrefix> inPaths;
inPaths.swap(this->Paths);
this->Paths.reserve(inPaths.size() * (suffixes.size() + 1));
- for (std::string& inPath : inPaths) {
- cmSystemTools::ConvertToUnixSlashes(inPath);
+ for (PathWithPrefix& inPath : inPaths) {
+ cmSystemTools::ConvertToUnixSlashes(inPath.Path);
+ cmSystemTools::ConvertToUnixSlashes(inPath.Prefix);
// if *i is only / then do not add a //
// this will get incorrectly considered a network
// path on windows and cause huge delays.
- std::string p = inPath;
+ std::string p = inPath.Path;
if (!p.empty() && p.back() != '/') {
p += "/";
}
// Combine with all the suffixes
for (std::string const& suffix : suffixes) {
- this->Paths.push_back(p + suffix);
+ this->Paths.push_back(PathWithPrefix{ p + suffix, inPath.Prefix });
}
// And now the original w/o any suffix
@@ -178,6 +179,10 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
if (!subdir.empty() && !dir.empty() && dir.back() != '/') {
dir += "/";
}
+ std::string prefix = dir;
+ if (!prefix.empty() && prefix != "/") {
+ prefix.erase(prefix.size() - 1);
+ }
if (subdir == "include" || subdir == "lib") {
cmValue arch =
this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
@@ -185,37 +190,47 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
if (this->FC->Makefile->IsDefinitionSet("CMAKE_SYSROOT") &&
this->FC->Makefile->IsDefinitionSet(
"CMAKE_PREFIX_LIBRARY_ARCHITECTURE")) {
- this->AddPathInternal(cmStrCat('/', *arch, dir, subdir), base);
+ this->AddPathInternal(cmStrCat('/', *arch, dir, subdir),
+ cmStrCat('/', *arch, prefix), base);
} else {
- this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), base);
+ this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), prefix,
+ base);
}
}
}
std::string add = dir + subdir;
if (add != "/") {
- this->AddPathInternal(add, base);
+ this->AddPathInternal(add, prefix, base);
}
if (subdir == "bin") {
- this->AddPathInternal(dir + "sbin", base);
+ this->AddPathInternal(dir + "sbin", prefix, base);
}
if (!subdir.empty() && path != "/") {
- this->AddPathInternal(path, base);
+ this->AddPathInternal(path, prefix, base);
}
}
}
-void cmSearchPath::AddPathInternal(const std::string& path, const char* base)
+void cmSearchPath::AddPathInternal(const std::string& path,
+ const std::string& prefix, const char* base)
{
assert(this->FC != nullptr);
- std::string collapsed = cmSystemTools::CollapseFullPath(path, base);
+ std::string collapsedPath = cmSystemTools::CollapseFullPath(path, base);
- if (collapsed.empty()) {
+ if (collapsedPath.empty()) {
return;
}
+ std::string collapsedPrefix;
+ if (!prefix.empty()) {
+ collapsedPrefix = cmSystemTools::CollapseFullPath(prefix, base);
+ }
+
// Insert the path if has not already been emitted.
- if (this->FC->SearchPathsEmitted.insert(collapsed).second) {
- this->Paths.push_back(std::move(collapsed));
+ PathWithPrefix pathWithPrefix{ std::move(collapsedPath),
+ std::move(collapsedPrefix) };
+ if (this->FC->SearchPathsEmitted.insert(pathWithPrefix).second) {
+ this->Paths.emplace_back(std::move(pathWithPrefix));
}
}