From c5cb3a734dd6d2472f10379d45dcec7ce03293d9 Mon Sep 17 00:00:00 2001
From: Stephen Kelly <steveire@gmail.com>
Date: Sun, 3 May 2015 17:19:16 +0200
Subject: cmLocalGenerator: Get project directories from the cmState.

Make this class and cmMakefile less interdependent.
---
 Source/cmLocalGenerator.cxx | 73 ++++++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 37 deletions(-)

diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index c099a4d..f3ad60a 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -115,7 +115,7 @@ void cmLocalGenerator::Configure()
   static_cast<void>(clg);
 
   // make sure the CMakeFiles dir is there
-  std::string filesDir = this->Makefile->GetCurrentBinaryDirectory();
+  std::string filesDir = this->StateSnapshot.GetCurrentBinaryDirectory();
   filesDir += cmake::GetCMakeFilesDirectory();
   cmSystemTools::MakeDirectory(filesDir.c_str());
 
@@ -191,7 +191,7 @@ void cmLocalGenerator::ComputeObjectMaxPath()
 void cmLocalGenerator::ReadInputFile()
 {
   // Look for the CMakeLists.txt file.
-  std::string currentStart = this->Makefile->GetCurrentSourceDirectory();
+  std::string currentStart = this->StateSnapshot.GetCurrentSourceDirectory();
   currentStart += "/CMakeLists.txt";
   if(cmSystemTools::FileExists(currentStart.c_str(), true))
     {
@@ -208,7 +208,7 @@ void cmLocalGenerator::ReadInputFile()
   cmMakefile* mf = this->Parent->GetMakefile();
   std::ostringstream e;
   e << "The source directory\n"
-    << "  " << this->Makefile->GetCurrentSourceDirectory() << "\n"
+    << "  " << this->StateSnapshot.GetCurrentSourceDirectory() << "\n"
     << "does not contain a CMakeLists.txt file.";
   switch (mf->GetPolicyStatus(cmPolicies::CMP0014))
     {
@@ -241,20 +241,19 @@ void cmLocalGenerator::SetupPathConversions()
   // Convert
   std::string outdir;
   outdir =
-    cmSystemTools::CollapseFullPath(this->Makefile->GetHomeDirectory());
+    cmSystemTools::CollapseFullPath(this->GetState()->GetSourceDirectory());
   cmSystemTools::SplitPath(outdir, this->HomeDirectoryComponents);
-  outdir =
-    cmSystemTools::CollapseFullPath(
-                                this->Makefile->GetCurrentSourceDirectory());
+  outdir = cmSystemTools::CollapseFullPath(
+      this->StateSnapshot.GetCurrentSourceDirectory());
   cmSystemTools::SplitPath(outdir, this->StartDirectoryComponents);
 
   outdir = cmSystemTools::CollapseFullPath
-    (this->Makefile->GetHomeOutputDirectory());
+    (this->GetState()->GetBinaryDirectory());
   cmSystemTools::SplitPath(outdir,
                            this->HomeOutputDirectoryComponents);
 
   outdir = cmSystemTools::CollapseFullPath
-    (this->Makefile->GetCurrentBinaryDirectory());
+    (this->StateSnapshot.GetCurrentBinaryDirectory());
   cmSystemTools::SplitPath(outdir,
                            this->StartOutputDirectoryComponents);
 }
@@ -303,7 +302,7 @@ void cmLocalGenerator::GenerateTestFiles()
   const std::string& config =
     this->Makefile->GetConfigurations(configurationTypes, false);
 
-  std::string file = this->Makefile->GetCurrentBinaryDirectory();
+  std::string file = this->StateSnapshot.GetCurrentBinaryDirectory();
   file += "/";
   file += "CTestTestfile.cmake";
 
@@ -312,9 +311,9 @@ void cmLocalGenerator::GenerateTestFiles()
 
   fout << "# CMake generated Testfile for " << std::endl
        << "# Source directory: "
-       << this->Makefile->GetCurrentSourceDirectory() << std::endl
+       << this->StateSnapshot.GetCurrentSourceDirectory() << std::endl
        << "# Build directory: "
-       << this->Makefile->GetCurrentBinaryDirectory() << std::endl
+       << this->StateSnapshot.GetCurrentBinaryDirectory() << std::endl
        << "# " << std::endl
        << "# This file includes the relevant testing commands "
        << "required for " << std::endl
@@ -428,9 +427,9 @@ void cmLocalGenerator::GenerateInstallRules()
     }
 
   // Create the install script file.
-  std::string file = this->Makefile->GetCurrentBinaryDirectory();
-  std::string homedir = this->Makefile->GetHomeOutputDirectory();
-  std::string currdir = this->Makefile->GetCurrentBinaryDirectory();
+  std::string file = this->StateSnapshot.GetCurrentBinaryDirectory();
+  std::string homedir = this->GetState()->GetBinaryDirectory();
+  std::string currdir = this->StateSnapshot.GetCurrentBinaryDirectory();
   cmSystemTools::ConvertToUnixSlashes(file);
   cmSystemTools::ConvertToUnixSlashes(homedir);
   cmSystemTools::ConvertToUnixSlashes(currdir);
@@ -445,7 +444,7 @@ void cmLocalGenerator::GenerateInstallRules()
 
   // Write the header.
   fout << "# Install script for directory: "
-       << this->Makefile->GetCurrentSourceDirectory()
+       << this->StateSnapshot.GetCurrentSourceDirectory()
        << std::endl << std::endl;
   fout << "# Set the install prefix" << std::endl
        << "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
@@ -664,7 +663,7 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
     source.GetFullPath(),
     commandLines,
     comment.c_str(),
-    this->Makefile->GetCurrentBinaryDirectory()
+    this->StateSnapshot.GetCurrentBinaryDirectory()
     );
 }
 
