浏览代码

cmCommonTargetGenerator: use modules from linked object-referenced targets

Fortran modules provided by objects added as linked items via
`$<TARGET_OBJECTS>` should also be considered as "linked targets" for
collation purposes. As C++ modules have their own visibility rules
through their `FILE_SET` feature, do not expose these for C++ module
collation.
Ben Boeckel 1 年之前
父节点
当前提交
7cd0adab1b
共有 2 个文件被更改,包括 15 次插入1 次删除
  1. 12 1
      Source/cmCommonTargetGenerator.cxx
  2. 3 0
      Source/cmMakefile.cxx

+ 12 - 1
Source/cmCommonTargetGenerator.cxx

@@ -211,7 +211,18 @@ cmCommonTargetGenerator::GetLinkedTargetDirectories(
         }
       };
     for (auto const& item : cli->GetItems()) {
-      addLinkedTarget(item.Target, Forwarding::No);
+      if (item.Target) {
+        addLinkedTarget(item.Target, Forwarding::No);
+      } else if (item.ObjectSource && lang == "Fortran"_s
+                 /* Object source files do not have a language associated with
+                    them. */
+                 /* && item.ObjectSource->GetLanguage() == "Fortran"_s*/) {
+        // Fortran modules provided by `$<TARGET_OBJECTS>` as linked items
+        // should be collated for use in this target.
+        addLinkedTarget(this->LocalCommonGenerator->FindGeneratorTargetToUse(
+                          item.ObjectSource->GetObjectLibrary()),
+                        Forwarding::Yes);
+      }
     }
     for (cmGeneratorTarget const* target : cli->GetExternalObjectTargets()) {
       addLinkedTarget(target, Forwarding::No);

+ 3 - 0
Source/cmMakefile.cxx

@@ -3630,6 +3630,9 @@ void cmMakefile::AddTargetObject(std::string const& tgtName,
     this->GetOrCreateSource(objFile, true, cmSourceFileLocationKind::Known);
   sf->SetObjectLibrary(tgtName);
   sf->SetProperty("EXTERNAL_OBJECT", "1");
+  // TODO: Compute a language for this object based on the associated source
+  // file that compiles to it. Needs a policy as it likely affects link
+  // language selection if done unconditionally.
 #if !defined(CMAKE_BOOTSTRAP)
   this->SourceGroups[this->ObjectLibrariesSourceGroupIndex].AddGroupFile(
     sf->ResolveFullPath());