It is factored out of cmGlobalUnixMakefileGenerator3::EnableLanguage,
and may be used by other generators to resolve CMAKE_*_COMPILER
settings.
---
 Source/cmGlobalGenerator.cxx              |   73 +++++++++++++++++++++++++++++
 Source/cmGlobalGenerator.h                |    7 +++
 Source/cmGlobalUnixMakefileGenerator3.cxx |   70 +---------------------------
 3 files changed, 81 insertions(+), 69 deletions(-)

diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index d62fb44..124519a 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -77,6 +77,79 @@ cmGlobalGenerator::~cmGlobalGenerator()
   this->ClearExportSets();
 }
 
+void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang,
+                                                cmMakefile *mf,
+                                                bool optional) {
+  std::string langComp = "CMAKE_";
+  langComp += lang;
+  langComp += "_COMPILER";
+
+  if(!mf->GetDefinition(langComp.c_str()))
+    {
+    if(!optional)
+      {
+      cmSystemTools::Error(langComp.c_str(),
+                           " not set, after EnableLanguage");
+      }
+    return;
+    }
+  const char* name = mf->GetRequiredDefinition(langComp.c_str());
+  std::string path;
+  if(!cmSystemTools::FileIsFullPath(name))
+    {
+    path = cmSystemTools::FindProgram(name);
+    }
+  else
+    {
+    path = name;
+    }
+  if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
+      && (optional==false))
+    {
+    std::string message = "your ";
+    message += lang;
+    message += " compiler: \"";
+    message +=  name;
+    message += "\" was not found.   Please set ";
+    message += langComp;
+    message += " to a valid compiler path or name.";
+    cmSystemTools::Error(message.c_str());
+    path = name;
+    }
+  std::string doc = lang;
+  doc += " compiler.";
+  const char* cname = this->GetCMakeInstance()->
+    GetCacheManager()->GetCacheValue(langComp.c_str());
+  std::string changeVars;
+  if(cname && (path != cname) && (optional==false))
+    {
+    std::string cnameString = cname;
+    std::string pathString = path;
+    // get rid of potentially multiple slashes:
+    cmSystemTools::ConvertToUnixSlashes(cnameString);
+    cmSystemTools::ConvertToUnixSlashes(pathString);
+    if (cnameString != pathString)
+      {
+      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);
+}
+
 // Find the make program for the generator, required for try compiles
 void cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
 {
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index adf7b77..96a326c 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -77,6 +77,13 @@ public:
                               cmMakefile *, bool optional);
 
   /**
+   * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
+   * Intended to be called from EnableLanguage.
+   */
+  void ResolveLanguageCompiler(const std::string &lang, cmMakefile *mf,
+                               bool optional);
+
+  /**
    * Try to determine system infomation, get it from another generator
    */
   virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx 
b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 169d77d..a23c0d8 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -39,7 +39,6 @@ void cmGlobalUnixMakefileGenerator3
                  bool optional)
 {
   this->cmGlobalGenerator::EnableLanguage(languages, mf, optional);
-  std::string path;
   for(std::vector<std::string>::const_iterator l = languages.begin();
       l != languages.end(); ++l)
     {
@@ -47,74 +46,7 @@ void cmGlobalUnixMakefileGenerator3
       {
       continue;
       }
-    const char* lang = l->c_str();
-    std::string langComp = "CMAKE_";
-    langComp += lang;
-    langComp += "_COMPILER";
-
-    if(!mf->GetDefinition(langComp.c_str()))
-      {
-      if(!optional)
-        {
-        cmSystemTools::Error(langComp.c_str(),
-                             " not set, after EnableLanguage");
-        }
-      continue;
-      }
-    const char* name = mf->GetRequiredDefinition(langComp.c_str());
-    if(!cmSystemTools::FileIsFullPath(name))
-      {
-      path = cmSystemTools::FindProgram(name);
-      }
-    else
-      {
-      path = name;
-      }
-    if((path.size() == 0 || !cmSystemTools::FileExists(path.c_str()))
-        && (optional==false))
-      {
-      std::string message = "your ";
-      message += lang;
-      message += " compiler: \"";
-      message +=  name;
-      message += "\" was not found.   Please set ";
-      message += langComp;
-      message += " to a valid compiler path or name.";
-      cmSystemTools::Error(message.c_str());
-      path = name;
-      }
-    std::string doc = lang;
-    doc += " compiler.";
-    const char* cname = this->GetCMakeInstance()->
-      GetCacheManager()->GetCacheValue(langComp.c_str());
-    std::string changeVars;
-    if(cname && (path != cname) && (optional==false))
-      {
-      std::string cnameString = cname;
-      std::string pathString = path;
-      // get rid of potentially multiple slashes:
-      cmSystemTools::ConvertToUnixSlashes(cnameString);
-      cmSystemTools::ConvertToUnixSlashes(pathString);
-      if (cnameString != pathString)
-        {
-        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);
+    this->ResolveLanguageCompiler(*l, mf, optional);
     }
 }
 
-- 
1.7.5.3

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to