Merge branch 'user-policy-defaults' into policy-CMP0017
This commit is contained in:
commit
1e69c6f37f
|
@ -85,7 +85,8 @@ public:
|
||||||
"given version of CMake. "
|
"given version of CMake. "
|
||||||
"All policies introduced in the specified version or earlier "
|
"All policies introduced in the specified version or earlier "
|
||||||
"will be set to use NEW behavior. "
|
"will be set to use NEW behavior. "
|
||||||
"All policies introduced after the specified version will be unset. "
|
"All policies introduced after the specified version will be unset "
|
||||||
|
"(unless variable CMAKE_POLICY_DEFAULT_CMP<NNNN> sets a default). "
|
||||||
"This effectively requests behavior preferred as of a given CMake "
|
"This effectively requests behavior preferred as of a given CMake "
|
||||||
"version and tells newer CMake versions to warn about their new "
|
"version and tells newer CMake versions to warn about their new "
|
||||||
"policies. "
|
"policies. "
|
||||||
|
|
|
@ -464,6 +464,25 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
|
||||||
|
|
||||||
// Variables defined by cmake, that change the behavior
|
// Variables defined by cmake, that change the behavior
|
||||||
// of cmake
|
// of cmake
|
||||||
|
|
||||||
|
cm->DefineProperty
|
||||||
|
("CMAKE_POLICY_DEFAULT_CMP<NNNN>", cmProperty::VARIABLE,
|
||||||
|
"Default for CMake Policy CMP<NNNN> when it is otherwise left unset.",
|
||||||
|
"Commands cmake_minimum_required(VERSION) and cmake_policy(VERSION) "
|
||||||
|
"by default leave policies introduced after the given version unset. "
|
||||||
|
"Set CMAKE_POLICY_DEFAULT_CMP<NNNN> to OLD or NEW to specify the "
|
||||||
|
"default for policy CMP<NNNN>, where <NNNN> is the policy number."
|
||||||
|
"\n"
|
||||||
|
"This variable should not be set by a project in CMake code; "
|
||||||
|
"use cmake_policy(SET) instead. "
|
||||||
|
"Users running CMake may set this variable in the cache "
|
||||||
|
"(e.g. -DCMAKE_POLICY_DEFAULT_CMP<NNNN>=<OLD|NEW>) "
|
||||||
|
"to set a policy not otherwise set by the project. "
|
||||||
|
"Set to OLD to quiet a policy warning while using old behavior "
|
||||||
|
"or to NEW to try building the project with new behavior.",
|
||||||
|
false,
|
||||||
|
"Variables That Change Behavior");
|
||||||
|
|
||||||
cm->DefineProperty
|
cm->DefineProperty
|
||||||
("CMAKE_FIND_LIBRARY_PREFIXES", cmProperty::VARIABLE,
|
("CMAKE_FIND_LIBRARY_PREFIXES", cmProperty::VARIABLE,
|
||||||
"Prefixes to prepend when looking for libraries.",
|
"Prefixes to prepend when looking for libraries.",
|
||||||
|
|
|
@ -556,9 +556,8 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
|
||||||
|
|
||||||
// now loop over all the policies and set them as appropriate
|
// now loop over all the policies and set them as appropriate
|
||||||
std::vector<cmPolicies::PolicyID> ancientPolicies;
|
std::vector<cmPolicies::PolicyID> ancientPolicies;
|
||||||
std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
|
for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
|
||||||
= this->Policies.begin();
|
= this->Policies.begin(); i != this->Policies.end(); ++i)
|
||||||
for (;i != this->Policies.end(); ++i)
|
|
||||||
{
|
{
|
||||||
if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
|
if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
|
||||||
{
|
{
|
||||||
|
@ -566,11 +565,16 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
|
||||||
{
|
{
|
||||||
ancientPolicies.push_back(i->first);
|
ancientPolicies.push_back(i->first);
|
||||||
}
|
}
|
||||||
else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
|
else
|
||||||
|
{
|
||||||
|
cmPolicies::PolicyStatus status = cmPolicies::WARN;
|
||||||
|
if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
|
||||||
|
!mf->SetPolicy(i->second->ID, status))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
|
if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
|
||||||
|
@ -592,6 +596,36 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
|
||||||
return true;
|
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)
|
bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
|
||||||
{
|
{
|
||||||
if (!id || strlen(id) < 1)
|
if (!id || strlen(id) < 1)
|
||||||
|
|
|
@ -102,6 +102,10 @@ public:
|
||||||
void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
|
void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
|
||||||
unsigned int majorVer, unsigned int minorVer,
|
unsigned int majorVer, unsigned int minorVer,
|
||||||
unsigned int patchVer, cmMakefile* mf);
|
unsigned int patchVer, cmMakefile* mf);
|
||||||
|
|
||||||
|
bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
|
||||||
|
cmPolicies::PolicyStatus* defaultStatus);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -81,6 +81,24 @@ macro1()
|
||||||
cmake_policy(GET CMP0002 cmp)
|
cmake_policy(GET CMP0002 cmp)
|
||||||
check(CMP0002 "OLD" "${cmp}")
|
check(CMP0002 "OLD" "${cmp}")
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Test CMAKE_POLICY_DEFAULT_CMP<NNNN> variable.
|
||||||
|
cmake_policy(PUSH)
|
||||||
|
set(CMAKE_POLICY_DEFAULT_CMP0010 OLD) # ignored
|
||||||
|
set(CMAKE_POLICY_DEFAULT_CMP0012 OLD) # honored
|
||||||
|
set(CMAKE_POLICY_DEFAULT_CMP0013 NEW) # honored
|
||||||
|
set(CMAKE_POLICY_DEFAULT_CMP0014 "") # noop
|
||||||
|
cmake_policy(VERSION 2.6.3)
|
||||||
|
cmake_policy(GET CMP0010 cmp)
|
||||||
|
check(CMP0010 "NEW" "${cmp}")
|
||||||
|
cmake_policy(GET CMP0012 cmp)
|
||||||
|
check(CMP0012 "OLD" "${cmp}")
|
||||||
|
cmake_policy(GET CMP0013 cmp)
|
||||||
|
check(CMP0013 "NEW" "${cmp}")
|
||||||
|
cmake_policy(GET CMP0014 cmp)
|
||||||
|
check(CMP0014 "" "${cmp}")
|
||||||
|
cmake_policy(POP)
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Dummy executable so the project can build and run.
|
# Dummy executable so the project can build and run.
|
||||||
add_executable(PolicyScope main.c)
|
add_executable(PolicyScope main.c)
|
||||||
|
|
Loading…
Reference in New Issue