summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-01-22 15:56:50 (GMT)
committerBrad King <brad.king@kitware.com>2009-01-22 15:56:50 (GMT)
commita01eb6b27be0e9a32378c56140d231ceda612368 (patch)
treec43d0140b682020f2339209f13321c500ff72ee6 /Source/cmMakefile.cxx
parent8997f4760a83efb270f3f9234a016451c0884fe2 (diff)
downloadCMake-a01eb6b27be0e9a32378c56140d231ceda612368.zip
CMake-a01eb6b27be0e9a32378c56140d231ceda612368.tar.gz
CMake-a01eb6b27be0e9a32378c56140d231ceda612368.tar.bz2
ENH: Create automatic policy push/pop helper
This creates cmMakefile::PolicyPushPop to push and pop policy scope automatically. It also enforces balanced push/pop pairs inside the scope it handles.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx29
1 files changed, 29 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.