summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-08-10 12:58:25 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-08-10 12:58:34 (GMT)
commit1233da9f4a6f1c9c7fdc4b051bbdf745b7830ba1 (patch)
tree7fd149a37f932a525f472fe547732b009e9b5c96
parentb47b44630ba14a8cd748bee06f47645862451506 (diff)
parent84eae7aedab558a12ab009b390f74bef011a3b1b (diff)
downloadCMake-1233da9f4a6f1c9c7fdc4b051bbdf745b7830ba1.zip
CMake-1233da9f4a6f1c9c7fdc4b051bbdf745b7830ba1.tar.gz
CMake-1233da9f4a6f1c9c7fdc4b051bbdf745b7830ba1.tar.bz2
Merge topic 'OPTIMIZE_DEPENDENCIES-runtime-targets'
84eae7aeda OPTIMIZE_DEPENDENCIES: Skip order-only deps for non-linking targets Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8685
-rw-r--r--Source/cmGeneratorTarget.cxx5
-rw-r--r--Source/cmGeneratorTarget.h1
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx8
-rw-r--r--Source/cmTarget.cxx18
-rw-r--r--Source/cmTarget.h1
-rw-r--r--Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/DependencyGraph/RuntimeTargets.cmake18
-rw-r--r--Tests/RunCMake/DependencyGraph/bottom.c7
-rw-r--r--Tests/RunCMake/DependencyGraph/middle.c9
-rw-r--r--Tests/RunCMake/DependencyGraph/neverbuild.c1
-rw-r--r--Tests/RunCMake/DependencyGraph/top.c9
11 files changed, 76 insertions, 3 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 8f1818d..eb4ba90 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -1224,6 +1224,11 @@ bool cmGeneratorTarget::IsNormal() const
return this->Target->IsNormal();
}
+bool cmGeneratorTarget::IsRuntimeBinary() const
+{
+ return this->Target->IsRuntimeBinary();
+}
+
bool cmGeneratorTarget::IsSynthetic() const
{
return this->Target->IsSynthetic();
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 3de9b17..a32e742 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -51,6 +51,7 @@ public:
bool IsInBuildSystem() const;
bool IsNormal() const;
+ bool IsRuntimeBinary() const;
bool IsSynthetic() const;
bool IsImported() const;
bool IsImportedGloballyVisible() const;
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index e41a0c3..089498b 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -1469,9 +1469,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
gt, linkBuild.OrderOnlyDeps, config, fileConfig, DependOnTargetArtifact);
// Add order-only dependencies on versioning symlinks of shared libs we link.
- if (!this->GeneratorTarget->IsDLLPlatform()) {
- if (cmComputeLinkInformation* cli =
- this->GeneratorTarget->GetLinkInformation(config)) {
+ // If our target is not producing a runtime binary, it doesn't need the
+ // symlinks (anything that links to the target might, but that consumer will
+ // get its own order-only dependency).
+ if (!gt->IsDLLPlatform() && gt->IsRuntimeBinary()) {
+ if (cmComputeLinkInformation* cli = gt->GetLinkInformation(config)) {
for (auto const& item : cli->GetItems()) {
if (item.Target &&
item.Target->GetType() == cmStateEnums::SHARED_LIBRARY &&
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 593a019..7cc5d2e 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -2652,6 +2652,24 @@ bool cmTarget::IsPerConfig() const
return this->impl->PerConfig;
}
+bool cmTarget::IsRuntimeBinary() const
+{
+ switch (this->GetType()) {
+ case cmStateEnums::EXECUTABLE:
+ case cmStateEnums::SHARED_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
+ return true;
+ case cmStateEnums::OBJECT_LIBRARY:
+ case cmStateEnums::STATIC_LIBRARY:
+ case cmStateEnums::UTILITY:
+ case cmStateEnums::INTERFACE_LIBRARY:
+ case cmStateEnums::GLOBAL_TARGET:
+ case cmStateEnums::UNKNOWN_LIBRARY:
+ break;
+ }
+ return false;
+}
+
bool cmTarget::CanCompileSources() const
{
if (this->IsImported()) {
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 7c10295..dae997f 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -212,6 +212,7 @@ public:
bool IsImported() const;
bool IsImportedGloballyVisible() const;
bool IsPerConfig() const;
+ bool IsRuntimeBinary() const;
bool CanCompileSources() const;
bool GetMappedConfig(std::string const& desired_config, cmValue& loc,
diff --git a/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake b/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake
index 891e138..6847a23 100644
--- a/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake
+++ b/Tests/RunCMake/DependencyGraph/RunCMakeTest.cmake
@@ -59,3 +59,5 @@ run_optimize_test(OptimizeStatic StaticTop)
if(CMAKE_Fortran_COMPILER)
run_optimize_test(OptimizeFortran FortranTop)
endif()
+
+run_cmake_build(RuntimeTargets mylib SharedTop)
diff --git a/Tests/RunCMake/DependencyGraph/RuntimeTargets.cmake b/Tests/RunCMake/DependencyGraph/RuntimeTargets.cmake
new file mode 100644
index 0000000..21531cd
--- /dev/null
+++ b/Tests/RunCMake/DependencyGraph/RuntimeTargets.cmake
@@ -0,0 +1,18 @@
+enable_language(C)
+
+set(CMAKE_OPTIMIZE_DEPENDENCIES TRUE)
+add_library(mylib STATIC mylib.c)
+add_library(neverbuild SHARED neverbuild.c)
+
+# Building mylib should not require building neverbuild
+target_link_libraries(mylib PRIVATE neverbuild)
+set_target_properties(neverbuild PROPERTIES EXCLUDE_FROM_ALL YES)
+
+# Building SharedTop should require SharedBottom to be built
+add_library(SharedTop SHARED top.c)
+add_library(StaticMiddle STATIC middle.c)
+add_library(SharedBottom SHARED bottom.c)
+target_link_libraries(SharedTop PRIVATE StaticMiddle)
+target_link_libraries(StaticMiddle PRIVATE SharedBottom)
+set_target_properties(StaticMiddle SharedBottom PROPERTIES EXCLUDE_FROM_ALL YES)
+set_target_properties(StaticMiddle PROPERTIES POSITION_INDEPENDENT_CODE YES)
diff --git a/Tests/RunCMake/DependencyGraph/bottom.c b/Tests/RunCMake/DependencyGraph/bottom.c
new file mode 100644
index 0000000..c8ea481
--- /dev/null
+++ b/Tests/RunCMake/DependencyGraph/bottom.c
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ int bottom(void)
+{
+ return 23;
+}
diff --git a/Tests/RunCMake/DependencyGraph/middle.c b/Tests/RunCMake/DependencyGraph/middle.c
new file mode 100644
index 0000000..3b1b84c
--- /dev/null
+++ b/Tests/RunCMake/DependencyGraph/middle.c
@@ -0,0 +1,9 @@
+#ifdef _WIN32
+__declspec(dllimport)
+#endif
+ int bottom(void);
+
+int middle(void)
+{
+ return bottom() + 19;
+}
diff --git a/Tests/RunCMake/DependencyGraph/neverbuild.c b/Tests/RunCMake/DependencyGraph/neverbuild.c
new file mode 100644
index 0000000..e490510
--- /dev/null
+++ b/Tests/RunCMake/DependencyGraph/neverbuild.c
@@ -0,0 +1 @@
+#error I should not be built
diff --git a/Tests/RunCMake/DependencyGraph/top.c b/Tests/RunCMake/DependencyGraph/top.c
new file mode 100644
index 0000000..eceb0a5
--- /dev/null
+++ b/Tests/RunCMake/DependencyGraph/top.c
@@ -0,0 +1,9 @@
+int middle(void);
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ int top(void)
+{
+ return middle() + 2;
+}