Jelajahi Sumber

cmTarget: Add method to add usage requirements from linked interfaces

Create a cmTargetInternals::AddInterfaceEntries method to construct a
$<TARGET_PROPERTY:tgt,INTERFACE_XYZ> generator expression and evaluate
it for every target in the link implementation.  This will be useful to
de-duplicate such evaluation for each usage requirement separately.

The new method will soon be used in the implementation of the
INTERFACE_* usage requirement lookup methods (GetSourceFiles,
GetCompileOptions, GetCompileDefinitions, GetCompileFeatures,
GetIncludeDirectories).  It is necessary for these methods to determine
whether an expression in LinkImplementationPropertyEntries evaluates to
a target or not because generator expression evaluation reports an error
for non-targets and we construct a $<TARGET_PROPERTY:tgt,INTERFACE_XYZ>
expression for each entry that is a target.

The implementation of each usage requirement currently processes the
LinkImplementationPropertyEntries and evaluates all generator
expressions to determine targets.  That is no longer necessary because
GetLinkImplementationLibraries now returns resolved and cached targets
together with their name.  Use it to implement AddInterfaceEntries.
Brad King 11 tahun lalu
induk
melakukan
363cd33ebe
1 mengubah file dengan 29 tambahan dan 0 penghapusan
  1. 29 0
      Source/cmTarget.cxx

+ 29 - 0
Source/cmTarget.cxx

@@ -181,6 +181,10 @@ public:
   std::vector<TargetPropertyEntry*> SourceEntries;
   std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
 
+  void AddInterfaceEntries(
+    cmTarget const* thisTarget, std::string const& config,
+    std::string const& prop, std::vector<TargetPropertyEntry*>& entries);
+
   std::map<std::string, std::vector<TargetPropertyEntry*> >
                         CachedLinkInterfaceIncludeDirectoriesEntries;
   std::map<std::string, std::vector<TargetPropertyEntry*> >
@@ -6549,6 +6553,31 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
   iface.Complete = true;
 }
 
+//----------------------------------------------------------------------------
+void cmTargetInternals::AddInterfaceEntries(
+  cmTarget const* thisTarget, std::string const& config,
+  std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
+{
+  if(cmTarget::LinkImplementation const* impl =
+     thisTarget->GetLinkImplementationLibraries(config))
+    {
+    for (std::vector<cmLinkImplItem>::const_iterator
+           it = impl->Libraries.begin(), end = impl->Libraries.end();
+         it != end; ++it)
+      {
+      if(it->Target)
+        {
+        std::string genex =
+          "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
+        cmGeneratorExpression ge(&it->Backtrace);
+        cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
+        entries.push_back(
+          new cmTargetInternals::TargetPropertyEntry(cge, *it));
+        }
+      }
+    }
+}
+
 //----------------------------------------------------------------------------
 cmTarget::LinkImplementation const*
 cmTarget::GetLinkImplementation(const std::string& config) const