Merge topic 'clean-up-cmMakefile'
b9f99155 cmMakefile: Remove VarUsageStack. 2b09d9f3 cmMakefile: Remove VarInitStack. 528d6802 cmMakefile: Use more suitable method name to log var usage. 9118b53b cmMakefile: Move internal method to private scope. f58c3774 cmMakefile: Mark definitions explicitly erased, even at top level. ea7b962b cmMakefile: Raise variable in scope explicitly when needed. c8cb6688 cmMakefile: Use early return to reduce nested code. bdd1aa91 cmMakefile: Don't use else after return. c42f0e2b cmMakefile: Remove redundant conditions. caff8e5a cmCTest: Remove unimplemented method. bb1e8c3a cmMakefile: Remove Print() debugging facilities. 1363bff8 cmMakefile: Remove duplicate variable initialization. 5b7ff35c cmMakefile: Don't expect the VarStack iterator to support size(). 390bc324 cmMakefile: Remove redundant condition. 8ab1cce7 cmMakefile: Rename method to something more appropriate. 2dd5d42f cmMakefile: Make the public ReadListFile method take one param. ...
This commit is contained in:
commit
f05d9308c9
@ -18,12 +18,13 @@ cmDefinitions::Def cmDefinitions::NoDef;
|
|||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDefinitions::Def const& cmDefinitions::GetInternal(
|
cmDefinitions::Def const& cmDefinitions::GetInternal(
|
||||||
const std::string& key, StackIter begin, StackIter end)
|
const std::string& key, StackIter begin, StackIter end, bool raise)
|
||||||
{
|
{
|
||||||
assert(begin != end);
|
assert(begin != end);
|
||||||
MapType::const_iterator i = begin->Map.find(key);
|
MapType::iterator i = begin->Map.find(key);
|
||||||
if (i != begin->Map.end())
|
if (i != begin->Map.end())
|
||||||
{
|
{
|
||||||
|
i->second.Used = true;
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
StackIter it = begin;
|
StackIter it = begin;
|
||||||
@ -32,7 +33,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(
|
|||||||
{
|
{
|
||||||
return cmDefinitions::NoDef;
|
return cmDefinitions::NoDef;
|
||||||
}
|
}
|
||||||
Def const& def = cmDefinitions::GetInternal(key, it, end);
|
Def const& def = cmDefinitions::GetInternal(key, it, end, raise);
|
||||||
|
if (!raise)
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
return begin->Map.insert(MapType::value_type(key, def)).first->second;
|
return begin->Map.insert(MapType::value_type(key, def)).first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +45,30 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(
|
|||||||
const char* cmDefinitions::Get(const std::string& key,
|
const char* cmDefinitions::Get(const std::string& key,
|
||||||
StackIter begin, StackIter end)
|
StackIter begin, StackIter end)
|
||||||
{
|
{
|
||||||
Def const& def = cmDefinitions::GetInternal(key, begin, end);
|
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
|
||||||
return def.Exists? def.c_str() : 0;
|
return def.Exists? def.c_str() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmDefinitions::Raise(const std::string& key,
|
||||||
|
StackIter begin, StackIter end)
|
||||||
|
{
|
||||||
|
cmDefinitions::GetInternal(key, begin, end, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmDefinitions::HasKey(const std::string& key,
|
||||||
|
StackConstIter begin, StackConstIter end)
|
||||||
|
{
|
||||||
|
for (StackConstIter it = begin; it != end; ++it)
|
||||||
|
{
|
||||||
|
MapType::const_iterator i = it->Map.find(key);
|
||||||
|
if (i != it->Map.end())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmDefinitions::Set(const std::string& key, const char* value)
|
void cmDefinitions::Set(const std::string& key, const char* value)
|
||||||
{
|
{
|
||||||
@ -51,13 +76,8 @@ void cmDefinitions::Set(const std::string& key, const char* value)
|
|||||||
this->Map[key] = def;
|
this->Map[key] = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmDefinitions::Erase(const std::string& key)
|
|
||||||
{
|
|
||||||
this->Map.erase(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::vector<std::string> cmDefinitions::LocalKeys() const
|
std::vector<std::string> cmDefinitions::UnusedKeys() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
keys.reserve(this->Map.size());
|
keys.reserve(this->Map.size());
|
||||||
@ -65,7 +85,7 @@ std::vector<std::string> cmDefinitions::LocalKeys() const
|
|||||||
for(MapType::const_iterator mi = this->Map.begin();
|
for(MapType::const_iterator mi = this->Map.begin();
|
||||||
mi != this->Map.end(); ++mi)
|
mi != this->Map.end(); ++mi)
|
||||||
{
|
{
|
||||||
if (mi->second.Exists)
|
if (!mi->second.Used)
|
||||||
{
|
{
|
||||||
keys.push_back(mi->first);
|
keys.push_back(mi->first);
|
||||||
}
|
}
|
||||||
|
@ -35,18 +35,18 @@ class cmDefinitions
|
|||||||
typedef std::list<cmDefinitions>::reverse_iterator StackIter;
|
typedef std::list<cmDefinitions>::reverse_iterator StackIter;
|
||||||
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
|
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
|
||||||
public:
|
public:
|
||||||
/** Get the value associated with a key; null if none.
|
|
||||||
Store the result locally if it came from a parent. */
|
|
||||||
static const char* Get(const std::string& key,
|
static const char* Get(const std::string& key,
|
||||||
StackIter begin, StackIter end);
|
StackIter begin, StackIter end);
|
||||||
|
|
||||||
|
static void Raise(const std::string& key, StackIter begin, StackIter end);
|
||||||
|
|
||||||
|
static bool HasKey(const std::string& key,
|
||||||
|
StackConstIter begin, StackConstIter end);
|
||||||
|
|
||||||
/** Set (or unset if null) a value associated with a key. */
|
/** Set (or unset if null) a value associated with a key. */
|
||||||
void Set(const std::string& key, const char* value);
|
void Set(const std::string& key, const char* value);
|
||||||
|
|
||||||
void Erase(const std::string& key);
|
std::vector<std::string> UnusedKeys() const;
|
||||||
|
|
||||||
/** Get the set of all local keys. */
|
|
||||||
std::vector<std::string> LocalKeys() const;
|
|
||||||
|
|
||||||
static std::vector<std::string> ClosureKeys(StackConstIter begin,
|
static std::vector<std::string> ClosureKeys(StackConstIter begin,
|
||||||
StackConstIter end);
|
StackConstIter end);
|
||||||
@ -60,11 +60,16 @@ private:
|
|||||||
private:
|
private:
|
||||||
typedef std::string std_string;
|
typedef std::string std_string;
|
||||||
public:
|
public:
|
||||||
Def(): std_string(), Exists(false) {}
|
Def(): std_string(), Exists(false), Used(false) {}
|
||||||
Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
|
Def(const char* v)
|
||||||
Def(const std_string& v): std_string(v), Exists(true) {}
|
: std_string(v ? v : ""),
|
||||||
Def(Def const& d): std_string(d), Exists(d.Exists) {}
|
Exists(v ? true : false),
|
||||||
|
Used(false)
|
||||||
|
{}
|
||||||
|
Def(const std_string& v): std_string(v), Exists(true), Used(false) {}
|
||||||
|
Def(Def const& d): std_string(d), Exists(d.Exists), Used(d.Used) {}
|
||||||
bool Exists;
|
bool Exists;
|
||||||
|
bool Used;
|
||||||
};
|
};
|
||||||
static Def NoDef;
|
static Def NoDef;
|
||||||
|
|
||||||
@ -80,7 +85,7 @@ private:
|
|||||||
MapType Map;
|
MapType Map;
|
||||||
|
|
||||||
static Def const& GetInternal(const std::string& key,
|
static Def const& GetInternal(const std::string& key,
|
||||||
StackIter begin, StackIter end);
|
StackIter begin, StackIter end, bool raise);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -182,7 +182,9 @@ void cmExtraQbsGenerator::AppendSources(cmGeneratedFileStream &fout,
|
|||||||
std::vector<cmSourceFile *> genSources;
|
std::vector<cmSourceFile *> genSources;
|
||||||
std::vector<cmSourceFile *>::const_iterator itr = sources.begin();
|
std::vector<cmSourceFile *>::const_iterator itr = sources.begin();
|
||||||
fout << "\t\t\tfiles: [\n"
|
fout << "\t\t\tfiles: [\n"
|
||||||
<< "\t\t\t\t\"" << t.GetMakefile()->GetCurrentListFile() << "\",\n";
|
<< "\t\t\t\t\""
|
||||||
|
<< t.GetMakefile()->GetDefinition("CMAKE_CURRENT_LIST_FILE")
|
||||||
|
<< "\",\n";
|
||||||
for (; itr != sources.end(); ++itr)
|
for (; itr != sources.end(); ++itr)
|
||||||
{
|
{
|
||||||
if (!(*itr)->GetPropertyAsBool("GENERATED"))
|
if (!(*itr)->GetPropertyAsBool("GENERATED"))
|
||||||
|
@ -305,8 +305,8 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
|
|||||||
cmGlobalNinjaGenerator::WriteDivider(os);
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
||||||
os
|
os
|
||||||
<< "# Write statements declared in CMakeLists.txt:" << std::endl
|
<< "# Write statements declared in CMakeLists.txt:" << std::endl
|
||||||
<< "# " << this->Makefile->GetCurrentListFile() << std::endl
|
<< "# "
|
||||||
;
|
<< this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE") << std::endl;
|
||||||
if(this->IsRootMakefile())
|
if(this->IsRootMakefile())
|
||||||
os << "# Which is the root file." << std::endl;
|
os << "# Which is the root file." << std::endl;
|
||||||
cmGlobalNinjaGenerator::WriteDivider(os);
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include <cmsys/FStream.hxx>
|
#include <cmsys/FStream.hxx>
|
||||||
#include <cmsys/auto_ptr.hxx>
|
#include <cmsys/auto_ptr.hxx>
|
||||||
|
|
||||||
#include <stack>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <ctype.h> // for isspace
|
#include <ctype.h> // for isspace
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -47,8 +46,6 @@ class cmMakefile::Internals
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::list<cmDefinitions> VarStack;
|
std::list<cmDefinitions> VarStack;
|
||||||
std::stack<std::set<std::string> > VarInitStack;
|
|
||||||
std::stack<std::set<std::string> > VarUsageStack;
|
|
||||||
bool IsSourceFileTryCompile;
|
bool IsSourceFileTryCompile;
|
||||||
|
|
||||||
void PushDefinitions()
|
void PushDefinitions()
|
||||||
@ -69,6 +66,12 @@ public:
|
|||||||
this->VarStack.rend());
|
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)
|
void SetDefinition(std::string const& name, std::string const& value)
|
||||||
{
|
{
|
||||||
this->VarStack.back().Set(name, value.c_str());
|
this->VarStack.back().Set(name, value.c_str());
|
||||||
@ -76,20 +79,12 @@ public:
|
|||||||
|
|
||||||
void RemoveDefinition(std::string const& name)
|
void RemoveDefinition(std::string const& name)
|
||||||
{
|
{
|
||||||
if (this->VarStack.size() > 1)
|
this->VarStack.back().Set(name, 0);
|
||||||
{
|
|
||||||
// In lower scopes we store keys, defined or not.
|
|
||||||
this->VarStack.back().Set(name, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->VarStack.back().Erase(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> LocalKeys() const
|
std::vector<std::string> UnusedKeys() const
|
||||||
{
|
{
|
||||||
return this->VarStack.back().LocalKeys();
|
return this->VarStack.back().UnusedKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ClosureKeys() const
|
std::vector<std::string> ClosureKeys() const
|
||||||
@ -105,35 +100,32 @@ public:
|
|||||||
|
|
||||||
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
|
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
|
||||||
{
|
{
|
||||||
assert(this->VarStack.size() > 0);
|
|
||||||
|
|
||||||
std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
|
std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
|
||||||
|
assert(it != this->VarStack.rend());
|
||||||
++it;
|
++it;
|
||||||
if(it == this->VarStack.rend())
|
if(it == this->VarStack.rend())
|
||||||
{
|
{
|
||||||
if(cmLocalGenerator* plg = mf->GetLocalGenerator()->GetParent())
|
cmLocalGenerator* plg = mf->GetLocalGenerator()->GetParent();
|
||||||
{
|
if(!plg)
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return false;
|
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.
|
// First localize the definition in the current scope.
|
||||||
this->GetDefinition(var);
|
cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
|
||||||
|
|
||||||
// Now update the definition in the parent scope.
|
// Now update the definition in the parent scope.
|
||||||
it->Set(var, varDef);
|
it->Set(var, varDef);
|
||||||
@ -148,13 +140,11 @@ cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
|
|||||||
StateSnapshot(localGenerator->GetStateSnapshot())
|
StateSnapshot(localGenerator->GetStateSnapshot())
|
||||||
{
|
{
|
||||||
this->Internal->PushDefinitions();
|
this->Internal->PushDefinitions();
|
||||||
this->Internal->VarInitStack.push(std::set<std::string>());
|
|
||||||
this->Internal->VarUsageStack.push(std::set<std::string>());
|
|
||||||
this->Internal->IsSourceFileTryCompile = false;
|
this->Internal->IsSourceFileTryCompile = false;
|
||||||
|
|
||||||
// Initialize these first since AddDefaultDefinitions calls AddDefinition
|
// Initialize these first since AddDefaultDefinitions calls AddDefinition
|
||||||
this->WarnUnused = false;
|
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
|
||||||
this->CheckSystemVars = false;
|
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
|
||||||
|
|
||||||
this->GeneratingBuildSystem = false;
|
this->GeneratingBuildSystem = false;
|
||||||
this->SuppressWatches = false;
|
this->SuppressWatches = false;
|
||||||
@ -224,24 +214,16 @@ cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->Properties.SetCMakeInstance(this->GetCMakeInstance());
|
this->Properties.SetCMakeInstance(this->GetCMakeInstance());
|
||||||
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
|
|
||||||
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const char* dir = this->GetCMakeInstance()->GetHomeDirectory();
|
const char* dir = this->GetCMakeInstance()->GetHomeDirectory();
|
||||||
this->AddDefinition("CMAKE_SOURCE_DIR", dir);
|
this->AddDefinition("CMAKE_SOURCE_DIR", dir);
|
||||||
if ( !this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR") )
|
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", dir);
|
||||||
{
|
|
||||||
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", dir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char* dir = this->GetCMakeInstance()->GetHomeOutputDirectory();
|
const char* dir = this->GetCMakeInstance()->GetHomeOutputDirectory();
|
||||||
this->AddDefinition("CMAKE_BINARY_DIR", dir);
|
this->AddDefinition("CMAKE_BINARY_DIR", dir);
|
||||||
if ( !this->GetDefinition("CMAKE_CURRENT_BINARY_DIR") )
|
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", dir);
|
||||||
{
|
|
||||||
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", dir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,59 +244,6 @@ cmMakefile::~cmMakefile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::PrintStringVector(const char* s,
|
|
||||||
const std::vector<std::string>& v) const
|
|
||||||
{
|
|
||||||
std::cout << s << ": ( \n" << cmWrap('"', v, '"', " ") << ")\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmMakefile
|
|
||||||
::PrintStringVector(const char* s,
|
|
||||||
const std::vector<std::pair<std::string, bool> >& v) const
|
|
||||||
{
|
|
||||||
std::cout << s << ": ( \n";
|
|
||||||
for(std::vector<std::pair<std::string, bool> >::const_iterator i
|
|
||||||
= v.begin(); i != v.end(); ++i)
|
|
||||||
{
|
|
||||||
std::cout << i->first << " " << i->second;
|
|
||||||
}
|
|
||||||
std::cout << " )\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// call print on all the classes in the makefile
|
|
||||||
void cmMakefile::Print() const
|
|
||||||
{
|
|
||||||
// print the class lists
|
|
||||||
std::cout << "classes:\n";
|
|
||||||
|
|
||||||
std::cout << " this->Targets: ";
|
|
||||||
for (cmTargets::iterator l = this->Targets.begin();
|
|
||||||
l != this->Targets.end(); l++)
|
|
||||||
{
|
|
||||||
std::cout << l->first << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << " this->StartOutputDirectory; " <<
|
|
||||||
this->GetCurrentBinaryDirectory() << std::endl;
|
|
||||||
std::cout << " this->HomeOutputDirectory; " <<
|
|
||||||
this->GetHomeOutputDirectory() << std::endl;
|
|
||||||
std::cout << " this->cmStartDirectory; " <<
|
|
||||||
this->GetCurrentSourceDirectory() << std::endl;
|
|
||||||
std::cout << " this->cmHomeDirectory; " <<
|
|
||||||
this->GetHomeDirectory() << std::endl;
|
|
||||||
std::cout << " this->ProjectName; "
|
|
||||||
<< this->ProjectName << std::endl;
|
|
||||||
this->PrintStringVector("this->LinkDirectories", this->LinkDirectories);
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
||||||
for( std::vector<cmSourceGroup>::const_iterator i =
|
|
||||||
this->SourceGroups.begin(); i != this->SourceGroups.end(); ++i)
|
|
||||||
{
|
|
||||||
std::cout << "Source Group: " << i->GetName() << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmMakefile::IssueMessage(cmake::MessageType t,
|
void cmMakefile::IssueMessage(cmake::MessageType t,
|
||||||
std::string const& text) const
|
std::string const& text) const
|
||||||
@ -601,7 +530,6 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
|
|||||||
bool cmMakefile::ProcessBuildsystemFile(const char* listfile)
|
bool cmMakefile::ProcessBuildsystemFile(const char* listfile)
|
||||||
{
|
{
|
||||||
this->AddDefinition("CMAKE_PARENT_LIST_FILE", listfile);
|
this->AddDefinition("CMAKE_PARENT_LIST_FILE", listfile);
|
||||||
this->cmCurrentListFile = listfile;
|
|
||||||
std::string curSrc = this->GetCurrentSourceDirectory();
|
std::string curSrc = this->GetCurrentSourceDirectory();
|
||||||
return this->ReadListFile(listfile, true,
|
return this->ReadListFile(listfile, true,
|
||||||
curSrc == this->GetHomeDirectory());
|
curSrc == this->GetHomeDirectory());
|
||||||
@ -609,17 +537,16 @@ bool cmMakefile::ProcessBuildsystemFile(const char* listfile)
|
|||||||
|
|
||||||
bool cmMakefile::ReadDependentFile(const char* listfile, bool noPolicyScope)
|
bool cmMakefile::ReadDependentFile(const char* listfile, bool noPolicyScope)
|
||||||
{
|
{
|
||||||
this->AddDefinition("CMAKE_PARENT_LIST_FILE", this->GetCurrentListFile());
|
this->AddDefinition("CMAKE_PARENT_LIST_FILE",
|
||||||
this->cmCurrentListFile =
|
this->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
|
||||||
cmSystemTools::CollapseFullPath(listfile,
|
return this->ReadListFile(listfile, noPolicyScope, false);
|
||||||
this->GetCurrentSourceDirectory());
|
}
|
||||||
return this->ReadListFile(this->cmCurrentListFile.c_str(),
|
|
||||||
noPolicyScope);
|
bool cmMakefile::ReadListFile(const char* listfile)
|
||||||
|
{
|
||||||
|
return this->ReadListFile(listfile, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
// Parse the given CMakeLists.txt file executing all commands
|
|
||||||
//
|
|
||||||
bool cmMakefile::ReadListFile(const char* listfile,
|
bool cmMakefile::ReadListFile(const char* listfile,
|
||||||
bool noPolicyScope,
|
bool noPolicyScope,
|
||||||
bool requireProjectCommand)
|
bool requireProjectCommand)
|
||||||
@ -658,7 +585,6 @@ bool cmMakefile::ReadListFile(const char* listfile,
|
|||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
// Check for unused variables
|
|
||||||
this->CheckForUnusedVariables();
|
this->CheckForUnusedVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1793,14 +1719,11 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Internal->SetDefinition(name, value);
|
if (this->VariableInitialized(name))
|
||||||
if (!this->Internal->VarUsageStack.empty() &&
|
|
||||||
this->VariableInitialized(name))
|
|
||||||
{
|
{
|
||||||
this->CheckForUnused("changing definition", name);
|
this->LogUnused("changing definition", name);
|
||||||
this->Internal->VarUsageStack.top().erase(name);
|
|
||||||
}
|
}
|
||||||
this->Internal->VarInitStack.top().insert(name);
|
this->Internal->SetDefinition(name, value);
|
||||||
|
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
cmVariableWatch* vv = this->GetVariableWatch();
|
cmVariableWatch* vv = this->GetVariableWatch();
|
||||||
@ -1869,14 +1792,11 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
|
|||||||
|
|
||||||
void cmMakefile::AddDefinition(const std::string& name, bool value)
|
void cmMakefile::AddDefinition(const std::string& name, bool value)
|
||||||
{
|
{
|
||||||
this->Internal->SetDefinition(name, value ? "ON" : "OFF");
|
if (this->VariableInitialized(name))
|
||||||
if (!this->Internal->VarUsageStack.empty() &&
|
|
||||||
this->VariableInitialized(name))
|
|
||||||
{
|
{
|
||||||
this->CheckForUnused("changing definition", name);
|
this->LogUnused("changing definition", name);
|
||||||
this->Internal->VarUsageStack.top().erase(name);
|
|
||||||
}
|
}
|
||||||
this->Internal->VarInitStack.top().insert(name);
|
this->Internal->SetDefinition(name, value ? "ON" : "OFF");
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
cmVariableWatch* vv = this->GetVariableWatch();
|
cmVariableWatch* vv = this->GetVariableWatch();
|
||||||
if ( vv )
|
if ( vv )
|
||||||
@ -1893,43 +1813,28 @@ void cmMakefile::CheckForUnusedVariables() const
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const std::vector<std::string>& locals = this->Internal->LocalKeys();
|
const std::vector<std::string>& unused = this->Internal->UnusedKeys();
|
||||||
std::vector<std::string>::const_iterator it = locals.begin();
|
std::vector<std::string>::const_iterator it = unused.begin();
|
||||||
for (; it != locals.end(); ++it)
|
for (; it != unused.end(); ++it)
|
||||||
{
|
{
|
||||||
this->CheckForUnused("out of scope", *it);
|
this->LogUnused("out of scope", *it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::MarkVariableAsUsed(const std::string& var)
|
void cmMakefile::MarkVariableAsUsed(const std::string& var)
|
||||||
{
|
{
|
||||||
this->Internal->VarUsageStack.top().insert(var);
|
this->Internal->GetDefinition(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmMakefile::VariableInitialized(const std::string& var) const
|
bool cmMakefile::VariableInitialized(const std::string& var) const
|
||||||
{
|
{
|
||||||
if(this->Internal->VarInitStack.top().find(var) !=
|
return this->Internal->IsInitialized(var);
|
||||||
this->Internal->VarInitStack.top().end())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmMakefile::VariableUsed(const std::string& var) const
|
void cmMakefile::LogUnused(const char* reason,
|
||||||
{
|
|
||||||
if(this->Internal->VarUsageStack.top().find(var) !=
|
|
||||||
this->Internal->VarUsageStack.top().end())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmMakefile::CheckForUnused(const char* reason,
|
|
||||||
const std::string& name) const
|
const std::string& name) const
|
||||||
{
|
{
|
||||||
if (this->WarnUnused && !this->VariableUsed(name))
|
if (this->WarnUnused)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
cmListFileBacktrace bt(this->GetLocalGenerator());
|
cmListFileBacktrace bt(this->GetLocalGenerator());
|
||||||
@ -1967,14 +1872,11 @@ void cmMakefile::CheckForUnused(const char* reason,
|
|||||||
|
|
||||||
void cmMakefile::RemoveDefinition(const std::string& name)
|
void cmMakefile::RemoveDefinition(const std::string& name)
|
||||||
{
|
{
|
||||||
this->Internal->RemoveDefinition(name);
|
if (this->VariableInitialized(name))
|
||||||
if (!this->Internal->VarUsageStack.empty() &&
|
|
||||||
this->VariableInitialized(name))
|
|
||||||
{
|
{
|
||||||
this->CheckForUnused("unsetting", name);
|
this->LogUnused("unsetting", name);
|
||||||
this->Internal->VarUsageStack.top().erase(name);
|
|
||||||
}
|
}
|
||||||
this->Internal->VarInitStack.top().insert(name);
|
this->Internal->RemoveDefinition(name);
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
cmVariableWatch* vv = this->GetVariableWatch();
|
cmVariableWatch* vv = this->GetVariableWatch();
|
||||||
if ( vv )
|
if ( vv )
|
||||||
@ -2441,7 +2343,6 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
|
|||||||
bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
||||||
{
|
{
|
||||||
const char* def = this->Internal->GetDefinition(name);
|
const char* def = this->Internal->GetDefinition(name);
|
||||||
this->Internal->VarUsageStack.top().insert(name);
|
|
||||||
if(!def)
|
if(!def)
|
||||||
{
|
{
|
||||||
def = this->GetState()->GetInitializedCacheValue(name);
|
def = this->GetState()->GetInitializedCacheValue(name);
|
||||||
@ -2462,10 +2363,6 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
|||||||
|
|
||||||
const char* cmMakefile::GetDefinition(const std::string& name) const
|
const char* cmMakefile::GetDefinition(const std::string& name) const
|
||||||
{
|
{
|
||||||
if (this->WarnUnused)
|
|
||||||
{
|
|
||||||
this->Internal->VarUsageStack.top().insert(name);
|
|
||||||
}
|
|
||||||
const char* def = this->Internal->GetDefinition(name);
|
const char* def = this->Internal->GetDefinition(name);
|
||||||
if(!def)
|
if(!def)
|
||||||
{
|
{
|
||||||
@ -4364,7 +4261,7 @@ void cmMakefile::AddCMakeDependFilesFromUser()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmMakefile::GetListFileStack() const
|
std::string cmMakefile::FormatListFileStack() const
|
||||||
{
|
{
|
||||||
std::ostringstream tmp;
|
std::ostringstream tmp;
|
||||||
size_t depth = this->ListFileStack.size();
|
size_t depth = this->ListFileStack.size();
|
||||||
@ -4393,10 +4290,6 @@ std::string cmMakefile::GetListFileStack() const
|
|||||||
void cmMakefile::PushScope()
|
void cmMakefile::PushScope()
|
||||||
{
|
{
|
||||||
this->Internal->PushDefinitions();
|
this->Internal->PushDefinitions();
|
||||||
const std::set<std::string>& init = this->Internal->VarInitStack.top();
|
|
||||||
const std::set<std::string>& usage = this->Internal->VarUsageStack.top();
|
|
||||||
this->Internal->VarInitStack.push(init);
|
|
||||||
this->Internal->VarUsageStack.push(usage);
|
|
||||||
|
|
||||||
this->PushLoopBlockBarrier();
|
this->PushLoopBlockBarrier();
|
||||||
|
|
||||||
@ -4413,31 +4306,9 @@ void cmMakefile::PopScope()
|
|||||||
|
|
||||||
this->PopLoopBlockBarrier();
|
this->PopLoopBlockBarrier();
|
||||||
|
|
||||||
std::set<std::string> init = this->Internal->VarInitStack.top();
|
this->CheckForUnusedVariables();
|
||||||
std::set<std::string> usage = this->Internal->VarUsageStack.top();
|
|
||||||
const std::vector<std::string>& locals = this->Internal->LocalKeys();
|
|
||||||
// Remove initialization and usage information for variables in the local
|
|
||||||
// scope.
|
|
||||||
std::vector<std::string>::const_iterator it = locals.begin();
|
|
||||||
for (; it != locals.end(); ++it)
|
|
||||||
{
|
|
||||||
init.erase(*it);
|
|
||||||
if (!this->VariableUsed(*it))
|
|
||||||
{
|
|
||||||
this->CheckForUnused("out of scope", *it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
usage.erase(*it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->Internal->PopDefinitions();
|
this->Internal->PopDefinitions();
|
||||||
this->Internal->VarInitStack.pop();
|
|
||||||
this->Internal->VarUsageStack.pop();
|
|
||||||
// Push initialization and usage up to the parent scope.
|
|
||||||
this->Internal->VarInitStack.top().insert(init.begin(), init.end());
|
|
||||||
this->Internal->VarUsageStack.top().insert(usage.begin(), usage.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
||||||
|
@ -65,14 +65,10 @@ class cmMakefile
|
|||||||
class Internals;
|
class Internals;
|
||||||
cmsys::auto_ptr<Internals> Internal;
|
cmsys::auto_ptr<Internals> Internal;
|
||||||
public:
|
public:
|
||||||
/* Check for unused variables in this scope */
|
|
||||||
void CheckForUnusedVariables() const;
|
|
||||||
/* Mark a variable as used */
|
/* Mark a variable as used */
|
||||||
void MarkVariableAsUsed(const std::string& var);
|
void MarkVariableAsUsed(const std::string& var);
|
||||||
/* return true if a variable has been initialized */
|
/* return true if a variable has been initialized */
|
||||||
bool VariableInitialized(const std::string& ) const;
|
bool VariableInitialized(const std::string& ) const;
|
||||||
/* return true if a variable has been used */
|
|
||||||
bool VariableUsed(const std::string& ) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an empty makefile.
|
* Construct an empty makefile.
|
||||||
@ -84,12 +80,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
~cmMakefile();
|
~cmMakefile();
|
||||||
|
|
||||||
/**
|
bool ReadListFile(const char* listfile);
|
||||||
* Read and parse a CMakeLists.txt file.
|
|
||||||
*/
|
|
||||||
bool ReadListFile(const char* listfile,
|
|
||||||
bool noPolicyScope = true,
|
|
||||||
bool requireProjectCommand = false);
|
|
||||||
|
|
||||||
bool ReadDependentFile(const char* listfile, bool noPolicyScope = true);
|
bool ReadDependentFile(const char* listfile, bool noPolicyScope = true);
|
||||||
|
|
||||||
@ -162,11 +153,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void FinalPass();
|
void FinalPass();
|
||||||
|
|
||||||
/**
|
|
||||||
* Print the object state to std::cout.
|
|
||||||
*/
|
|
||||||
void Print() const;
|
|
||||||
|
|
||||||
/** Add a custom command to the build. */
|
/** Add a custom command to the build. */
|
||||||
void AddCustomCommandToTarget(const std::string& target,
|
void AddCustomCommandToTarget(const std::string& target,
|
||||||
const std::vector<std::string>& byproducts,
|
const std::vector<std::string>& byproducts,
|
||||||
@ -418,14 +404,6 @@ public:
|
|||||||
void SetCurrentBinaryDirectory(const std::string& dir);
|
void SetCurrentBinaryDirectory(const std::string& dir);
|
||||||
const char* GetCurrentBinaryDirectory() const;
|
const char* GetCurrentBinaryDirectory() const;
|
||||||
|
|
||||||
/* Get the current CMakeLists.txt file that is being processed. This
|
|
||||||
* is just used in order to be able to 'branch' from one file to a second
|
|
||||||
* transparently */
|
|
||||||
const char* GetCurrentListFile() const
|
|
||||||
{
|
|
||||||
return this->cmCurrentListFile.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -588,7 +566,7 @@ public:
|
|||||||
{ this->ListFiles.push_back(file);}
|
{ this->ListFiles.push_back(file);}
|
||||||
void AddCMakeDependFilesFromUser();
|
void AddCMakeDependFilesFromUser();
|
||||||
|
|
||||||
std::string GetListFileStack() const;
|
std::string FormatListFileStack() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current context backtrace.
|
* Get the current context backtrace.
|
||||||
@ -843,9 +821,7 @@ protected:
|
|||||||
void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
|
void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
|
||||||
|
|
||||||
// Check for a an unused variable
|
// Check for a an unused variable
|
||||||
void CheckForUnused(const char* reason, const std::string& name) const;
|
void LogUnused(const char* reason, const std::string& name) const;
|
||||||
|
|
||||||
std::string cmCurrentListFile;
|
|
||||||
|
|
||||||
std::string ProjectName; // project name
|
std::string ProjectName; // project name
|
||||||
|
|
||||||
@ -912,6 +888,10 @@ private:
|
|||||||
|
|
||||||
cmState::Snapshot StateSnapshot;
|
cmState::Snapshot StateSnapshot;
|
||||||
|
|
||||||
|
bool ReadListFile(const char* listfile,
|
||||||
|
bool noPolicyScope,
|
||||||
|
bool requireProjectCommand);
|
||||||
|
|
||||||
bool ReadListFileInternal(const char* filenametoread,
|
bool ReadListFileInternal(const char* filenametoread,
|
||||||
bool noPolicyScope,
|
bool noPolicyScope,
|
||||||
bool requireProjectCommand);
|
bool requireProjectCommand);
|
||||||
@ -923,10 +903,6 @@ private:
|
|||||||
|
|
||||||
friend class cmMakeDepend; // make depend needs direct access
|
friend class cmMakeDepend; // make depend needs direct access
|
||||||
// to the Sources array
|
// to the Sources array
|
||||||
void PrintStringVector(const char* s, const
|
|
||||||
std::vector<std::pair<std::string, bool> >& v) const;
|
|
||||||
void PrintStringVector(const char* s,
|
|
||||||
const std::vector<std::string>& v) const;
|
|
||||||
|
|
||||||
void AddDefaultDefinitions();
|
void AddDefaultDefinitions();
|
||||||
typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
|
typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
|
||||||
@ -1062,6 +1038,8 @@ private:
|
|||||||
bool HaveCxxStandardAvailable(cmTarget const* target,
|
bool HaveCxxStandardAvailable(cmTarget const* target,
|
||||||
const std::string& feature) const;
|
const std::string& feature) const;
|
||||||
|
|
||||||
|
void CheckForUnusedVariables() const;
|
||||||
|
|
||||||
mutable bool SuppressWatches;
|
mutable bool SuppressWatches;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,11 +40,6 @@ public:
|
|||||||
return this->Command;
|
return this->Command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Print the structure to std::cout.
|
|
||||||
*/
|
|
||||||
void Print() const;
|
|
||||||
|
|
||||||
///! Set/Get a property of this source file
|
///! Set/Get a property of this source file
|
||||||
void SetProperty(const std::string& prop, const char *value);
|
void SetProperty(const std::string& prop, const char *value);
|
||||||
void AppendProperty(const std::string& prop,
|
void AppendProperty(const std::string& prop,
|
||||||
|
@ -375,7 +375,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
|
|||||||
comment += "Run arguments : ";
|
comment += "Run arguments : ";
|
||||||
comment += runArgs;
|
comment += runArgs;
|
||||||
comment += "\n";
|
comment += "\n";
|
||||||
comment += " Called from: " + this->Makefile->GetListFileStack();
|
comment += " Called from: " + this->Makefile->FormatListFileStack();
|
||||||
cmsys::SystemTools::ReplaceString(comment, "\n", "\n# ");
|
cmsys::SystemTools::ReplaceString(comment, "\n", "\n# ");
|
||||||
file << comment << "\n\n";
|
file << comment << "\n\n";
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ static std::string cmakemainGetStack(void *clientdata)
|
|||||||
cmMakefile* mf=cmakemainGetMakefile(clientdata);
|
cmMakefile* mf=cmakemainGetMakefile(clientdata);
|
||||||
if (mf)
|
if (mf)
|
||||||
{
|
{
|
||||||
msg = mf->GetListFileStack();
|
msg = mf->FormatListFileStack();
|
||||||
if (!msg.empty())
|
if (!msg.empty())
|
||||||
{
|
{
|
||||||
msg = "\n Called from: " + msg;
|
msg = "\n Called from: " + msg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user