summaryrefslogtreecommitdiffstats
path: root/Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2022-07-03 04:50:33 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-07-03 04:50:44 (GMT)
commit2a336d855443d7db601bd79e80fce86726962cd2 (patch)
tree51a21089ba1810b9ad1f1d91570997fb942301ec /Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst
parent32014390465669fe4ead629a79447c9996c7dee5 (diff)
parentd185f7c0a8cac19edaea8d54c2a12b51a622731b (diff)
downloadCMake-2a336d855443d7db601bd79e80fce86726962cd2.zip
CMake-2a336d855443d7db601bd79e80fce86726962cd2.tar.gz
CMake-2a336d855443d7db601bd79e80fce86726962cd2.tar.bz2
Merge topic 'doc-LINK_LIBRARY_genex' into release-3.24
d185f7c0a8 Help: Rework $<LINK_LIBRARY>, $<LINK_GROUP> and related docs Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !7413
Diffstat (limited to 'Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst')
-rw-r--r--Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst50
1 files changed, 28 insertions, 22 deletions
diff --git a/Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst b/Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst
index 112f614..4d3dd4f 100644
--- a/Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst
+++ b/Help/prop_tgt/LINK_LIBRARY_OVERRIDE_LIBRARY.rst
@@ -3,43 +3,49 @@ LINK_LIBRARY_OVERRIDE_<LIBRARY>
.. versionadded:: 3.24
-To resolve incompatible features introduced by :genex:`LINK_LIBRARY` generator
-expression, this property offers the possibility to override, for a
-``link-item`` (``CMake`` target or external library) involved in the link step,
-any defined features with a new one.
+Override the library feature associated with ``<LIBRARY>`` from
+:genex:`LINK_LIBRARY` generator expressions. This can be used to resolve
+incompatible library features that result from specifying different features
+for ``<LIBRARY>`` in different :genex:`LINK_LIBRARY` generator expressions.
-This property takes a ``feature`` name which will be applied to the
-``link-item`` specified by ``<LIBRARY>`` suffix property. For example:
+When set on a target, this property holds a single library feature name, which
+will be applied to ``<LIBRARY>`` when linking that target.
.. code-block:: cmake
add_library(lib1 ...)
- target_link_libraries(lib1 PUBLIC "$<LINK_LIBRARY:feature1,external>")
-
add_library(lib2 ...)
- target_link_libraries(lib2 PUBLIC "$<LINK_LIBRARY:feature2,lib1>")
-
add_library(lib3 ...)
+
+ target_link_libraries(lib1 PUBLIC "$<LINK_LIBRARY:feature1,external>")
+ target_link_libraries(lib2 PUBLIC "$<LINK_LIBRARY:feature2,lib1>")
target_link_libraries(lib3 PRIVATE lib1 lib2)
- # Here, lib1 has two different features which prevents to link lib3
- # So, define LINK_LIBRARY_OVERRIDE_lib1 property to ensure correct link
+
+ # lib1 is associated with both feature2 and no feature. Without any override,
+ # this would result in a fatal error at generation time for lib3.
+ # Define an override to resolve the incompatible feature associations.
set_property(TARGET lib3 PROPERTY LINK_LIBRARY_OVERRIDE_lib1 feature2)
- # The lib1 will be used with feature2 to link lib3
-It is also possible to override any feature with the pre-defined feature
-``DEFAULT`` to get the standard behavior (i.e. no feature):
+ # lib1 will now be associated with feature2 instead when linking lib3
+
+It is also possible to override any feature with the pre-defined ``DEFAULT``
+library feature. This effectively discards any feature for that link item,
+for that target only (``lib3`` in this example):
.. code-block:: cmake
+ # When linking lib3, discard any library feature for lib1
set_property(TARGET lib3 PROPERTY LINK_LIBRARY_OVERRIDE_lib1 DEFAULT)
- # The lib1 will be used without any feature to link lib3
+
+See the :prop_tgt:`LINK_LIBRARY_OVERRIDE` target property for an alternative
+way of overriding library features for multiple libraries at once. If both
+properties are defined and specify an override for the same link item,
+``LINK_LIBRARY_OVERRIDE_<LIBRARY>`` takes precedence over
+:prop_tgt:`LINK_LIBRARY_OVERRIDE`.
Contents of ``LINK_LIBRARY_OVERRIDE_<LIBRARY>`` may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
-This property takes precedence over :prop_tgt:`LINK_LIBRARY_OVERRIDE`
-target property.
-
-For more information about features, see
-:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>`
-and :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>` variables.
+For more information about library features, see the
+:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>` and
+:variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>` variables.