cmLocalGenerator: Get project directories from the cmState.

Make this class and cmMakefile less interdependent.
This commit is contained in:
Stephen Kelly 2015-05-03 17:19:16 +02:00
parent 76b598319f
commit c5cb3a734d
1 changed files with 36 additions and 37 deletions

View File

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