Просмотр исходного кода

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

Ken Martin 18 лет назад
Родитель
Сommit
55eede4b13
5 измененных файлов с 65 добавлено и 26 удалено
  1. 9 0
      Source/cmCMakeMinimumRequired.cxx
  2. 1 0
      Source/cmCacheManager.h
  3. 5 26
      Source/cmListFileCache.cxx
  4. 24 0
      Source/cmPolicies.cxx
  5. 26 0
      Source/cmake.cxx

+ 9 - 0
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;
 }
 

+ 1 - 0
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<cmStdString, CacheEntry>::iterator Position;

+ 5 - 26
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)

+ 24 - 0
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<cmPolicies::PolicyID,cmPolicy *>::iterator i 
     = this->Policies.begin();

+ 26 - 0
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;
 }