summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmMakefile.cxx29
-rw-r--r--Source/cmMakefile.h12
2 files changed, 41 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index f9b40b1..b402a6d 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -3674,6 +3674,35 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
return true;
}
+//----------------------------------------------------------------------------
+cmMakefile::PolicyPushPop::PolicyPushPop(cmMakefile* m): Makefile(m)
+{
+ this->Makefile->PushPolicy();
+ this->PolicyDepth = this->Makefile->PolicyStack.size();
+}
+
+//----------------------------------------------------------------------------
+cmMakefile::PolicyPushPop::~PolicyPushPop()
+{
+ // Enforce matching PUSH/POP pairs.
+ if(this->Makefile->PolicyStack.size() < this->PolicyDepth)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "cmake_policy POP without matching PUSH");
+ return;
+ }
+ while(this->Makefile->PolicyStack.size() > this->PolicyDepth)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "cmake_policy PUSH without matching POP");
+ this->Makefile->PopPolicy(false);
+ }
+
+ // Pop our scope.
+ this->Makefile->PopPolicy();
+}
+
+//----------------------------------------------------------------------------
bool cmMakefile::PushPolicy()
{
// Allocate a new stack entry.
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 4daec16..fb1e1e1 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -346,6 +346,18 @@ public:
bool SetPolicyVersion(const char *version);
//@}
+ /** Helper class to push and pop policies automatically. */
+ class PolicyPushPop
+ {
+ public:
+ PolicyPushPop(cmMakefile* m);
+ ~PolicyPushPop();
+ private:
+ cmMakefile* Makefile;
+ size_t PolicyDepth;
+ };
+ friend class PolicyPushPop;
+
/**
* Get the Policies Instance
*/