mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-08 07:10:12 -05:00
genex-LINK_LIBRARY: Add feature WHOLE_ARCHIVE
This commit is contained in:
@@ -1125,9 +1125,9 @@ Output-Related Expressions
|
||||
|
||||
add_library(lib1 STATIC ...)
|
||||
add_library(lib2 ...)
|
||||
target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:whole_archive,lib1>")
|
||||
target_link_libraries(lib2 PRIVATE "$<LINK_LIBRARY:load_archive,lib1>")
|
||||
|
||||
This specify to use the ``lib1`` target with feature ``whole_archive`` for
|
||||
This specify to use the ``lib1`` target with feature ``load_archive`` for
|
||||
linking target ``lib2``. The feature must have be defined by
|
||||
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>` variable or, if
|
||||
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` is false,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
LINK_LIBRARY-WHOLE_ARCHIVE
|
||||
--------------------------
|
||||
|
||||
* The :genex:`LINK_LIBRARY` generator expression gained the feature
|
||||
``WHOLE_ARCHIVE`` to force load of all members in a static library. This
|
||||
feature is supported on the following target platforms:
|
||||
|
||||
* all ``Apple`` variants
|
||||
* ``Linux``
|
||||
* all ``BSD`` variants
|
||||
* ``SunOS``
|
||||
* ``Windows``
|
||||
* ``CYGWIN``
|
||||
* ``MSYS``
|
||||
@@ -46,27 +46,27 @@ is offered by various environments but with a specific syntax:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_whole_archive_SUPPORTED TRUE)
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_load_archive_SUPPORTED TRUE)
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "-force_load <LIB_ITEM>")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_load_archive "-force_load <LIB_ITEM>")
|
||||
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU"
|
||||
AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "LINKER:--push-state,--whole-archive"
|
||||
"<LINK_ITEM>"
|
||||
"LINKER:--pop-state")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_load_archive "LINKER:--push-state,--whole-archive"
|
||||
"<LINK_ITEM>"
|
||||
"LINKER:--pop-state")
|
||||
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "/WHOLEARCHIVE:<LIBRARY>")
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_load_archive "/WHOLEARCHIVE:<LIBRARY>")
|
||||
else()
|
||||
# feature not yet supported for the other environments
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_whole_archive_SUPPORTED FALSE)
|
||||
set(CMAKE_C_LINK_LIBRARY_USING_load_archive_SUPPORTED FALSE)
|
||||
endif()
|
||||
|
||||
add_library(lib1 STATIC ...)
|
||||
|
||||
add_library(lib2 SHARED ...)
|
||||
if(CMAKE_C_LINK_LIBRARY_USING_whole_archive_SUPPORTED)
|
||||
if(CMAKE_C_LINK_LIBRARY_USING_load_archive_SUPPORTED)
|
||||
target_link_libraries(lib2 PRIVATE
|
||||
"$<LINK_LIBRARY:whole_archive,lib1,$<IF:$<LINK_LANG_AND_ID:C,Clang>,libexternal.a,external>>")
|
||||
"$<LINK_LIBRARY:load_archive,lib1,$<IF:$<LINK_LANG_AND_ID:C,Clang>,libexternal.a,external>>")
|
||||
else()
|
||||
target_link_libraries(lib2 PRIVATE lib1 external)
|
||||
endif()
|
||||
|
||||
@@ -5,6 +5,24 @@
|
||||
useful with :prop_tgt:`LINK_LIBRARY_OVERRIDE` and
|
||||
:prop_tgt:`LINK_LIBRARY_OVERRIDE_<LIBRARY>` target properties.
|
||||
|
||||
**Features available for a subset of environments**
|
||||
|
||||
``WHOLE_ARCHIVE``
|
||||
Force load of all members in a static library.
|
||||
|
||||
Target platforms supported: all ``Apple`` variants, ``Linux``, all ``BSD``
|
||||
variants, ``SunOS``, ``Windows``, ``CYGWIN``, and ``MSYS``.
|
||||
|
||||
Platform-specific notes:
|
||||
|
||||
* On Apple platforms, the library must be specified as a CMake target name, a
|
||||
library file name (such as ``libfoo.a``), or a library file path (such as
|
||||
``/path/to/libfoo.a``). It cannot be specified as a plain library name
|
||||
(such as ``foo``, where ``foo`` is not CMake target), due to a limitation
|
||||
in the Apple linker.
|
||||
* On Windows platforms, for ``MSVC`` or MSVC-like toolchains, the version
|
||||
must be greater than ``1900``.
|
||||
|
||||
**Features available in Apple environments**
|
||||
|
||||
It is assumed that the linker used is the one provided by `XCode` or is
|
||||
|
||||
Reference in New Issue
Block a user