Browse Source

Merge topic 'module-depends-static-lib-cycle'

01d7860fdb Ninja,Makefile: Restore Fortran module scanning in static library cycle
846baa7c5b cmGlobalGenerator: Factor out helper to check target ordering

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !8363
Brad King 2 năm trước cách đây
mục cha
commit
367aa65a9f

+ 3 - 0
Source/cmCommonTargetGenerator.cxx

@@ -165,6 +165,7 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
 {
   std::vector<std::string> dirs;
   std::set<cmGeneratorTarget const*> emitted;
+  cmGlobalCommonGenerator* const gg = this->GlobalCommonGenerator;
   if (cmComputeLinkInformation* cli =
         this->GeneratorTarget->GetLinkInformation(config)) {
     cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
@@ -172,6 +173,8 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories(
       cmGeneratorTarget const* linkee = item.Target;
       if (linkee &&
           !linkee->IsImported()
+          // Skip targets that build after this one in a static lib cycle.
+          && gg->TargetOrderIndexLess(linkee, this->GeneratorTarget)
           // We can ignore the INTERFACE_LIBRARY items because
           // Target->GetLinkInformation already processed their
           // link interface and they don't have any output themselves.

+ 7 - 2
Source/cmGlobalGenerator.cxx

@@ -1727,8 +1727,7 @@ cmGlobalGenerator::GetLocalGeneratorTargetsInOrder(cmLocalGenerator* lg) const
   cm::append(gts, lg->GetGeneratorTargets());
   std::sort(gts.begin(), gts.end(),
             [this](cmGeneratorTarget const* l, cmGeneratorTarget const* r) {
-              return this->TargetOrderIndex.at(l) <
-                this->TargetOrderIndex.at(r);
+              return this->TargetOrderIndexLess(l, r);
             });
   return gts;
 }
@@ -3068,6 +3067,12 @@ cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target)
   return this->TargetDependencies[target];
 }
 
+bool cmGlobalGenerator::TargetOrderIndexLess(cmGeneratorTarget const* l,
+                                             cmGeneratorTarget const* r) const
+{
+  return this->TargetOrderIndex.at(l) < this->TargetOrderIndex.at(r);
+}
+
 bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
 {
   // The following is a list of targets reserved

+ 5 - 0
Source/cmGlobalGenerator.h

@@ -479,6 +479,11 @@ public:
   TargetDependSet const& GetTargetDirectDepends(
     const cmGeneratorTarget* target);
 
+  // Return true if target 'l' occurs before 'r' in a global ordering
+  // of targets that respects inter-target dependencies.
+  bool TargetOrderIndexLess(cmGeneratorTarget const* l,
+                            cmGeneratorTarget const* r) const;
+
   const std::map<std::string, std::vector<cmLocalGenerator*>>& GetProjectMap()
     const
   {

+ 1 - 0
Tests/FortranModules/Executable/CMakeLists.txt

@@ -6,3 +6,4 @@ add_executable(subdir_exe2 main.f90)
 target_link_libraries(subdir_exe2 subdir_mods subdir_mods2)
 add_dependencies(subdir_exe2 ExternalTarget)
 target_link_libraries(subdir_exe2 myext)
+target_link_libraries(subdir_exe2 cycleA)

+ 4 - 0
Tests/FortranModules/Executable/main.f90

@@ -3,5 +3,9 @@ PROGRAM MAINF90
   USE libraryModuleB
   USE subdirModuleA
   USE externalMod
+  USE libraryCycleA
+  USE libraryCycleB
   CALL printExtModGreeting
+  CALL libraryCycleA2
+  CALL libraryCycleB2
 END PROGRAM MAINF90

+ 6 - 1
Tests/FortranModules/Library/CMakeLists.txt

@@ -3,9 +3,14 @@ add_library(subdir_mods a.f90 b.f90)
 add_executable(subdir_exe main.f90)
 target_link_libraries(subdir_exe subdir_mods)
 
+add_library(cycleA STATIC cycleA1.f90 cycleA2.f90)
+add_library(cycleB STATIC cycleB1.f90 cycleB2.f90)
+target_link_libraries(cycleA PRIVATE cycleB)
+target_link_libraries(cycleB PRIVATE cycleA)
+
 # Test module output directory if available.
 if(CMAKE_Fortran_MODDIR_FLAG)
-  set_target_properties(subdir_mods PROPERTIES
+  set_target_properties(subdir_mods cycleA cycleB PROPERTIES
     Fortran_MODULE_DIRECTORY modules
     )
 endif()

+ 3 - 0
Tests/FortranModules/Library/cycleA1.f90

@@ -0,0 +1,3 @@
+subroutine cycleA1
+use libraryCycleA
+end subroutine

+ 5 - 0
Tests/FortranModules/Library/cycleA2.f90

@@ -0,0 +1,5 @@
+module libraryCycleA
+contains
+  subroutine libraryCycleA2
+  end subroutine
+end module

+ 3 - 0
Tests/FortranModules/Library/cycleB1.f90

@@ -0,0 +1,3 @@
+subroutine cycleB1
+use libraryCycleB
+end subroutine

+ 5 - 0
Tests/FortranModules/Library/cycleB2.f90

@@ -0,0 +1,5 @@
+module libraryCycleB
+contains
+  subroutine libraryCycleB2
+  end subroutine
+end module