mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 03:29:18 -05:00
Merge topic 'LINK_LIBRARY-WHOLE_ARCHIVE'
dabe56de58 genex-LINK_LIBRARY: Add feature WHOLE_ARCHIVE
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: huangqinjin <huangqinjin@gmail.com>
Merge-request: !7064
This commit is contained in:
@@ -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