ENH: clean up some policy stuff and interactions with CMAKE_BACKWARDS_COMPATIBILITY and CMAKE_MINIMUM_REQUIRED

This commit is contained in:
Ken Martin 2008-03-07 11:43:47 -05:00
parent 497779d4b3
commit 55eede4b13
5 changed files with 65 additions and 26 deletions

View File

@ -108,6 +108,15 @@ bool cmCMakeMinimumRequired
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
} }
if (required_major < 2 || required_major == 2 && required_minor < 4)
{
this->Makefile->SetPolicyVersion("2.4");
}
else
{
this->Makefile->SetPolicyVersion(version_string.c_str());
}
return true; return true;
} }

View File

@ -66,6 +66,7 @@ public:
bool GetValueAsBool() const; bool GetValueAsBool() const;
void SetValue(const char*); void SetValue(const char*);
CacheEntryType GetType() const { return this->GetEntry().Type; } CacheEntryType GetType() const { return this->GetEntry().Type; }
void SetType(CacheEntryType ty) { this->GetEntry().Type = ty; }
bool Initialized() { return this->GetEntry().Initialized; } bool Initialized() { return this->GetEntry().Initialized; }
cmCacheManager &Container; cmCacheManager &Container;
std::map<cmStdString, CacheEntry>::iterator Position; std::map<cmStdString, CacheEntry>::iterator Position;

View File

@ -134,22 +134,15 @@ bool cmListFile::ParseFile(const char* filename,
hasPolicy = true; hasPolicy = true;
break; break;
} }
if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required")
{
hasPolicy = true;
break;
}
} }
// if no policy command is found this is an error // if no policy command is found this is an error
if(!hasPolicy) if(!hasPolicy)
{ {
// add in the old CMAKE_BACKWARDS_COMPATIBILITY var for old CMake compatibility
if (!mf->GetCacheManager()->
GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
{
mf->AddCacheDefinition
("CMAKE_BACKWARDS_COMPATIBILITY", "2.5",
"For backwards compatibility, what version of CMake "
"commands and "
"syntax should this version of CMake try to support.",
cmCacheManager::STRING);
}
switch (mf->GetPolicyStatus(cmPolicies::CMP_0000)) switch (mf->GetPolicyStatus(cmPolicies::CMP_0000))
{ {
case cmPolicies::WARN: case cmPolicies::WARN:
@ -165,20 +158,6 @@ bool cmListFile::ParseFile(const char* filename,
return false; return false;
} }
} }
else
{
// add in the old CMAKE_BACKWARDS_COMPATIBILITY var for old CMake compatibility
if (!mf->GetCacheManager()->
GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
{
mf->AddCacheDefinition
("CMAKE_BACKWARDS_COMPATIBILITY", "2.5",
"For backwards compatibility, what version of CMake "
"commands and "
"syntax should this version of CMake try to support.",
cmCacheManager::INTERNAL);
}
}
} }
if(topLevel) if(topLevel)

View File

@ -184,6 +184,30 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
return false; return false;
} }
// it is an error if the policy version is less than 2.4
if (majorVer < 2 || majorVer == 2 && minorVer < 4)
{
mf->IssueError("An attempt was made to set the policy version of "
"CMake to something earlier than 2.4, this is an error!");
}
// if the version is 2.4 then make sure the backwards compatibility variable is visible
if (majorVer == 2 && minorVer == 4)
{
// set the default BACKWARDS compatibility to be visible
mf->GetCacheManager()->GetCacheIterator(
"CMAKE_BACKWARDS_COMPATIBILITY").SetType
(cmCacheManager::STRING);
// const char *cbcValue =
// mf->GetCacheManager()->
// GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY");
// mf->AddCacheDefinition
// ("CMAKE_BACKWARDS_COMPATIBILITY",cbcValue,
// "For backwards compatibility, what version of CMake commands and "
// "syntax should this version of CMake allow.",
// cmCacheManager::STRING);
}
// now loop over all the policies and set them as appropriate // now loop over all the policies and set them as appropriate
std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
= this->Policies.begin(); = this->Policies.begin();

View File

@ -1899,6 +1899,19 @@ int cmake::ActualConfigure()
cmCacheManager::INTERNAL); cmCacheManager::INTERNAL);
} }
// set the default BACKWARDS compatibility to the current version
if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
{
char ver[256];
sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(),
cmVersion::GetMinorVersion());
this->CacheManager->AddCacheEntry
("CMAKE_BACKWARDS_COMPATIBILITY",ver,
"For backwards compatibility, what version of CMake commands and "
"syntax should this version of CMake allow.",
cmCacheManager::INTERNAL);
}
// no generator specified on the command line // no generator specified on the command line
if(!this->GlobalGenerator) if(!this->GlobalGenerator)
{ {
@ -2380,6 +2393,19 @@ int cmake::LoadCache()
return -3; return -3;
} }
// set the default BACKWARDS compatibility to the current version
if(!this->CacheManager->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
{
char ver[256];
sprintf(ver,"%i.%i",cmVersion::GetMajorVersion(),
cmVersion::GetMinorVersion());
this->CacheManager->AddCacheEntry
("CMAKE_BACKWARDS_COMPATIBILITY",ver,
"For backwards compatibility, what version of CMake commands and "
"syntax should this version of CMake allow.",
cmCacheManager::INTERNAL);
}
return 0; return 0;
} }