[Cmake-commits] [cmake-commits] king committed cmComputeLinkDepends.cxx 1.33 1.34 cmTarget.cxx 1.255 1.256 cmTarget.h 1.134 1.135

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jul 8 12:04:50 EDT 2009


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

Modified Files:
	cmComputeLinkDepends.cxx cmTarget.cxx cmTarget.h 
Log Message:
ENH: Introduce cmTarget::LinkImplementation API

The new method centralizes loops that process raw OriginalLinkLibraries
to extract the link implementation (libraries linked into the target)
for each configuration.  Results are computed on demand and then cached.
This simplifies link interface computation because the default case
trivially copies the link implementation.


Index: cmTarget.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.h,v
retrieving revision 1.134
retrieving revision 1.135
diff -C 2 -d -r1.134 -r1.135
*** cmTarget.h	8 Jul 2009 12:31:30 -0000	1.134
--- cmTarget.h	8 Jul 2009 16:04:48 -0000	1.135
***************
*** 256,259 ****
--- 256,272 ----
    LinkInterface const* GetLinkInterface(const char* config);
  
+   /** The link implementation specifies the direct library
+       dependencies needed by the object files of the target.  */
+   struct LinkImplementation
+   {
+     // Libraries linked directly in this configuration.
+     std::vector<std::string> Libraries;
+ 
+     // Libraries linked directly in other configurations.
+     // Needed only for OLD behavior of CMP0003.
+     std::vector<std::string> WrongConfigLibraries;
+   };
+   LinkImplementation const* GetLinkImplementation(const char* config);
+ 
    /** Strip off leading and trailing whitespace from an item named in
        the link dependencies of this target.  */
***************
*** 521,524 ****
--- 534,540 ----
    bool ComputeLinkInterface(const char* config, LinkInterface& iface);
  
+   void ComputeLinkImplementation(const char* config,
+                                  LinkImplementation& impl);
+ 
    // The cmMakefile instance that owns this target.  This should
    // always be set.

Index: cmComputeLinkDepends.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmComputeLinkDepends.cxx,v
retrieving revision 1.33
retrieving revision 1.34
diff -C 2 -d -r1.33 -r1.34
*** cmComputeLinkDepends.cxx	7 Jul 2009 13:45:22 -0000	1.33
--- cmComputeLinkDepends.cxx	8 Jul 2009 16:04:47 -0000	1.34
***************
*** 521,540 ****
  {
    // Add direct link dependencies in this configuration.
!   int depender_index = -1;
!   LinkLibraryVectorType const& libs=this->Target->GetOriginalLinkLibraries();
!   std::vector<std::string> actual_libs;
!   for(cmTarget::LinkLibraryVectorType::const_iterator li = libs.begin();
!       li != libs.end(); ++li)
      {
!     if(li->second == cmTarget::GENERAL || li->second == this->LinkType)
!       {
!       actual_libs.push_back(li->first);
!       }
!     else if(this->OldLinkDirMode)
!       {
!       this->CheckWrongConfigItem(depender_index, li->first);
!       }
      }
-   this->AddLinkEntries(depender_index, actual_libs);
  }
  
--- 521,533 ----
  {
    // Add direct link dependencies in this configuration.
!   cmTarget::LinkImplementation const* impl =
!     this->Target->GetLinkImplementation(this->Config);
!   this->AddLinkEntries(-1, impl->Libraries);
!   for(std::vector<std::string>::const_iterator
!         wi = impl->WrongConfigLibraries.begin();
!       wi != impl->WrongConfigLibraries.end(); ++wi)
      {
!     this->CheckWrongConfigItem(-1, *wi);
      }
  }
  

Index: cmTarget.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTarget.cxx,v
retrieving revision 1.255
retrieving revision 1.256
diff -C 2 -d -r1.255 -r1.256
*** cmTarget.cxx	8 Jul 2009 12:31:28 -0000	1.255
--- cmTarget.cxx	8 Jul 2009 16:04:48 -0000	1.256
***************
*** 82,85 ****
--- 82,89 ----
    typedef std::map<cmStdString, cmTarget::ImportInfo> ImportInfoMapType;
    ImportInfoMapType ImportInfoMap;
+ 
+   // Cache link implementation computation from each configuration.
+   typedef std::map<cmStdString, cmTarget::LinkImplementation> LinkImplMapType;
+   LinkImplMapType LinkImplMap;
  };
  
***************
*** 3778,3862 ****
      }
  
