diff options
author | Brad King <brad.king@kitware.com> | 2024-09-26 12:47:39 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-09-26 12:47:47 (GMT) |
commit | 53f3e5da1e6bc15baedb1053976b677909564c6f (patch) | |
tree | 7cfd690d8ca0577ed7b1c30471a1e053cc39f746 /Help | |
parent | 8d69aa79b059c9b6145de04458088a6e1e700837 (diff) | |
parent | 7abd3137b74543cf698ac6c7290696d82042e7de (diff) | |
download | CMake-53f3e5da1e6bc15baedb1053976b677909564c6f.zip CMake-53f3e5da1e6bc15baedb1053976b677909564c6f.tar.gz CMake-53f3e5da1e6bc15baedb1053976b677909564c6f.tar.bz2 |
Merge topic 'link-strategy'
7abd3137b7 Linking: Optionally reorder direct dependencies from LINK_LIBRARIES
9285a9dc9a cmComputeLinkDepends: Add final dependency ordering to debug output
f792db4ca2 cmComputeLinkDepends: Add undocumented per-target debug property
80b469a51d cmComputeLinkDepends: Factor out string literals as named constants
3bd73fcc76 cmComputeLinkDepends: Modernize member initialization
8db69c767b cmComputeLinkDepends: Remove redundant member
dccdd030cd cmComputeLinkDepends: Replace depender index sentinel value with cm::optional
6c9d8dc243 cmComputeLinkDepends: Replace group index sentinel value with cm::optional
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9835
Diffstat (limited to 'Help')
-rw-r--r-- | Help/command/target_link_libraries.rst | 5 | ||||
-rw-r--r-- | Help/manual/cmake-properties.7.rst | 1 | ||||
-rw-r--r-- | Help/manual/cmake-variables.7.rst | 1 | ||||
-rw-r--r-- | Help/prop_tgt/LINK_LIBRARIES.rst | 5 | ||||
-rw-r--r-- | Help/prop_tgt/LINK_LIBRARIES_STRATEGY.rst | 11 | ||||
-rw-r--r-- | Help/release/dev/link-strategy.rst | 7 | ||||
-rw-r--r-- | Help/variable/CMAKE_LINK_LIBRARIES_STRATEGY.rst | 68 |
7 files changed, 98 insertions, 0 deletions
diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst index a82adda..94a2429 100644 --- a/Help/command/target_link_libraries.rst +++ b/Help/command/target_link_libraries.rst @@ -140,6 +140,11 @@ Items containing ``::``, such as ``Foo::Bar``, are assumed to be target names and will cause an error if no such target exists. See policy :policy:`CMP0028`. +See the :variable:`CMAKE_LINK_LIBRARIES_STRATEGY` variable and +corresponding :prop_tgt:`LINK_LIBRARIES_STRATEGY` target property +for details on how CMake orders direct link dependencies on linker +command lines. + See the :manual:`cmake-buildsystem(7)` manual for more on defining buildsystem properties. diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 9ad856d..10dbe10 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -336,6 +336,7 @@ Properties on Targets /prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG /prop_tgt/LINK_LIBRARIES /prop_tgt/LINK_LIBRARIES_ONLY_TARGETS + /prop_tgt/LINK_LIBRARIES_STRATEGY /prop_tgt/LINK_LIBRARY_OVERRIDE /prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY /prop_tgt/LINK_OPTIONS diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index e0358db..4d92339 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -491,6 +491,7 @@ Variables that Control the Build /variable/CMAKE_LINK_GROUP_USING_FEATURE /variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED /variable/CMAKE_LINK_INTERFACE_LIBRARIES + /variable/CMAKE_LINK_LIBRARIES_STRATEGY /variable/CMAKE_LINK_LIBRARY_FEATURE_ATTRIBUTES /variable/CMAKE_LINK_LIBRARY_FILE_FLAG /variable/CMAKE_LINK_LIBRARY_FLAG diff --git a/Help/prop_tgt/LINK_LIBRARIES.rst b/Help/prop_tgt/LINK_LIBRARIES.rst index b5c1d89..b449aa1 100644 --- a/Help/prop_tgt/LINK_LIBRARIES.rst +++ b/Help/prop_tgt/LINK_LIBRARIES.rst @@ -28,3 +28,8 @@ In advanced use cases, the list of direct link dependencies specified by this property may be updated by usage requirements from dependencies. See the :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` and :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE` target properties. + +See the :variable:`CMAKE_LINK_LIBRARIES_STRATEGY` variable and +corresponding :prop_tgt:`LINK_LIBRARIES_STRATEGY` target property +for details on how CMake orders direct link dependencies on linker +command lines. diff --git a/Help/prop_tgt/LINK_LIBRARIES_STRATEGY.rst b/Help/prop_tgt/LINK_LIBRARIES_STRATEGY.rst new file mode 100644 index 0000000..bba707c --- /dev/null +++ b/Help/prop_tgt/LINK_LIBRARIES_STRATEGY.rst @@ -0,0 +1,11 @@ +LINK_LIBRARIES_STRATEGY +----------------------- + +.. versionadded:: 3.31 + +Specify a strategy for ordering a target's direct link dependencies +on linker command lines. + +See the :variable:`CMAKE_LINK_LIBRARIES_STRATEGY` variable for details +and supported values. This property is initialized by the value of that +variable when a target is created. diff --git a/Help/release/dev/link-strategy.rst b/Help/release/dev/link-strategy.rst new file mode 100644 index 0000000..ab626d1 --- /dev/null +++ b/Help/release/dev/link-strategy.rst @@ -0,0 +1,7 @@ +link-strategy +------------- + +* The :variable:`CMAKE_LINK_LIBRARIES_STRATEGY` variable and + corresponding :prop_tgt:`LINK_LIBRARIES_STRATEGY` target + property were added to optionally specify the strategy + CMake uses to generate link lines. diff --git a/Help/variable/CMAKE_LINK_LIBRARIES_STRATEGY.rst b/Help/variable/CMAKE_LINK_LIBRARIES_STRATEGY.rst new file mode 100644 index 0000000..1ba6b27 --- /dev/null +++ b/Help/variable/CMAKE_LINK_LIBRARIES_STRATEGY.rst @@ -0,0 +1,68 @@ +CMAKE_LINK_LIBRARIES_STRATEGY +----------------------------- + +.. versionadded:: 3.31 + +Specify a strategy for ordering targets' direct link dependencies +on linker command lines. + +The value of this variable initializes the :prop_tgt:`LINK_LIBRARIES_STRATEGY` +target property of targets as they are created. Set that property directly +to specify a strategy for a single target. + +CMake generates a target's link line using its :ref:`Target Link Properties`. +In particular, the :prop_tgt:`LINK_LIBRARIES` target property records the +target's direct link dependencies, typically populated by calls to +:command:`target_link_libraries`. Indirect link dependencies are +propagated from those entries of :prop_tgt:`LINK_LIBRARIES` that name +library targets by following the transitive closure of their +:prop_tgt:`INTERFACE_LINK_LIBRARIES` properties. CMake supports multiple +strategies for passing direct and indirect link dependencies to the linker. + +Consider this example for the strategies below: + +.. code-block:: cmake + + add_library(A STATIC ...) + add_library(B STATIC ...) + add_library(C STATIC ...) + add_executable(main ...) + target_link_libraries(B PRIVATE A) + target_link_libraries(C PRIVATE A) + target_link_libraries(main PRIVATE A B C) + +The supported strategies are: + +``PRESERVE_ORDER`` + Entries of :prop_tgt:`LINK_LIBRARIES` always appear first and in their + original order. Indirect link dependencies not satisfied by the + original entries may be reordered and de-duplicated with respect to + one another, but are always appended after the original entries. + This may result in less efficient link lines, but gives projects + control of ordering among independent entries. Such control may be + important when intermixing link flags with libraries, or when multiple + libraries provide a given symbol. + + This is the default. + + In the above example, this strategy computes a link line for ``main`` + by starting with its original entries ``A B C``, and then appends + another ``A`` to satisfy the dependencies of ``B`` and ``C`` on ``A``. + The final order is ``A B C A``. + +``REORDER`` + Entries of :prop_tgt:`LINK_LIBRARIES` may be reordered, de-duplicated, + and intermixed with indirect link dependencies. This may result in + more efficient link lines, but does not give projects any control of + ordering among independent entries. + + In the above example, this strategy computes a link line for ``main`` + by re-ordering its original entries ``A B C`` to satisfy the + dependencies of ``B`` and ``C`` on ``A``. + The final order is ``B C A``. + +.. note:: + + Regardless of the strategy used, the actual linker invocation for + some platforms may de-duplicate entries based on linker capabilities. + See policy :policy:`CMP0156`. |