[cmake-commits] hoffman committed cmGlobalUnixMakefileGenerator3.cxx 1.116 1.117 cmMakefileTargetGenerator.cxx 1.73 1.74 cmake.cxx 1.336 1.337 cmake.h 1.95 1.96

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Dec 13 15:54:31 EST 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv24622/Source

Modified Files:
	cmGlobalUnixMakefileGenerator3.cxx 
	cmMakefileTargetGenerator.cxx cmake.cxx cmake.h 
Log Message:
ENH: fix for bug 6102, allow users to change the compiler


Index: cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -d -r1.95 -r1.96
--- cmake.h	19 Nov 2007 18:45:16 -0000	1.95
+++ cmake.h	13 Dec 2007 20:54:29 -0000	1.96
@@ -142,6 +142,7 @@
    * files for the tree. It will not produce any actual Makefiles, or
    * workspaces. Generate does that.  */
   int Configure();
+  int ActualConfigure();
 
   /**
    * Configure the cmMakefiles. This routine will create a GlobalGenerator if
@@ -328,6 +329,7 @@
   static void DefineProperties(cmake *cm);
 
 protected:
+  int HandleDeleteCacheVariables(const char* var);
   cmPropertyMap Properties;
   std::set<std::pair<cmStdString,cmProperty::ScopeType> > AccessedProperties;
 

Index: cmGlobalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalUnixMakefileGenerator3.cxx,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- cmGlobalUnixMakefileGenerator3.cxx	22 Oct 2007 16:48:39 -0000	1.116
+++ cmGlobalUnixMakefileGenerator3.cxx	13 Dec 2007 20:54:29 -0000	1.117
@@ -63,7 +63,7 @@
                            " not set, after EnableLanguage");
       continue;
       }
-    const char* name = mf->GetRequiredDefinition(langComp.c_str());
+    const char* name = mf->GetRequiredDefinition(langComp.c_str()); 
     if(!cmSystemTools::FileIsFullPath(name))
       {
       path = cmSystemTools::FindProgram(name);
@@ -87,6 +87,26 @@
       }
     std::string doc = lang;
     doc += " compiler.";
+    const char* cname = this->GetCMakeInstance()->
+      GetCacheManager()->GetCacheValue(langComp.c_str());
+    std::string changeVars;
+    if(cname && (path != cname))
+      {
+      const char* cvars = 
+        this->GetCMakeInstance()->GetProperty(
+          "__CMAKE_DELETE_CACHE_CHANGE_VARS_");
+      if(cvars)
+        {
+        changeVars += cvars;
+        changeVars += ";";
+        }
+      changeVars += langComp;
+      changeVars += ";";
+      changeVars += cname;
+      this->GetCMakeInstance()->SetProperty(
+        "__CMAKE_DELETE_CACHE_CHANGE_VARS_",
+        changeVars.c_str());
+      }
     mf->AddCacheDefinition(langComp.c_str(), path.c_str(),
                            doc.c_str(), cmCacheManager::FILEPATH);
     }

Index: cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.336
retrieving revision 1.337
diff -u -d -r1.336 -r1.337
--- cmake.cxx	4 Dec 2007 21:03:18 -0000	1.336
+++ cmake.cxx	13 Dec 2007 20:54:29 -0000	1.337
@@ -224,7 +224,7 @@
   for(RegisteredCommandsMap::iterator j = this->Commands.begin();
       j != this->Commands.end(); ++j)
     {
-    if ( !j->second->IsA("cmMacroHelperCommand") && 
+    if ( !j->second->IsA("cmMacroHelpperCommand") && 
          !j->second->IsA("cmFunctionHelperCommand"))
       {
       commands.push_back(j->second);
@@ -1793,9 +1793,79 @@
     }
   return 1;
 }
+struct SaveCacheEntry
+{
+  std::string key;
+  std::string value;
+  std::string help;
+  cmCacheManager::CacheEntryType type;
+};
+
+int cmake::HandleDeleteCacheVariables(const char* var)
+{
+  std::vector<std::string> argsSplit;
+  cmSystemTools::ExpandListArgument(std::string(var), argsSplit);
+  // erase the property to avoid infinite recursion
+  this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
+
+  cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
+  std::vector<SaveCacheEntry> saved;
+  cmOStringStream warning;
+  warning 
+    << "You have changed variables that require your cache to be deleted.\n"
+    << "Configure will be re-run and you may have to reset some variables.\n"
+    << "The following variables have changed:\n";
+  for(std::vector<std::string>::iterator i = argsSplit.begin();
+      i != argsSplit.end(); ++i)
+    { 
+    SaveCacheEntry save;
+    save.key = *i;
+    warning << *i << "= ";
+    i++;
+    save.value = *i;
+    warning << *i << "\n";
+    if(ci.Find(save.key.c_str()))
+      {
+      save.type = ci.GetType();
+      save.help = ci.GetProperty("HELPSTRING");
+      }
+    saved.push_back(save);
+    }
+  
+  // remove the cache
+  this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
+  // load the empty cache
+  this->LoadCache();
+  // restore the changed compilers
+  for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
+      i != saved.end(); ++i)
+    {
+    this->AddCacheEntry(i->key.c_str(), i->value.c_str(),
+                        i->help.c_str(), i->type);
+    }
+  cmSystemTools::Message(warning.str().c_str());
+  // avoid reconfigure if there were errors
+  if(!cmSystemTools::GetErrorOccuredFlag())
+    {
+    // re-run configure
+    return this->Configure();
+    }
+}
 
 int cmake::Configure()
 {
+  int ret = this->ActualConfigure();
+  const char* delCacheVars = this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
+  if(delCacheVars && delCacheVars[0] != 0)
+    {
+    return this->HandleDeleteCacheVariables(delCacheVars);
+    }
+  return ret;
+
+}
+
+int cmake::ActualConfigure()
+{
   // Construct right now our path conversion table before it's too late:
   this->UpdateConversionPathTable();
   this->CleanupCommandsAndMacros();
@@ -1955,7 +2025,6 @@
 
   // actually do the configure
   this->GlobalGenerator->Configure();
-  
   // Before saving the cache
   // if the project did not define one of the entries below, add them now
   // so users can edit the values in the cache:

Index: cmMakefileTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- cmMakefileTargetGenerator.cxx	23 Nov 2007 19:53:06 -0000	1.73
+++ cmMakefileTargetGenerator.cxx	13 Dec 2007 20:54:29 -0000	1.74
@@ -236,6 +236,18 @@
   // write language flags for target
   std::set<cmStdString> languages;
   this->Target->GetLanguages(languages);
+    // put the compiler in the rules.make file so that if it changes
+  // things rebuild
+  for(std::set<cmStdString>::const_iterator l = languages.begin();
+      l != languages.end(); ++l)
+    {
+    cmStdString compiler = "CMAKE_";
+    compiler += *l;
+    compiler += "_COMPILER";
+    *this->FlagFileStream << "# compile " << l->c_str() << " with " << 
+      this->Makefile->GetSafeDefinition(compiler.c_str()) << "\n";
+    }
+
   for(std::set<cmStdString>::const_iterator l = languages.begin();
       l != languages.end(); ++l)
     {



More information about the Cmake-commits mailing list