summaryrefslogtreecommitdiffstats
path: root/Source/cmPolicies.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-01-03 23:04:58 (GMT)
committerBrad King <brad.king@kitware.com>2011-01-04 12:46:10 (GMT)
commita364daf1fd1fd9079fdc13bec4fe8ea2a56efe04 (patch)
treebd2e3d1a05d13d67ceb277b449f4d345d61d837a /Source/cmPolicies.cxx
parent8e45c1128cd6546a87d7ee32ace91950016f5233 (diff)
downloadCMake-a364daf1fd1fd9079fdc13bec4fe8ea2a56efe04.zip
CMake-a364daf1fd1fd9079fdc13bec4fe8ea2a56efe04.tar.gz
CMake-a364daf1fd1fd9079fdc13bec4fe8ea2a56efe04.tar.bz2
Allow users to specify defaults for unset policies
Check CMAKE_POLICY_DEFAULT_CMP<NNNN> for a default when policy CMP<NNNN> would otherwise be left unset. This allows users to set policies on the command line when the project does not set them. One may do this to quiet warnings or test whether a project will build with new behavior without modifying code. There may also be cases when users want to build an existing project release using new behavior for policies unknown to the project at the time of the release.
Diffstat (limited to 'Source/cmPolicies.cxx')
-rw-r--r--Source/cmPolicies.cxx39
1 files changed, 37 insertions, 2 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index d147a3b..fccf0cc 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -565,9 +565,14 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
{
ancientPolicies.push_back(i->first);
}
- else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
+ else
{
- return false;
+ cmPolicies::PolicyStatus status = cmPolicies::WARN;
+ if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
+ !mf->SetPolicy(i->second->ID, status))
+ {
+ return false;
+ }
}
}
else
@@ -591,6 +596,36 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
return true;
}
+//----------------------------------------------------------------------------
+bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
+ cmPolicies::PolicyStatus* defaultSetting)
+{
+ std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
+ std::string defaultValue = mf->GetSafeDefinition(defaultVar.c_str());
+ if(defaultValue == "NEW")
+ {
+ *defaultSetting = cmPolicies::NEW;
+ }
+ else if(defaultValue == "OLD")
+ {
+ *defaultSetting = cmPolicies::OLD;
+ }
+ else if(defaultValue == "")
+ {
+ *defaultSetting = cmPolicies::WARN;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << defaultVar << " has value \"" << defaultValue
+ << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+
+ return true;
+}
+
bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
{
if (!id || strlen(id) < 1)