summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-10-03 12:06:27 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-10-03 12:06:39 (GMT)
commit1ee630e06fcce4bf62f8c141eb3cdc2419c9545a (patch)
tree52626e7adb3e71004d155a22ad751cdd64152de4 /Source
parent31db1a047e5911f4eda14a044910fe1e4e2baa61 (diff)
parentcd418d4bb62bbcc805bd734a01f5b0737292cc88 (diff)
downloadCMake-1ee630e06fcce4bf62f8c141eb3cdc2419c9545a.zip
CMake-1ee630e06fcce4bf62f8c141eb3cdc2419c9545a.tar.gz
CMake-1ee630e06fcce4bf62f8c141eb3cdc2419c9545a.tar.bz2
Merge topic 'static-libraries-deduplication'
cd418d4bb6 Static libraries de-duplication: keep first occurrence 9b5c805bf6 Tests/RunCMake/LinkLibrariesStrategy: Check ordering results more strongly Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !9864
Diffstat (limited to 'Source')
-rw-r--r--Source/cmComputeLinkDepends.cxx65
-rw-r--r--Source/cmPolicies.h9
2 files changed, 70 insertions, 4 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 70e992e..5d92549 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -381,6 +381,34 @@ public:
target->GetBacktrace());
CM_FALLTHROUGH;
case cmPolicies::NEW: {
+ // Policy 0179 applies only when policy 0156 is new
+ switch (target->GetPolicyStatusCMP0179()) {
+ case cmPolicies::WARN:
+ if (!makefile->GetCMakeInstance()->GetIsInTryCompile() &&
+ makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0179")) {
+ makefile->GetCMakeInstance()->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0179),
+ "\nSince the policy is not set, static libraries "
+ "de-duplication will keep the last occurrence of the "
+ "static libraries."),
+ target->GetBacktrace());
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ makefile->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0179),
+ target->GetBacktrace());
+ CM_FALLTHROUGH;
+ case cmPolicies::NEW:
+ break;
+ }
+
if (auto libProcessing = makefile->GetDefinition(cmStrCat(
"CMAKE_", linkLanguage, "_LINK_LIBRARIES_PROCESSING"))) {
// UNICITY keyword is just for compatibility with previous
@@ -444,9 +472,42 @@ public:
void AddLibraries(const std::vector<size_t>& libEntries)
{
if (this->Order == Reverse) {
+ std::vector<size_t> entries;
+ if (this->Deduplication == All &&
+ this->Target->GetPolicyStatusCMP0179() == cmPolicies::NEW) {
+ // keep the first occurrence of the static libraries
+ std::set<size_t> emitted{ this->Emitted };
+ std::set<std::string> importedEmitted;
+ for (auto index : libEntries) {
+ LinkEntry const& entry = this->Entries[index];
+ if (!entry.Target ||
+ entry.Target->GetType() != cmStateEnums::STATIC_LIBRARY) {
+ entries.emplace_back(index);
+ continue;
+ }
+ if (this->IncludeEntry(entry)) {
+ entries.emplace_back(index);
+ continue;
+ }
+ if (entry.Target->IsImported()) {
+ if (emitted.insert(index).second &&
+ importedEmitted
+ .insert(cmSystemTools::GetRealPath(entry.Item.Value))
+ .second) {
+ entries.emplace_back(index);
+ }
+ continue;
+ }
+ if (emitted.insert(index).second) {
+ entries.emplace_back(index);
+ }
+ }
+ } else {
+ entries = libEntries;
+ }
// Iterate in reverse order so we can keep only the last occurrence
- // of a library.
- this->AddLibraries(cmReverseRange(libEntries));
+ // of the shared libraries.
+ this->AddLibraries(cmReverseRange(entries));
} else {
this->AddLibraries(cmMakeRange(libEntries));
}
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index e2254fe..55fce2e 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -545,7 +545,11 @@ class cmMakefile;
SELECT(POLICY, CMP0177, "install() DESTINATION paths are normalized.", 3, \
31, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0178, "Test command lines preserve empty arguments.", 3, \
- 31, 0, cmPolicies::WARN)
+ 31, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0179, \
+ "De-duplication of static libraries on link lines keeps first " \
+ "occurrence.", \
+ 3, 31, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -589,7 +593,8 @@ class cmMakefile;
F(CMP0156) \
F(CMP0157) \
F(CMP0160) \
- F(CMP0162)
+ F(CMP0162) \
+ F(CMP0179)
#define CM_FOR_EACH_CUSTOM_COMMAND_POLICY(F) \
F(CMP0116) \