From 841164cb36650574a1a7363c78e4cdf28d5d37fd Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Tue, 13 Oct 2015 21:57:54 +0200
Subject: cmState: Initialize current directories immediately.

Don't leave this as cmMakefile responsibility.
---
 Source/cmMakefile.cxx | 28 ++--------------------------
 Source/cmState.cxx    |  8 ++++++++
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 2c5501e..f804d06 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -118,32 +118,6 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
   this->AddSourceGroup("Resources", "\\.plist$");
   this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
 #endif
-
-  {
-  const char* dir = this->StateSnapshot.GetDirectory().GetCurrentSource();
-  if (dir)
-    {
-    this->StateSnapshot.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", dir);
-    }
-  else
-    {
-    this->StateSnapshot.SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
-                        this->GetCMakeInstance()->GetHomeDirectory());
-    }
-  }
-  {
-  const char* dir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
-  if (dir)
-    {
-    cmSystemTools::MakeDirectory(dir);
-    this->StateSnapshot.SetDefinition("CMAKE_CURRENT_BINARY_DIR", dir);
-    }
-  else
-    {
-    this->StateSnapshot.SetDefinition("CMAKE_CURRENT_BINARY_DIR",
-                        this->GetCMakeInstance()->GetHomeOutputDirectory());
-    }
-  }
 }
 
 cmMakefile::~cmMakefile()
@@ -1756,6 +1730,8 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
   newSnapshot.GetDirectory().SetCurrentSource(srcPath);
   newSnapshot.GetDirectory().SetCurrentBinary(binPath);
 
+  cmSystemTools::MakeDirectory(binPath.c_str());
+
   cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
   this->GetGlobalGenerator()->AddMakefile(subMf);
 
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 9de58d8..e3f62b5 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -1020,6 +1020,8 @@ void cmState::Directory::SetCurrentSource(std::string const& dir)
       loc,
       this->DirectoryState->CurrentSourceDirectoryComponents);
   this->ComputeRelativePathTopSource();
+
+  this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc.c_str());
 }
 
 const char* cmState::Directory::GetCurrentBinary() const
@@ -1038,6 +1040,8 @@ void cmState::Directory::SetCurrentBinary(std::string const& dir)
       loc,
       this->DirectoryState->CurrentBinaryDirectoryComponents);
   this->ComputeRelativePathTopBinary();
+
+  this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc.c_str());
 }
 
 void cmState::Snapshot::SetListFile(const std::string& listfile)
@@ -1333,8 +1337,12 @@ void cmState::Snapshot::SetDirectoryDefinitions()
 {
   this->SetDefinition("CMAKE_SOURCE_DIR",
                       this->State->GetSourceDirectory());
+  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
+                      this->State->GetSourceDirectory());
   this->SetDefinition("CMAKE_BINARY_DIR",
                       this->State->GetBinaryDirectory());
+  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
+                      this->State->GetBinaryDirectory());
 }
 
 void cmState::Snapshot::InitializeFromParent()
-- 
cgit v0.12