@@ -686,12 +685,12 @@ void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
        !sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
       {
       std::string dir_max;
-      dir_max += this->Makefile->GetCurrentBinaryDirectory();
+      dir_max += this->StateSnapshot.GetCurrentBinaryDirectory();
       dir_max += "/";
       std::string obj = this->GetObjectFileNameWithoutTarget(*sf, dir_max);
       if(!obj.empty())
         {
-        std::string ofname = this->Makefile->GetCurrentBinaryDirectory();
+        std::string ofname = this->StateSnapshot.GetCurrentBinaryDirectory();
         ofname += "/";
         ofname += obj;
         objVector.push_back(ofname);
@@ -761,7 +760,7 @@ void cmLocalGenerator::AddBuildTargetRule(const std::string& llang,
     "",
     commandLines,
     comment.c_str(),
-    this->Makefile->GetCurrentBinaryDirectory()
+    this->StateSnapshot.GetCurrentBinaryDirectory()
     );
   this->Makefile->GetSource(targetFullPath);
   target.Target->AddSource(targetFullPath);
@@ -1565,19 +1564,19 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
   if(includeBinaryDir)
     {
     if(emitted.find(
-                this->Makefile->GetCurrentBinaryDirectory()) == emitted.end())
+        this->StateSnapshot.GetCurrentBinaryDirectory()) == emitted.end())
       {
-      dirs.push_back(this->Makefile->GetCurrentBinaryDirectory());
-      emitted.insert(this->Makefile->GetCurrentBinaryDirectory());
+      dirs.push_back(this->StateSnapshot.GetCurrentBinaryDirectory());
+      emitted.insert(this->StateSnapshot.GetCurrentBinaryDirectory());
       }
     }
   if(includeSourceDir)
     {
     if(emitted.find(
-                this->Makefile->GetCurrentSourceDirectory()) == emitted.end())
+        this->StateSnapshot.GetCurrentSourceDirectory()) == emitted.end())
       {
-      dirs.push_back(this->Makefile->GetCurrentSourceDirectory());
-      emitted.insert(this->Makefile->GetCurrentSourceDirectory());
+      dirs.push_back(this->StateSnapshot.GetCurrentSourceDirectory());
+      emitted.insert(this->StateSnapshot.GetCurrentSourceDirectory());
       }
     }
 
@@ -1619,8 +1618,8 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
   // it is requested by the project.
   if(this->Makefile->IsOn("CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"))
     {
-    const char* topSourceDir = this->Makefile->GetHomeDirectory();
-    const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory();
+    const char* topSourceDir = this->GetState()->GetSourceDirectory();
+    const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
     for(std::vector<std::string>::const_iterator i = includes.begin();
         i != includes.end(); ++i)
       {
@@ -2178,7 +2177,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
 
   // Treat the name as relative to the source directory in which it
   // was given.
-  dep = this->Makefile->GetCurrentSourceDirectory();
+  dep = this->StateSnapshot.GetCurrentSourceDirectory();
   dep += "/";
   dep += inName;
   return true;
@@ -2730,10 +2729,10 @@ const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
 {
   switch (relroot)
     {
-    case HOME:         return this->Makefile->GetHomeDirectory();
-    case START:        return this->Makefile->GetCurrentSourceDirectory();
-    case HOME_OUTPUT:  return this->Makefile->GetHomeOutputDirectory();
-    case START_OUTPUT: return this->Makefile->GetCurrentBinaryDirectory();
+    case HOME:         return this->GetState()->GetSourceDirectory();
+    case START:        return this->StateSnapshot.GetCurrentSourceDirectory();
+    case HOME_OUTPUT:  return this->GetState()->GetBinaryDirectory();
+    case START_OUTPUT: return this->StateSnapshot.GetCurrentBinaryDirectory();
     default: break;
     }
   return 0;
@@ -2861,14 +2860,14 @@ std::string cmLocalGenerator::FindRelativePathTopSource()
     {
     std::string parentTop = parent->FindRelativePathTopSource();
     if(cmSystemTools::IsSubDirectory(
-         this->Makefile->GetCurrentSourceDirectory(), parentTop))
+         this->StateSnapshot.GetCurrentSourceDirectory(), parentTop))
       {
       return parentTop;
       }
     }
 
   // Otherwise this directory itself is the new top.
-  return this->Makefile->GetCurrentSourceDirectory();
+  return this->StateSnapshot.GetCurrentSourceDirectory();
 }
 
 //----------------------------------------------------------------------------
@@ -2881,14 +2880,14 @@ std::string cmLocalGenerator::FindRelativePathTopBinary()
     {
     std::string parentTop = parent->FindRelativePathTopBinary();
     if(cmSystemTools::IsSubDirectory(
-         this->Makefile->GetCurrentBinaryDirectory(), parentTop))
+         this->StateSnapshot.GetCurrentBinaryDirectory(), parentTop))
       {
       return parentTop;
       }
     }
 
   // Otherwise this directory itself is the new top.
-  return this->Makefile->GetCurrentBinaryDirectory();
+  return this->StateSnapshot.GetCurrentBinaryDirectory();
 }
 
 //----------------------------------------------------------------------------
-- 
cgit v0.12