-   // Is the link interface just the link implementation?
-   bool doLibraries = !explicitLibraries;
- 
-   // Do we need to construct a list of shared library dependencies not
-   // included in the interface?
-   bool doSharedDeps = (explicitLibraries &&
-                        this->GetType() == cmTarget::SHARED_LIBRARY);
- 
-   // Keep track of what libraries have been emitted.
-   std::set<cmStdString> emitted;
-   std::set<cmStdString> emittedWrongConfig;
- 
    if(explicitLibraries)
      {
      // The interface libraries have been explicitly set.
      cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
-     for(std::vector<std::string>::const_iterator
-           li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
-       {
-       emitted.insert(*li);
-       }
-     }
- 
-   if(doLibraries || doSharedDeps)
-     {
-     // Compute which library configuration to link.
-     cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  
!     // Construct the list of libs linked for this configuration.
!     cmTarget::LinkLibraryVectorType const& llibs =
!       this->GetOriginalLinkLibraries();
!     for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
!         li != llibs.end(); ++li)
        {
!       // Skip entries that resolve to the target itself or are empty.
!       std::string item = this->CheckCMP0004(li->first);
!       if(item == this->GetName() || item.empty())
!         {
!         continue;
!         }
! 
!       // Skip entries not meant for this configuration.
!       if(li->second != cmTarget::GENERAL && li->second != linkType)
!         {
!         // Support OLD behavior for CMP0003.
!         if(doLibraries && emittedWrongConfig.insert(item).second)
!           {
!           iface.WrongConfigLibraries.push_back(item);
!           }
!         continue;
!         }
! 
!       // Skip entries that have already been emitted.
!       if(!emitted.insert(item).second)
!         {
!         continue;
!         }
! 
!       // Emit this item.
!       if(doLibraries)
          {
!         // This implementation dependency goes in the implicit interface.
!         iface.Libraries.push_back(item);
          }
!       else if(cmTarget* tgt = this->Makefile->FindTargetToUse(item.c_str()))
          {
!         // This is a runtime dependency on another shared library.
!         if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
            {
!           iface.SharedDeps.push_back(item);
            }
          }
-       else
-         {
-         // TODO: Recognize shared library file names.  Perhaps this
-         // should be moved to cmComputeLinkInformation, but that creates
-         // a chicken-and-egg problem since this list is needed for its
-         // construction.
-         }
        }
      }
  
    return true;
--- 3782,3832 ----
      }
  
    if(explicitLibraries)
      {
      // The interface libraries have been explicitly set.
      cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries);
  
!     if(this->GetType() == cmTarget::SHARED_LIBRARY)
        {
!       // Shared libraries may have runtime implementation dependencies
!       // on other shared libraries that are not in the interface.
!       std::set<cmStdString> emitted;
!       for(std::vector<std::string>::const_iterator
!             li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
          {
!         emitted.insert(*li);
          }
!       LinkImplementation const* impl = this->GetLinkImplementation(config);
!       for(std::vector<std::string>::const_iterator
!             li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
          {
!         if(emitted.insert(*li).second)
            {
!           if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
!             {
!             // This is a runtime dependency on another shared library.
!             if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
!               {
!               iface.SharedDeps.push_back(*li);
!               }
!             }
!           else
!             {
!             // TODO: Recognize shared library file names.  Perhaps this
!             // should be moved to cmComputeLinkInformation, but that creates
!             // a chicken-and-egg problem since this list is needed for its
!             // construction.
!             }
            }
          }
        }
      }
+   else
+     {
+     // The link implementation is the default link interface.
+     LinkImplementation const* impl = this->GetLinkImplementation(config);
+     iface.Libraries = impl->Libraries;
+     iface.WrongConfigLibraries = impl->WrongConfigLibraries;
+     }
  
    return true;
***************
*** 3864,3867 ****
--- 3834,3896 ----
  
  //----------------------------------------------------------------------------
+ cmTarget::LinkImplementation const*
+ cmTarget::GetLinkImplementation(const char* config)
+ {
+   // There is no link implementation for imported targets.
+   if(this->IsImported())
+     {
+     return 0;
+     }
+ 
+   // Lookup any existing link implementation for this configuration.
+   std::string key = cmSystemTools::UpperCase(config? config : "");
+   cmTargetInternals::LinkImplMapType::iterator
+     i = this->Internal->LinkImplMap.find(key);
+   if(i == this->Internal->LinkImplMap.end())
+     {
+     // Compute the link implementation for this configuration.
+     LinkImplementation impl;
+     this->ComputeLinkImplementation(config, impl);
+ 
+     // Store the information for this configuration.
+     cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
+     i = this->Internal->LinkImplMap.insert(entry).first;
+     }
+ 
+   return &i->second;
+ }
+ 
+ //----------------------------------------------------------------------------
+ void cmTarget::ComputeLinkImplementation(const char* config,
+                                          LinkImplementation& impl)
+ {
+   // Compute which library configuration to link.
+   cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
+ 
+   LinkLibraryVectorType const& llibs = this->GetOriginalLinkLibraries();
+   for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
+       li != llibs.end(); ++li)
+     {
+     // Skip entries that resolve to the target itself or are empty.
+     std::string item = this->CheckCMP0004(li->first);
+     if(item == this->GetName() || item.empty())
+       {
+       continue;
+       }
+ 
+     if(li->second == cmTarget::GENERAL || li->second == linkType)
+       {
+       // The entry is meant for this configuration.
+       impl.Libraries.push_back(item);
+       }
+     else
+       {
+       // Support OLD behavior for CMP0003.
+       impl.WrongConfigLibraries.push_back(item);
+       }
+     }
+ }
+ 
+ //----------------------------------------------------------------------------
  std::string cmTarget::CheckCMP0004(std::string const& item)
  {



More information about the Cmake-commits mailing list