CMAKE_<LANG>_LINK_LIBRARY_<FEATURE>_PROPERTIES¶
New in version 3.30.
This variable defines the semantics of the specified <FEATURE> for the
language <LANG> (as described by the
CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE> or
CMAKE_LINK_LIBRARY_USING_<FEATURE> variables) used for the link
command generation.
Feature Properties Definition¶
A feature properties definition is a
semicolon-separated list of property=value(s)
items. In the case of multiple values can be specified, they are separated by
a comma.
The following properties are supported:
LIBRARY_TYPE=<library_type-list>Specify which library types are supported by this feature. The possible values are:
STATIC,SHARED,MODULEorEXECUTABLE.If this property is not specified, the default is
LIBRARY_TYPE=STATIC,SHARED,MODULE,EXECUTABLE.If the feature is used with an unsupported library type, CMake will emit a developer warning and the feature will be ignored.
OVERRIDE=<feature-list>Specify which features will be replaced by this one in the event of a conflict. This override mechanism is superseded by any
LINK_LIBRARY_OVERRIDEorLINK_LIBRARY_OVERRIDE_<LIBRARY>target properties definitions.If this property is not specified, the default is an empty list.
UNICITY=YES|NO|DEFAULTManage the strategy of de-duplication for the libraries using this feature.
YESLibraries are de-duplicated regardless the default strategy applied by CMake.
NOLibraries are not de-duplicated regardless the default strategy applied by CMake.
DEFAULTApply the default CMake strategy.
If this property is not specified,
DEFAULTwill be used.
Example¶
A common need is the loading of a full archive as part of the creation of a
shared library or an executable. For that purpose, the WHOLE_ARCHIVE
feature can be used.
Currently, the associated properties with this feature are defined as follows:
set(CMAKE_LINK_LIBRARY_WHOLE_ARCHIVE_PROPERTIES LIBRARY_TYPE=STATIC
OVERRIDE=DEFAULT
UNICITY=YES)
LIBRARY_TYPE=STATICObviously, this feature is only meaningful for static libraries.
OVERRIDE=DEFAULTThe
DEFAULTfeature will be overridden by theWHOLE_ARCHIVEfeature because they are compatible and enhance the user's experience: standard library specification and$<LINK_LIBRARY:WHOLE_ARCHIVE>can be used freely.UNICITY=YESWhen this feature is used, all symbols from the static library are loaded by the linker, so there is no need to duplicate the library on the link command.
A typical usage of the WHOLE_ARCHIVE can be:
add_library(A STATIC ...)
add_library(B STATIC ...)
target_link_libraries(B PUBLIC A)
target_link_libraries(A PUBLIC B)
add_library(global SHARED ...)
target_link_libraries(global PRIVATE $<LINK_LIBRARY:WHOLE_ARCHIVE,A>)
The resulting link command will only have one iteration of the A library
specified with the needed linker flags to ensure the load of all the symbols
of the library.