From 55eede4b131e39cc341832cd99d3b339f040af75 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Fri, 7 Mar 2008 11:43:47 -0500 Subject: [PATCH] ENH: clean up some policy stuff and interactions with CMAKE_BACKWARDS_COMPATIBILITY and CMAKE_MINIMUM_REQUIRED --- Source/cmCMakeMinimumRequired.cxx | 9 +++++++++ Source/cmCacheManager.h | 1 + Source/cmListFileCache.cxx | 31 +++++-------------------------- Source/cmPolicies.cxx | 24 ++++++++++++++++++++++++ Source/cmake.cxx | 26 ++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 26 deletions(-) diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx index 54acb898c..bb5bdb099 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -108,6 +108,15 @@ bool cmCMakeMinimumRequired 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; } diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h index 50cc873d2..f1e2298ac 100644 --- a/Source/cmCacheManager.h +++ b/Source/cmCacheManager.h @@ -66,6 +66,7 @@ public: bool GetValueAsBool() const; void SetValue(const char*); CacheEntryType GetType() const { return this->GetEntry().Type; } + void SetType(CacheEntryType ty) { this->GetEntry().Type = ty; } bool Initialized() { return this->GetEntry().Initialized; } cmCacheManager &Container; std::map::iterator Position; diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 34798f527..234c8e5c3 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -134,22 +134,15 @@ bool cmListFile::ParseFile(const char* filename, hasPolicy = true; break; } + if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required") + { + hasPolicy = true; + break; + } } // if no policy command is found this is an error 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)) { case cmPolicies::WARN: @@ -165,20 +158,6 @@ bool cmListFile::ParseFile(const char* filename, 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) diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 382507bb2..79fecc324 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -184,6 +184,30 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, 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 std::map::iterator i = this->Policies.begin(); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 31693d25f..e9d92b3db 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1899,6 +1899,19 @@ int cmake::ActualConfigure() 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 if(!this->GlobalGenerator) { @@ -2380,6 +2393,19 @@ int cmake::LoadCache() 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; }