summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmDefinitions.cxx6
-rw-r--r--Source/cmDefinitions.h4
-rw-r--r--Source/cmMakefile.cxx17
-rw-r--r--Source/cmOptionCommand.cxx4
-rw-r--r--Source/cmState.cxx4
-rw-r--r--Source/cmStateSnapshot.cxx7
-rw-r--r--Source/cmStateSnapshot.h2
7 files changed, 25 insertions, 19 deletions
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index e766854..5fafaf9 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -30,11 +30,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
return begin->Map.insert(MapType::value_type(key, def)).first->second;
}
-const char* cmDefinitions::Get(const std::string& key, StackIter begin,
- StackIter end)
+const std::string* cmDefinitions::Get(const std::string& key, StackIter begin,
+ StackIter end)
{
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
- return def.Exists ? def.c_str() : nullptr;
+ return def.Exists ? &def : nullptr;
}
void cmDefinitions::Raise(const std::string& key, StackIter begin,
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 528b157..4ab5be6 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -23,8 +23,8 @@ class cmDefinitions
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
public:
- static const char* Get(const std::string& key, StackIter begin,
- StackIter end);
+ static const std::string* Get(const std::string& key, StackIter begin,
+ StackIter end);
static void Raise(const std::string& key, StackIter begin, StackIter end);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 11019d7..5498ad2 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2368,8 +2368,10 @@ std::string cmMakefile::GetRequiredDefinition(const std::string& name) const
bool cmMakefile::IsDefinitionSet(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ const char* def;
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -2385,8 +2387,10 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
const char* cmMakefile::GetDefinition(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ const char* def;
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -2402,8 +2406,9 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
// A callback was executed and may have caused re-allocation of the
// variable storage. Look it up again for now.
// FIXME: Refactor variable storage to avoid this problem.
- def = this->StateSnapshot.GetDefinition(name);
- if (!def) {
+ if (const std::string* d = this->StateSnapshot.GetDefinition(name)) {
+ def = d->c_str();
+ } else {
def = this->GetState()->GetInitializedCacheValue(name);
}
}
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
index 816f06c..006211d 100644
--- a/Source/cmOptionCommand.cxx
+++ b/Source/cmOptionCommand.cxx
@@ -31,7 +31,7 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
bool checkAndWarn = false;
{
auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077);
- const char* existsBeforeSet =
+ const auto* existsBeforeSet =
this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
switch (status) {
case cmPolicies::WARN:
@@ -72,7 +72,7 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
args[1].c_str(), cmStateEnums::BOOL);
if (checkAndWarn) {
- const char* existsAfterSet =
+ const auto* existsAfterSet =
this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
if (!existsAfterSet) {
std::ostringstream w;
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 5651594..89738f4 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -298,9 +298,9 @@ cmStateSnapshot cmState::Reset()
{
std::string srcDir =
- cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
std::string binDir =
- cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
this->VarTree.Clear();
pos->Vars = this->VarTree.Push(this->VarTree.Root());
pos->Parent = this->VarTree.Root();
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index ec428a6..0379e7e 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -204,7 +204,8 @@ bool cmStateSnapshot::HasDefinedPolicyCMP0011()
return !this->Position->Policies->IsEmpty();
}
-const char* cmStateSnapshot::GetDefinition(std::string const& name) const
+std::string const* cmStateSnapshot::GetDefinition(
+ std::string const& name) const
{
assert(this->Position->Vars.IsValid());
return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
@@ -426,8 +427,8 @@ std::string cmStateSnapshot::GetProjectName() const
void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand()
{
- std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
- std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
+ std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
+ std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
this->InitializeFromParent();
this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h
index af5653b..014c62e 100644
--- a/Source/cmStateSnapshot.h
+++ b/Source/cmStateSnapshot.h
@@ -22,7 +22,7 @@ public:
cmStateSnapshot(cmState* state = nullptr);
cmStateSnapshot(cmState* state, cmStateDetail::PositionType position);
- const char* GetDefinition(std::string const& name) const;
+ std::string const* GetDefinition(std::string const& name) const;
bool IsInitialized(std::string const& name) const;
void SetDefinition(std::string const& name, std::string const& value);
void RemoveDefinition(std::string const& name);