From 46f6a5f458d7d9ef074820d3e90960af2793bd33 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 28 Apr 2015 07:50:31 +0200 Subject: [PATCH] cmState: Store the Current directories. --- Source/cmMakefile.cxx | 22 ++++++++-------------- Source/cmMakefile.h | 2 -- Source/cmState.cxx | 33 +++++++++++++++++++++++++++++++++ Source/cmState.h | 7 +++++++ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5d48f58e6..0935383e9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1647,33 +1647,27 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath, void cmMakefile::SetCurrentSourceDirectory(const std::string& dir) { - this->cmStartDirectory = dir; - cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory); - this->cmStartDirectory = - cmSystemTools::CollapseFullPath(this->cmStartDirectory); + this->StateSnapshot.SetCurrentSourceDirectory(dir); this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", - this->cmStartDirectory.c_str()); + this->StateSnapshot.GetCurrentSourceDirectory()); } const char* cmMakefile::GetCurrentSourceDirectory() const { - return this->cmStartDirectory.c_str(); + return this->StateSnapshot.GetCurrentSourceDirectory(); } void cmMakefile::SetCurrentBinaryDirectory(const std::string& dir) { - this->StartOutputDirectory = dir; - cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory); - this->StartOutputDirectory = - cmSystemTools::CollapseFullPath(this->StartOutputDirectory); - cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str()); - this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", - this->StartOutputDirectory.c_str()); + this->StateSnapshot.SetCurrentBinaryDirectory(dir); + const char* binDir = this->StateSnapshot.GetCurrentBinaryDirectory(); + cmSystemTools::MakeDirectory(binDir); + this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", binDir); } const char* cmMakefile::GetCurrentBinaryDirectory() const { - return this->StartOutputDirectory.c_str(); + return this->StateSnapshot.GetCurrentBinaryDirectory(); } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 447dadc50..8968e81ff 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -858,8 +858,6 @@ protected: // Check for a an unused variable void CheckForUnused(const char* reason, const std::string& name) const; - std::string cmStartDirectory; - std::string StartOutputDirectory; std::string cmCurrentListFile; std::string ProjectName; // project name diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 610257e7f..d6899a450 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -472,6 +472,8 @@ cmState::Snapshot cmState::CreateSnapshot(Snapshot originSnapshot) { PositionType pos = this->ParentPositions.size(); this->ParentPositions.push_back(originSnapshot.Position); + this->Locations.resize(this->Locations.size() + 1); + this->OutputLocations.resize(this->OutputLocations.size() + 1); return cmState::Snapshot(this, pos); } @@ -481,3 +483,34 @@ cmState::Snapshot::Snapshot(cmState* state, PositionType position) { } + +const char* cmState::Snapshot::GetCurrentSourceDirectory() const +{ + return this->State->Locations[this->Position].c_str(); +} + +void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) +{ + assert(this->State->Locations.size() > this->Position); + this->State->Locations[this->Position] = dir; + cmSystemTools::ConvertToUnixSlashes( + this->State->Locations[this->Position]); + this->State->Locations[this->Position] = + cmSystemTools::CollapseFullPath(this->State->Locations[this->Position]); +} + +const char* cmState::Snapshot::GetCurrentBinaryDirectory() const +{ + return this->State->OutputLocations[this->Position].c_str(); +} + +void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) +{ + assert(this->State->OutputLocations.size() > this->Position); + this->State->OutputLocations[this->Position] = dir; + cmSystemTools::ConvertToUnixSlashes( + this->State->OutputLocations[this->Position]); + this->State->OutputLocations[this->Position] = + cmSystemTools::CollapseFullPath( + this->State->OutputLocations[this->Position]); +} diff --git a/Source/cmState.h b/Source/cmState.h index f35cbd6d5..9902db909 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -31,6 +31,11 @@ public: public: Snapshot(cmState* state = 0, PositionType position = 0); + const char* GetCurrentSourceDirectory() const; + void SetCurrentSourceDirectory(std::string const& dir); + const char* GetCurrentBinaryDirectory() const; + void SetCurrentBinaryDirectory(std::string const& dir); + private: friend class cmState; cmState* State; @@ -120,6 +125,8 @@ private: std::map Commands; cmPropertyMap GlobalProperties; cmake* CMakeInstance; + std::vector Locations; + std::vector OutputLocations; std::vector ParentPositions; std::string SourceDirectory; std::string BinaryDirectory;