summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx361
1 files changed, 78 insertions, 283 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 85bc493..cb66a75 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -16,7 +16,6 @@
#include "cmSourceFileLocation.h"
#include "cmSystemTools.h"
#include "cmGlobalGenerator.h"
-#include "cmLocalGenerator.h"
#include "cmCommands.h"
#include "cmState.h"
#include "cmOutputConverter.h"
@@ -31,7 +30,6 @@
#endif
#include "cmInstallGenerator.h"
#include "cmTestGenerator.h"
-#include "cmDefinitions.h"
#include "cmAlgorithms.h"
#include "cmake.h"
#include <stdlib.h> // required for atoi
@@ -44,111 +42,18 @@
#include <ctype.h> // for isspace
#include <assert.h>
-class cmMakefile::Internals
-{
-public:
- std::list<cmDefinitions> VarStack;
- bool IsSourceFileTryCompile;
-
- void PushDefinitions()
- {
- this->VarStack.push_back(cmDefinitions());
- }
-
- void InitializeDefinitions(cmMakefile* parent)
- {
- this->VarStack.back() =
- cmDefinitions::MakeClosure(parent->Internal->VarStack.rbegin(),
- parent->Internal->VarStack.rend());
- }
-
- const char* GetDefinition(std::string const& name)
- {
- return cmDefinitions::Get(name, this->VarStack.rbegin(),
- this->VarStack.rend());
- }
-
- bool IsInitialized(std::string const& name)
- {
- return cmDefinitions::HasKey(name, this->VarStack.rbegin(),
- this->VarStack.rend());
- }
-
- void SetDefinition(std::string const& name, std::string const& value)
- {
- this->VarStack.back().Set(name, value.c_str());
- }
-
- void RemoveDefinition(std::string const& name)
- {
- this->VarStack.back().Set(name, 0);
- }
-
- std::vector<std::string> UnusedKeys() const
- {
- return this->VarStack.back().UnusedKeys();
- }
-
- std::vector<std::string> ClosureKeys() const
- {
- return cmDefinitions::ClosureKeys(this->VarStack.rbegin(),
- this->VarStack.rend());
- }
-
- void PopDefinitions()
- {
- this->VarStack.pop_back();
- }
-
- bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
- {
- std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
- assert(it != this->VarStack.rend());
- ++it;
- if(it == this->VarStack.rend())
- {
- cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
- if(!plg)
- {
- return false;
- }
- // Update the definition in the parent directory top scope. This
- // directory's scope was initialized by the closure of the parent
- // scope, so we do not need to localize the definition first.
- cmMakefile* parent = plg->GetMakefile();
- if (varDef)
- {
- parent->AddDefinition(var, varDef);
- }
- else
- {
- parent->RemoveDefinition(var);
- }
- return true;
- }
- // First localize the definition in the current scope.
- cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
-
- // Now update the definition in the parent scope.
- it->Set(var, varDef);
- return true;
- }
-};
-
// default is not to be building executables
-cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
- : Internal(new Internals),
- LocalGenerator(localGenerator),
- StateSnapshot(localGenerator->GetStateSnapshot())
+cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
+ cmState::Snapshot const& snapshot)
+ : GlobalGenerator(globalGenerator),
+ StateSnapshot(snapshot)
{
- this->Internal->PushDefinitions();
- this->Internal->IsSourceFileTryCompile = false;
+ this->IsSourceFileTryCompile = false;
// Initialize these first since AddDefaultDefinitions calls AddDefinition
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
- this->Configured = false;
this->SuppressWatches = false;
// Setup the default include file regular expression (match everything).
@@ -1567,9 +1472,6 @@ void cmMakefile::AddLinkLibrary(const std::string& lib)
void cmMakefile::InitializeFromParent(cmMakefile* parent)
{
- // Initialize definitions with the closure of the parent scope.
- this->Internal->InitializeDefinitions(parent);
-
this->StateSnapshot.InitializeFromParent();
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
@@ -1615,7 +1517,7 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
parent->GetProperty("LINK_DIRECTORIES"));
// the initial project name
- this->ProjectName = parent->ProjectName;
+ this->SetProjectName(parent->GetProjectName());
// Copy include regular expressions.
this->ComplainFileRegularExpression = parent->ComplainFileRegularExpression;
@@ -1634,8 +1536,6 @@ void cmMakefile::PushFunctionScope(std::string const& fileName,
fileName);
assert(this->StateSnapshot.IsValid());
- this->Internal->PushDefinitions();
-
this->PushLoopBlockBarrier();
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -1662,8 +1562,6 @@ void cmMakefile::PopFunctionScope(bool reportError)
this->PopLoopBlockBarrier();
this->CheckForUnusedVariables();
-
- this->Internal->PopDefinitions();
}
void cmMakefile::PushMacroScope(std::string const& fileName,
@@ -1759,7 +1657,6 @@ void cmMakefile::Configure()
cmParseFileScope pfs(this);
if (!listFile.ParseFile(currentStart.c_str(), this->IsRootMakefile(), this))
{
- this->SetConfigured();
return;
}
}
@@ -1780,7 +1677,6 @@ void cmMakefile::Configure()
}
this->AddCMakeDependFilesFromUser();
- this->SetConfigured();
}
void cmMakefile::ConfigureSubDirectory(cmMakefile *mf)
@@ -1824,7 +1720,6 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile *mf)
// NEW behavior prints the error.
this->IssueMessage(cmake::FATAL_ERROR, e.str());
}
- mf->SetConfigured();
return;
}
// finally configure the subdir
@@ -1854,13 +1749,8 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
this->ContextStack.back()->Name,
this->ContextStack.back()->Line);
- // create a new local generator and set its parent
- cmLocalGenerator *lg2 = this->GetGlobalGenerator()
- ->MakeLocalGenerator(newSnapshot, this->LocalGenerator);
- this->GetGlobalGenerator()->AddMakefile(lg2->GetMakefile());
- this->GetGlobalGenerator()->AddLocalGenerator(lg2);
-
- cmMakefile* subMf = lg2->GetMakefile();
+ cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
+ this->GetGlobalGenerator()->AddMakefile(subMf);
// set the subdirs start dirs
subMf->SetCurrentSourceDirectory(srcPath);
@@ -1967,7 +1857,7 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value)
{
this->LogUnused("changing definition", name);
}
- this->Internal->SetDefinition(name, value);
+ this->StateSnapshot.SetDefinition(name, value);
#ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch();
@@ -2030,7 +1920,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
doc, type);
// if there was a definition then remove it
- this->Internal->RemoveDefinition(name);
+ this->StateSnapshot.RemoveDefinition(name);
}
@@ -2040,7 +1930,9 @@ void cmMakefile::AddDefinition(const std::string& name, bool value)
{
this->LogUnused("changing definition", name);
}
- this->Internal->SetDefinition(name, value ? "ON" : "OFF");
+
+ this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF");
+
#ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch();
if ( vv )
@@ -2057,7 +1949,7 @@ void cmMakefile::CheckForUnusedVariables() const
{
return;
}
- const std::vector<std::string>& unused = this->Internal->UnusedKeys();
+ const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys();
std::vector<std::string>::const_iterator it = unused.begin();
for (; it != unused.end(); ++it)
{
@@ -2067,12 +1959,12 @@ void cmMakefile::CheckForUnusedVariables() const
void cmMakefile::MarkVariableAsUsed(const std::string& var)
{
- this->Internal->GetDefinition(var);
+ this->StateSnapshot.GetDefinition(var);
}
bool cmMakefile::VariableInitialized(const std::string& var) const
{
- return this->Internal->IsInitialized(var);
+ return this->StateSnapshot.IsInitialized(var);
}
void cmMakefile::LogUnused(const char* reason,
@@ -2120,7 +2012,7 @@ void cmMakefile::RemoveDefinition(const std::string& name)
{
this->LogUnused("unsetting", name);
}
- this->Internal->RemoveDefinition(name);
+ this->StateSnapshot.RemoveDefinition(name);
#ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch();
if ( vv )
@@ -2136,11 +2028,15 @@ void cmMakefile::RemoveCacheDefinition(const std::string& name)
this->GetState()->RemoveCacheEntry(name);
}
-void cmMakefile::SetProjectName(const char* p)
+void cmMakefile::SetProjectName(std::string const& p)
{
- this->ProjectName = p;
+ this->StateSnapshot.SetProjectName(p);
}
+std::string cmMakefile::GetProjectName() const
+{
+ return this->StateSnapshot.GetProjectName();
+}
void cmMakefile::AddGlobalLinkInformation(const std::string& name,
cmTarget& target)
@@ -2171,7 +2067,8 @@ void cmMakefile::AddGlobalLinkInformation(const std::string& name,
if(std::find(this->LinkDirectories.begin(),
this->LinkDirectories.end(), newdir)
== this->LinkDirectories.end())
- {target.AddLinkDirectory(*j);
+ {
+ target.AddLinkDirectory(*j);
}
}
}
@@ -2428,7 +2325,8 @@ void cmMakefile::ExpandVariablesCMP0019()
l != this->Targets.end(); ++l)
{
cmTarget &t = l->second;
- if (t.GetType() == cmTarget::INTERFACE_LIBRARY)
+ if (t.GetType() == cmTarget::INTERFACE_LIBRARY
+ || t.GetType() == cmTarget::GLOBAL_TARGET)
{
continue;
}
@@ -2529,6 +2427,18 @@ bool cmMakefile::PlatformIs64Bit() const
return false;
}
+bool cmMakefile::PlatformIsAppleIos() const
+{
+ std::string sdkRoot;
+ sdkRoot = this->GetSafeDefinition("CMAKE_OSX_SYSROOT");
+ sdkRoot = cmSystemTools::LowerCase(sdkRoot);
+
+ return sdkRoot.find("iphoneos") == 0 ||
+ sdkRoot.find("/iphoneos") != std::string::npos ||
+ sdkRoot.find("iphonesimulator") == 0 ||
+ sdkRoot.find("/iphonesimulator") != std::string::npos;
+}
+
const char* cmMakefile::GetSONameFlag(const std::string& language) const
{
std::string name = "CMAKE_SHARED_LIBRARY_SONAME";
@@ -2586,7 +2496,7 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
bool cmMakefile::IsDefinitionSet(const std::string& name) const
{
- const char* def = this->Internal->GetDefinition(name);
+ const char* def = this->StateSnapshot.GetDefinition(name);
if(!def)
{
def = this->GetState()->GetInitializedCacheValue(name);
@@ -2607,7 +2517,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
const char* cmMakefile::GetDefinition(const std::string& name) const
{
- const char* def = this->Internal->GetDefinition(name);
+ const char* def = this->StateSnapshot.GetDefinition(name);
if(!def)
{
def = this->GetState()->GetInitializedCacheValue(name);
@@ -2643,7 +2553,7 @@ const char* cmMakefile::GetSafeDefinition(const std::string& def) const
std::vector<std::string> cmMakefile::GetDefinitions() const
{
- std::vector<std::string> res = this->Internal->ClosureKeys();
+ std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
std::sort(res.begin(), res.end());
@@ -3308,7 +3218,7 @@ void cmMakefile::AddDefaultDefinitions()
//----------------------------------------------------------------------------
std::string
cmMakefile::GetConfigurations(std::vector<std::string>& configs,
- bool single) const
+ bool singleConfig) const
{
if(this->GetGlobalGenerator()->IsMultiConfig())
{
@@ -3322,7 +3232,7 @@ cmMakefile::GetConfigurations(std::vector<std::string>& configs,
else
{
const std::string& buildType = this->GetSafeDefinition("CMAKE_BUILD_TYPE");
- if(single && !buildType.empty())
+ if(singleConfig && !buildType.empty())
{
configs.push_back(buildType);
}
@@ -3696,7 +3606,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
const std::vector<std::string> *cmakeArgs,
std::string& output)
{
- this->Internal->IsSourceFileTryCompile = fast;
+ this->IsSourceFileTryCompile = fast;
// does the binary directory exist ? If not create it...
if (!cmSystemTools::FileIsDirectory(bindir))
{
@@ -3721,7 +3631,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
"Internal CMake error, TryCompile bad GlobalGenerator");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd);
- this->Internal->IsSourceFileTryCompile = false;
+ this->IsSourceFileTryCompile = false;
return 1;
}
cm.SetGlobalGenerator(gg);
@@ -3792,7 +3702,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
"Internal CMake error, TryCompile configure of cmake failed");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd);
- this->Internal->IsSourceFileTryCompile = false;
+ this->IsSourceFileTryCompile = false;
return 1;
}
@@ -3802,7 +3712,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
"Internal CMake error, TryCompile generation of cmake failed");
// return to the original directory
cmSystemTools::ChangeDirectory(cwd);
- this->Internal->IsSourceFileTryCompile = false;
+ this->IsSourceFileTryCompile = false;
return 1;
}
@@ -3815,23 +3725,23 @@ int cmMakefile::TryCompile(const std::string& srcdir,
this);
cmSystemTools::ChangeDirectory(cwd);
- this->Internal->IsSourceFileTryCompile = false;
+ this->IsSourceFileTryCompile = false;
return ret;
}
bool cmMakefile::GetIsSourceFileTryCompile() const
{
- return this->Internal->IsSourceFileTryCompile;
+ return this->IsSourceFileTryCompile;
}
cmake *cmMakefile::GetCMakeInstance() const
{
- return this->GetGlobalGenerator()->GetCMakeInstance();
+ return this->GlobalGenerator->GetCMakeInstance();
}
cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const
{
- return this->LocalGenerator->GetGlobalGenerator();
+ return this->GlobalGenerator;
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -4155,148 +4065,28 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
void cmMakefile::SetProperty(const std::string& prop, const char* value)
{
- if (prop == "INCLUDE_DIRECTORIES")
- {
- if (!value)
- {
- this->StateSnapshot.GetDirectory().ClearIncludeDirectories();
- return;
- }
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().SetIncludeDirectories(value, lfbt);
- return;
- }
- if (prop == "COMPILE_OPTIONS")
- {
- if (!value)
- {
- this->StateSnapshot.GetDirectory().ClearCompileOptions();
- return;
- }
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().SetCompileOptions(value, lfbt);
- return;
- }
- if (prop == "COMPILE_DEFINITIONS")
- {
- if (!value)
- {
- this->StateSnapshot.GetDirectory().ClearCompileDefinitions();
- return;
- }
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().SetCompileDefinitions(value, lfbt);
- return;
- }
-
- this->Properties.SetProperty(prop, value);
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->StateSnapshot.GetDirectory().SetProperty(prop, value, lfbt);
}
void cmMakefile::AppendProperty(const std::string& prop,
const char* value,
bool asString)
{
- if (prop == "INCLUDE_DIRECTORIES")
- {
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().AppendIncludeDirectoriesEntry(value,
- lfbt);
- return;
- }
- if (prop == "COMPILE_OPTIONS")
- {
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().AppendCompileOptionsEntry(value, lfbt);
- return;
- }
- if (prop == "COMPILE_DEFINITIONS")
- {
- cmListFileBacktrace lfbt = this->GetBacktrace();
- this->StateSnapshot.GetDirectory().AppendCompileDefinitionsEntry(value,
- lfbt);
- return;
- }
-
- this->Properties.AppendProperty(prop, value, asString);
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ this->StateSnapshot.GetDirectory().AppendProperty(prop, value,
+ asString, lfbt);
}
const char *cmMakefile::GetProperty(const std::string& prop) const
{
- const bool chain = this->GetState()->
- IsPropertyChained(prop, cmProperty::DIRECTORY);
- return this->GetProperty(prop, chain);
+ return this->StateSnapshot.GetDirectory().GetProperty(prop);
}
const char *cmMakefile::GetProperty(const std::string& prop,
bool chain) const
{
- // watch for specific properties
- static std::string output;
- output = "";
- if (prop == "PARENT_DIRECTORY")
- {
- cmState::Snapshot parent =
- this->StateSnapshot.GetBuildsystemDirectoryParent();
- if(parent.IsValid())
- {
- return parent.GetDirectory().GetCurrentSource();
- }
- return "";
- }
- else if (prop == "LISTFILE_STACK")
- {
- std::vector<std::string> listFiles;
- cmState::Snapshot snp = this->StateSnapshot;
- while (snp.IsValid())
- {
- listFiles.push_back(snp.GetExecutionListFile());
- snp = snp.GetCallStackParent();
- }
- std::reverse(listFiles.begin(), listFiles.end());
- output = cmJoin(listFiles, ";");
- return output.c_str();
- }
- else if ( prop == "CACHE_VARIABLES" )
- {
- output = cmJoin(this->GetState()->GetCacheEntryKeys(), ";");
- return output.c_str();
- }
- else if (prop == "VARIABLES")
- {
- output = cmJoin(this->GetDefinitions(), ";");
- return output.c_str();
- }
- else if (prop == "INCLUDE_DIRECTORIES")
- {
- output = cmJoin(this->StateSnapshot.GetDirectory()
- .GetIncludeDirectoriesEntries(), ";");
- return output.c_str();
- }
- else if (prop == "COMPILE_OPTIONS")
- {
- output = cmJoin(this->StateSnapshot.GetDirectory()
- .GetCompileOptionsEntries(), ";");
- return output.c_str();
- }
- else if (prop == "COMPILE_DEFINITIONS")
- {
- output = cmJoin(this->StateSnapshot.GetDirectory()
- .GetCompileDefinitionsEntries(), ";");
- return output.c_str();
- }
-
- const char *retVal = this->Properties.GetPropertyValue(prop);
- if (!retVal && chain)
- {
- if(this->LocalGenerator->GetParent())
- {
- return this->LocalGenerator->GetParent()->GetMakefile()->
- GetProperty(prop, chain);
- }
- return this->GetState()->GetGlobalProperty(prop);
- }
-
- return retVal;
+ return this->StateSnapshot.GetDirectory().GetProperty(prop, chain);
}
bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
@@ -4306,14 +4096,7 @@ bool cmMakefile::GetPropertyAsBool(const std::string& prop) const
std::vector<std::string> cmMakefile::GetPropertyKeys() const
{
- std::vector<std::string> keys;
- keys.reserve(this->Properties.size());
- for(cmPropertyMap::const_iterator it = this->Properties.begin();
- it != this->Properties.end(); ++it)
- {
- keys.push_back(it->first);
- }
- return keys;
+ return this->StateSnapshot.GetDirectory().GetPropertyKeys();
}
cmTarget* cmMakefile::FindTarget(const std::string& name,
@@ -4422,8 +4205,17 @@ std::string cmMakefile::FormatListFileStack() const
void cmMakefile::PushScope()
{
- this->Internal->PushDefinitions();
-
+ std::string commandName;
+ long line = 0;
+ if (!this->ContextStack.empty())
+ {
+ commandName = this->ContextStack.back()->Name;
+ line = this->ContextStack.back()->Line;
+ }
+ this->StateSnapshot = this->GetState()->CreateVariableScopeSnapshot(
+ this->StateSnapshot,
+ commandName,
+ line);
this->PushLoopBlockBarrier();
#if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -4441,7 +4233,9 @@ void cmMakefile::PopScope()
this->CheckForUnusedVariables();
- this->Internal->PopDefinitions();
+ this->StateSnapshot =
+ this->GetState()->Pop(this->StateSnapshot);
+ assert(this->StateSnapshot.IsValid());
}
void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
@@ -4451,7 +4245,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
return;
}
- if (!this->Internal->RaiseScope(var, varDef, this))
+ if (!this->StateSnapshot.RaiseScope(var, varDef))
{
std::ostringstream m;
m << "Cannot set \"" << var << "\": current scope has no parent.";
@@ -4864,9 +4658,10 @@ bool cmMakefile::SetPolicyVersion(const char *version)
}
//----------------------------------------------------------------------------
-bool cmMakefile::HasCMP0054AlreadyBeenReported() const
+bool cmMakefile::HasCMP0054AlreadyBeenReported(
+ cmListFileContext const& context) const
{
- return !this->CMP0054ReportedIds.insert(this->GetExecutionContext()).second;
+ return !this->CMP0054ReportedIds.insert(context).second;
}
//----------------------------------------------------------------------------