[Cmake-commits] [cmake-commits] king committed cmGlobalGenerator.h 1.121 1.122 cmGlobalXCodeGenerator.cxx 1.217 1.218 cmGlobalXCodeGenerator.h 1.59 1.60

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jul 10 16:51:46 EDT 2009


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

Modified Files:
	cmGlobalGenerator.h cmGlobalXCodeGenerator.cxx 
	cmGlobalXCodeGenerator.h 
Log Message:
BUG: Fix Xcode linker language

Xcode does not seem to support direct requests for using the linker for
a particular language.  It always infers the linker using the languages
in the source files.  When no user source files compile with target's
linker language we add one to help Xcode pick the linker.

A typical use case is when a C executable links to a C++ archive.  The
executable has no C++ source files but we need to use the C++ linker.


Index: cmGlobalXCodeGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.cxx,v
retrieving revision 1.217
retrieving revision 1.218
diff -C 2 -d -r1.217 -r1.218
*** cmGlobalXCodeGenerator.cxx	8 Jul 2009 17:04:00 -0000	1.217
--- cmGlobalXCodeGenerator.cxx	10 Jul 2009 20:51:44 -0000	1.218
***************
*** 240,243 ****
--- 240,244 ----
      this->AddExtraTargets(root, it->second);
      }
+   this->ForceLinkerLanguages();
    this->cmGlobalGenerator::Generate();
    for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
***************
*** 970,973 ****
--- 971,1030 ----
  
  //----------------------------------------------------------------------------
+ void cmGlobalXCodeGenerator::ForceLinkerLanguages()
+ {
+   // This makes sure all targets link using the proper language.
+   for(std::map<cmStdString, cmTarget*>::const_iterator
+         ti = this->TotalTargets.begin(); ti != this->TotalTargets.end(); ++ti)
+     {
+     this->ForceLinkerLanguage(*ti->second);
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget)
+ {
+   // This matters only for targets that link.
+   if(cmtarget.GetType() != cmTarget::EXECUTABLE &&
+      cmtarget.GetType() != cmTarget::SHARED_LIBRARY &&
+      cmtarget.GetType() != cmTarget::MODULE_LIBRARY)
+     {
+     return;
+     }
+ 
+   const char* llang = cmtarget.GetLinkerLanguage("NOCONFIG");
+   if(!llang) { return; }
+ 
+   // If the language is compiled as a source trust Xcode to link with it.
+   cmTarget::LinkImplementation const* impl =
+     cmtarget.GetLinkImplementation("NOCONFIG");
+   for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
+       li != impl->Languages.end(); ++li)
+     {
+     if(*li == llang) { return; }
+     }
+ 
+   // Add an empty source file to the target that compiles with the
+   // linker language.  This should convince Xcode to choose the proper
+   // language.
+   cmMakefile* mf = cmtarget.GetMakefile();
+   std::string fname = mf->GetCurrentOutputDirectory();
+   fname += cmake::GetCMakeFilesDirectory();
+   fname += "/";
+   fname += cmtarget.GetName();
+   fname += "-CMakeForceLinker";
+   fname += ".";
+   fname += cmSystemTools::LowerCase(llang);
+   {
+   cmGeneratedFileStream fout(fname.c_str());
+   fout << "\n";
+   }
+   if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str()))
+     {
+     sf->SetProperty("LANGUAGE", llang);
+     cmtarget.AddSourceFile(sf);
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
  bool cmGlobalXCodeGenerator::IsHeaderFile(cmSourceFile* sf)
  {

Index: cmGlobalXCodeGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalXCodeGenerator.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -C 2 -d -r1.59 -r1.60
*** cmGlobalXCodeGenerator.h	2 Jul 2009 18:14:03 -0000	1.59
--- cmGlobalXCodeGenerator.h	10 Jul 2009 20:51:44 -0000	1.60
***************
*** 129,132 ****
--- 129,134 ----
    cmXCodeObject* CreateXCodeTarget(cmTarget& target,
                                     cmXCodeObject* buildPhases);
+   void ForceLinkerLanguages();
+   void ForceLinkerLanguage(cmTarget& cmtarget);
    const char* GetTargetFileType(cmTarget& cmtarget);
    const char* GetTargetProductType(cmTarget& cmtarget);

Index: cmGlobalGenerator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmGlobalGenerator.h,v
retrieving revision 1.121
retrieving revision 1.122
diff -C 2 -d -r1.121 -r1.122
*** cmGlobalGenerator.h	9 Mar 2009 16:19:27 -0000	1.121
--- cmGlobalGenerator.h	10 Jul 2009 20:51:43 -0000	1.122
***************
*** 318,321 ****
--- 318,324 ----
    cmTargetManifest TargetManifest;
  
+   // All targets in the entire project.
+   std::map<cmStdString,cmTarget *> TotalTargets;
+ 
  private:
    float FirstTimeProgress;
***************
*** 329,335 ****
    std::map<cmStdString, int> LanguageToLinkerPreference; 
  
-   // this is used to improve performance
-   std::map<cmStdString,cmTarget *> TotalTargets;
- 
    // Record hashes for rules and outputs.
    struct RuleHash { char Data[32]; };
--- 332,335 ----



More information about the Cmake-commits mailing list