LINK_LIBRARIES_STRATEGY: Rename strategies to clarify expectations

Since commit 7abd3137b7 (Linking: Optionally reorder direct dependencies
from LINK_LIBRARIES, 2024-09-19, v3.31.0-rc1~53^2) the strategy name
`PRESERVE_ORDER` has led users to expect that it strictly preserves
order.  While the part of the link line generation logic controlled by
`LINK_LIBRARIES_STRATEGY` does preserve order, it is not the last step.
Toolchain-specific de-duplication can cause the order to change on the
actual link line generated in the build system.

Rename the strategies:

* `PRESERVE_ORDER` => `REORDER_MINIMALLY`
* `REORDER`        => `REORDER_FREELY`

The new names make it clear that reordering is always possible, just to
varying degrees.  Update the `LINK_LIBRARIES_STRATEGY` documentation to
clarify that the strategies do not directly control the final link line.

Fixes: #26400
Issue: #26271
This commit is contained in:
Brad King
2024-10-25 09:53:57 -04:00
parent ebd038613e
commit 39fd396421
27 changed files with 32 additions and 29 deletions

View File

@@ -1521,14 +1521,14 @@ void cmComputeLinkDepends::OrderLinkEntries()
// Start with the original link line.
switch (this->Strategy) {
case LinkLibrariesStrategy::PRESERVE_ORDER: {
case LinkLibrariesStrategy::REORDER_MINIMALLY: {
// Emit the direct dependencies in their original order.
// This gives projects control over ordering.
for (size_t originalEntry : this->OriginalEntries) {
this->VisitEntry(originalEntry);
}
} break;
case LinkLibrariesStrategy::REORDER: {
case LinkLibrariesStrategy::REORDER_FREELY: {
// Schedule the direct dependencies for emission in topo order.
// This may produce more efficient link lines.
for (size_t originalEntry : this->OriginalEntries) {

View File

@@ -29,8 +29,8 @@ class cmake;
enum class LinkLibrariesStrategy
{
PRESERVE_ORDER,
REORDER,
REORDER_MINIMALLY,
REORDER_FREELY,
};
/** \class cmComputeLinkDepends

View File

@@ -568,12 +568,12 @@ bool cmComputeLinkInformation::Compute()
return false;
}
LinkLibrariesStrategy strategy = LinkLibrariesStrategy::PRESERVE_ORDER;
LinkLibrariesStrategy strategy = LinkLibrariesStrategy::REORDER_MINIMALLY;
if (cmValue s = this->Target->GetProperty("LINK_LIBRARIES_STRATEGY")) {
if (*s == "PRESERVE_ORDER"_s) {
strategy = LinkLibrariesStrategy::PRESERVE_ORDER;
} else if (*s == "REORDER"_s) {
strategy = LinkLibrariesStrategy::REORDER;
if (*s == "REORDER_MINIMALLY"_s) {
strategy = LinkLibrariesStrategy::REORDER_MINIMALLY;
} else if (*s == "REORDER_FREELY"_s) {
strategy = LinkLibrariesStrategy::REORDER_FREELY;
} else {
this->CMakeInstance->IssueMessage(
MessageType::FATAL_ERROR,