summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-27 13:51:45 +0000
committerKitware Robot <kwrobot@kitware.com>2023-03-27 09:51:58 -0400
commit381327c944dc60ccc418e110c5afee85462cfea4 (patch)
tree82783869aace757d4bfd1480b63e5c5f1dc9aa63
parentfae6e8c2cdb5ce6049439f4defd1367b507d1e4b (diff)
parent01d7860fdb078dae5198056930e8cfd2ce532d84 (diff)
downloadcmake-381327c944dc60ccc418e110c5afee85462cfea4.tar.gz
Merge topic 'module-depends-static-lib-cycle' into release-3.26
01d7860fdb Ninja,Makefile: Restore Fortran module scanning in static library cycle 846baa7c5b cmGlobalGenerator: Factor out helper to check target ordering Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8363
-rw-r--r--Source/cmCommonTargetGenerator.cxx3
-rw-r--r--Source/cmGlobalGenerator.cxx9
-rw-r--r--Source/cmGlobalGenerator.h5
-rw-r--r--Tests/FortranModules/Executable/CMakeLists.txt1
-rw-r--r--Tests/FortranModules/Executable/main.f904
-rw-r--r--Tests/FortranModules/Library/CMakeLists.txt7
-rw-r--r--Tests/FortranModules/Library/cycleA1.f903
-rw-r--r--Tests/FortranModules/Library/cycleA2.f905
-rw-r--r--Tests/FortranModules/Library/cycleB1.f903
-rw-r--r--Tests/FortranModules/Library/cycleB2.f905
10 files changed, 42 insertions, 3 deletions
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index a065ba9499..6be0fa329c 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -164,6 +164,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();
@@ -171,6 +172,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.
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 4cfec22587..b55fcb8504 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1719,8 +1719,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;
}
@@ -3060,6 +3059,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
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 66ab752dc1..f4862a0ef9 100644
--- a/Source/cmGlobalGenerator.h
+++ b/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
{
diff --git a/Tests/FortranModules/Executable/CMakeLists.txt b/Tests/FortranModules/Executable/CMakeLists.txt
index f31a3e65f7..182e23a7ac 100644
--- a/Tests/FortranModules/Executable/CMakeLists.txt
+++ b/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)
diff --git a/Tests/FortranModules/Executable/main.f90 b/Tests/FortranModules/Executable/main.f90
index 640259c124..218eee6c6b 100644
--- a/Tests/FortranModules/Executable/main.f90
+++ b/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
diff --git a/Tests/FortranModules/Library/CMakeLists.txt b/Tests/FortranModules/Library/CMakeLists.txt
index 17438cafbb..e525208dd3 100644
--- a/Tests/FortranModules/Library/CMakeLists.txt
+++ b/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()
diff --git a/Tests/FortranModules/Library/cycleA1.f90 b/Tests/FortranModules/Library/cycleA1.f90
new file mode 100644
index 0000000000..cceebe2e5f
--- /dev/null
+++ b/Tests/FortranModules/Library/cycleA1.f90
@@ -0,0 +1,3 @@
+subroutine cycleA1
+use libraryCycleA
+end subroutine
diff --git a/Tests/FortranModules/Library/cycleA2.f90 b/Tests/FortranModules/Library/cycleA2.f90
new file mode 100644
index 0000000000..a2e432ea7a
--- /dev/null
+++ b/Tests/FortranModules/Library/cycleA2.f90
@@ -0,0 +1,5 @@
+module libraryCycleA
+contains
+ subroutine libraryCycleA2
+ end subroutine
+end module
diff --git a/Tests/FortranModules/Library/cycleB1.f90 b/Tests/FortranModules/Library/cycleB1.f90
new file mode 100644
index 0000000000..d6680fa33b
--- /dev/null
+++ b/Tests/FortranModules/Library/cycleB1.f90
@@ -0,0 +1,3 @@
+subroutine cycleB1
+use libraryCycleB
+end subroutine
diff --git a/Tests/FortranModules/Library/cycleB2.f90 b/Tests/FortranModules/Library/cycleB2.f90
new file mode 100644
index 0000000000..07c774e0fe
--- /dev/null
+++ b/Tests/FortranModules/Library/cycleB2.f90
@@ -0,0 +1,5 @@
+module libraryCycleB
+contains
+ subroutine libraryCycleB2
+ end subroutine
+end module