summaryrefslogtreecommitdiffstats
path: root/Source/cmState.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-05-04 21:30:29 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-05-16 06:12:02 (GMT)
commit9e4b6cc2cebc7af40432f5027d2960c0cc68515f (patch)
treeac9f3904c2cbba953194704dd637802e0311764d /Source/cmState.cxx
parent991f5e4968ce7b86aea12224b4cecc1be3ed92d9 (diff)
downloadCMake-9e4b6cc2cebc7af40432f5027d2960c0cc68515f.zip
CMake-9e4b6cc2cebc7af40432f5027d2960c0cc68515f.tar.gz
CMake-9e4b6cc2cebc7af40432f5027d2960c0cc68515f.tar.bz2
cmState: Store computed relative paths to to current directories.
Diffstat (limited to 'Source/cmState.cxx')
-rw-r--r--Source/cmState.cxx106
1 files changed, 106 insertions, 0 deletions
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 27a36bc..4965ae3 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -199,6 +199,8 @@ void cmState::Initialize()
this->ParentPositions.clear();
this->CurrentSourceDirectoryComponents.clear();
this->CurrentBinaryDirectoryComponents.clear();
+ this->RelativePathTopSource.clear();
+ this->RelativePathTopBinary.clear();
this->CreateSnapshot(Snapshot());
this->DefineProperty
@@ -496,6 +498,86 @@ std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
return this->BinaryDirectoryComponents;
}
+void cmState::Snapshot::ComputeRelativePathTopSource()
+{
+ // Relative path conversion inside the source tree is not used to
+ // construct relative paths passed to build tools so it is safe to use
+ // even when the source is a network path.
+
+ cmState::Snapshot snapshot = *this;
+ std::vector<cmState::Snapshot> snapshots;
+ snapshots.push_back(snapshot);
+ while (true)
+ {
+ snapshot = snapshot.GetParent();
+ if (snapshot.IsValid())
+ {
+ snapshots.push_back(snapshot);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ std::string result = snapshots.front().GetCurrentSourceDirectory();
+
+ for (std::vector<cmState::Snapshot>::const_iterator it =
+ snapshots.begin() + 1; it != snapshots.end(); ++it)
+ {
+ std::string currentSource = it->GetCurrentSourceDirectory();
+ if(cmSystemTools::IsSubDirectory(result, currentSource))
+ {
+ result = currentSource;
+ }
+ }
+ this->State->RelativePathTopSource[this->Position] = result;
+}
+
+void cmState::Snapshot::ComputeRelativePathTopBinary()
+{
+ cmState::Snapshot snapshot = *this;
+ std::vector<cmState::Snapshot> snapshots;
+ snapshots.push_back(snapshot);
+ while (true)
+ {
+ snapshot = snapshot.GetParent();
+ if (snapshot.IsValid())
+ {
+ snapshots.push_back(snapshot);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ std::string result =
+ snapshots.front().GetCurrentBinaryDirectory();
+
+ for (std::vector<cmState::Snapshot>::const_iterator it =
+ snapshots.begin() + 1; it != snapshots.end(); ++it)
+ {
+ std::string currentBinary = it->GetCurrentBinaryDirectory();
+ if(cmSystemTools::IsSubDirectory(result, currentBinary))
+ {
+ result = currentBinary;
+ }
+ }
+
+ // The current working directory on Windows cannot be a network
+ // path. Therefore relative paths cannot work when the binary tree
+ // is a network path.
+ if(result.size() < 2 || result.substr(0, 2) != "//")
+ {
+ this->State->RelativePathTopBinary[this->Position] = result;
+ }
+ else
+ {
+ this->State->RelativePathTopBinary[this->Position] = "";
+ }
+}
+
cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot)
{
PositionType pos = this->ParentPositions.size();
@@ -506,6 +588,8 @@ cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot)
this->CurrentSourceDirectoryComponents.size() + 1);
this->CurrentBinaryDirectoryComponents.resize(
this->CurrentBinaryDirectoryComponents.size() + 1);
+ this->RelativePathTopSource.resize(this->RelativePathTopSource.size() + 1);
+ this->RelativePathTopBinary.resize(this->RelativePathTopBinary.size() + 1);
return cmState::Snapshot(this, pos);
}
@@ -533,6 +617,7 @@ void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir)
cmSystemTools::SplitPath(
this->State->Locations[this->Position],
this->State->CurrentSourceDirectoryComponents[this->Position]);
+ this->ComputeRelativePathTopSource();
}
const char* cmState::Snapshot::GetCurrentBinaryDirectory() const
@@ -553,6 +638,7 @@ void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
cmSystemTools::SplitPath(
this->State->OutputLocations[this->Position],
this->State->CurrentBinaryDirectoryComponents[this->Position]);
+ this->ComputeRelativePathTopBinary();
}
std::vector<std::string> const&
@@ -567,6 +653,26 @@ cmState::Snapshot::GetCurrentBinaryDirectoryComponents()
return this->State->CurrentBinaryDirectoryComponents[this->Position];
}
+const char* cmState::Snapshot::GetRelativePathTopSource() const
+{
+ return this->State->RelativePathTopSource[this->Position].c_str();
+}
+
+const char* cmState::Snapshot::GetRelativePathTopBinary() const
+{
+ return this->State->RelativePathTopBinary[this->Position].c_str();
+}
+
+void cmState::Snapshot::SetRelativePathTopSource(const char* dir)
+{
+ this->State->RelativePathTopSource[this->Position] = dir;
+}
+
+void cmState::Snapshot::SetRelativePathTopBinary(const char* dir)
+{
+ this->State->RelativePathTopBinary[this->Position] = dir;
+}
+
bool cmState::Snapshot::IsValid() const
{
return this->State ? true : false;