summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2022-03-10 15:54:43 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2022-03-17 22:07:59 (GMT)
commitdabe56de58a32768f0dff740f83539ab8337b132 (patch)
tree1804ac7f935f1344ffeca22388d3e07d85d3350f
parent3a37fda6a2b4f28fdd7efe58f4a0b7570404a7d4 (diff)
downloadCMake-dabe56de58a32768f0dff740f83539ab8337b132.zip
CMake-dabe56de58a32768f0dff740f83539ab8337b132.tar.gz
CMake-dabe56de58a32768f0dff740f83539ab8337b132.tar.bz2
genex-LINK_LIBRARY: Add feature WHOLE_ARCHIVE
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst4
-rw-r--r--Help/release/dev/LINK_LIBRARY-WHOLE_ARCHIVE.rst14
-rw-r--r--Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.txt18
-rw-r--r--Help/variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt18
-rw-r--r--Modules/Platform/CYGWIN-GNU.cmake28
-rw-r--r--Modules/Platform/Darwin.cmake8
-rw-r--r--Modules/Platform/FreeBSD.cmake27
-rw-r--r--Modules/Platform/Linux.cmake25
-rw-r--r--Modules/Platform/NetBSD.cmake27
-rw-r--r--Modules/Platform/SunOS.cmake14
-rw-r--r--Modules/Platform/Windows-Clang.cmake7
-rw-r--r--Modules/Platform/Windows-GNU.cmake25
-rw-r--r--Modules/Platform/Windows-MSVC.cmake9
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake14
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LIBRARY/feature-WHOLE_ARCHIVE.cmake11
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LIBRARY/load_archive.cmake34
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LIBRARY/whole_archive.cmake34
17 files changed, 268 insertions, 49 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index 2394eb2..b79cf3a 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -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,
diff --git a/Help/release/dev/LINK_LIBRARY-WHOLE_ARCHIVE.rst b/Help/release/dev/LINK_LIBRARY-WHOLE_ARCHIVE.rst
new file mode 100644
index 0000000..abaf3a9
--- /dev/null
+++ b/Help/release/dev/LINK_LIBRARY-WHOLE_ARCHIVE.rst
@@ -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``
diff --git a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.txt b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.txt
index ad393b0..ec293d3 100644
--- a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.txt
+++ b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.txt
@@ -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()
diff --git a/Help/variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt b/Help/variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt
index 936bd31..e4fa0ed8 100644
--- a/Help/variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt
+++ b/Help/variable/LINK_LIBRARY_PREDEFINED_FEATURES.txt
@@ -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
diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake
index b81bd4d..ef64012 100644
--- a/Modules/Platform/CYGWIN-GNU.cmake
+++ b/Modules/Platform/CYGWIN-GNU.cmake
@@ -14,6 +14,34 @@ string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,--enable-auto-import")
set(CMAKE_GNULD_IMAGE_VERSION
"-Wl,--major-image-version,<TARGET_VERSION_MAJOR>,--minor-image-version,<TARGET_VERSION_MINOR>")
set(CMAKE_GENERATOR_RC windres)
+
+
+# Features for LINK_LIBRARY generator expression
+## check linker capabilities
+if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE __linker_help
+ ERROR_VARIABLE __linker_help)
+ if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
+ else()
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
+ endif()
+ unset(__linker_help)
+endif()
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
+
macro(__cygwin_compiler_gnu lang)
# Binary link rules.
set(CMAKE_${lang}_CREATE_SHARED_MODULE
diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake
index a27bb36..ec88a37 100644
--- a/Modules/Platform/Darwin.cmake
+++ b/Modules/Platform/Darwin.cmake
@@ -108,7 +108,7 @@ foreach(lang C CXX Fortran OBJC OBJCXX)
set(CMAKE_${lang}_FRAMEWORK_SEARCH_FLAG -F)
endforeach()
-# Defines link features for frameworks
+# Defines LINK_LIBRARY features for frameworks
set(CMAKE_LINK_LIBRARY_USING_FRAMEWORK "LINKER:-framework,<LIBRARY>")
set(CMAKE_LINK_LIBRARY_USING_FRAMEWORK_SUPPORTED TRUE)
@@ -121,7 +121,7 @@ set(CMAKE_LINK_LIBRARY_USING_REEXPORT_FRAMEWORK_SUPPORTED TRUE)
set(CMAKE_LINK_LIBRARY_USING_WEAK_FRAMEWORK "LINKER:-weak_framework,<LIBRARY>")
set(CMAKE_LINK_LIBRARY_USING_WEAK_FRAMEWORK_SUPPORTED TRUE)
-# Defines link features for libraries
+# Defines LINK_LIBRARY features for libraries
set(CMAKE_LINK_LIBRARY_USING_NEEDED_LIBRARY "PATH{LINKER:-needed_library <LIBRARY>}NAME{LINKER:-needed-l<LIB_ITEM>}")
set(CMAKE_LINK_LIBRARY_USING_NEEDED_LIBRARY_SUPPORTED TRUE)
@@ -131,6 +131,10 @@ set(CMAKE_LINK_LIBRARY_USING_REEXPORT_LIBRARY_SUPPORTED TRUE)
set(CMAKE_LINK_LIBRARY_USING_WEAK_LIBRARY "PATH{LINKER:-weak_library <LIBRARY>}NAME{LINKER:-weak-l<LIB_ITEM>}")
set(CMAKE_LINK_LIBRARY_USING_WEAK_LIBRARY_SUPPORTED TRUE)
+# Defines LINK_LIBRARY feature to Force loading of all members of an archive
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:-force_load <LIB_ITEM>")
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
# default to searching for frameworks first
if(NOT DEFINED CMAKE_FIND_FRAMEWORK)
set(CMAKE_FIND_FRAMEWORK FIRST)
diff --git a/Modules/Platform/FreeBSD.cmake b/Modules/Platform/FreeBSD.cmake
index 4a4c00d..4c8cb6a 100644
--- a/Modules/Platform/FreeBSD.cmake
+++ b/Modules/Platform/FreeBSD.cmake
@@ -26,4 +26,31 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Wl,-Bdynamic")
endforeach()
+
+# Features for LINK_LIBRARY generator expression
+## check linker capabilities
+if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE __linker_help
+ ERROR_VARIABLE __linker_help)
+ if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
+ else()
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
+ endif()
+ unset(__linker_help)
+endif()
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
+
include(Platform/UnixPaths)
diff --git a/Modules/Platform/Linux.cmake b/Modules/Platform/Linux.cmake
index 95102e1..a7e58ab 100644
--- a/Modules/Platform/Linux.cmake
+++ b/Modules/Platform/Linux.cmake
@@ -20,6 +20,31 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
endforeach()
+# Features for LINK_LIBRARY generator expression
+## check linker capabilities
+if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE __linker_help
+ ERROR_VARIABLE __linker_help)
+ if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
+ else()
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
+ endif()
+ unset(__linker_help)
+endif()
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
# Features for LINK_GROUP generator expression
## RESCAN: request the linker to rescan static libraries until there is
## no pending undefined symbols
diff --git a/Modules/Platform/NetBSD.cmake b/Modules/Platform/NetBSD.cmake
index d99cb4a..8774159 100644
--- a/Modules/Platform/NetBSD.cmake
+++ b/Modules/Platform/NetBSD.cmake
@@ -12,4 +12,31 @@ set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+
+# Features for LINK_LIBRARY generator expression
+## check linker capabilities
+if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE __linker_help
+ ERROR_VARIABLE __linker_help)
+ if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
+ else()
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
+ endif()
+ unset(__linker_help)
+endif()
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
+
include(Platform/UnixPaths)
diff --git a/Modules/Platform/SunOS.cmake b/Modules/Platform/SunOS.cmake
index e01e892..b8a302c 100644
--- a/Modules/Platform/SunOS.cmake
+++ b/Modules/Platform/SunOS.cmake
@@ -8,6 +8,20 @@ if(CMAKE_SYSTEM MATCHES "SunOS-4")
endif()
+# Features for LINK_LIBRARY generator expression
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if (CMAKE_SYSTEM_VERSION VERSION_GREATER "5.10")
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:-z,allextract"
+ "<LINK_ITEM>"
+ "LINKER:-z,defaultextract")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
+
# Features for LINK_GROUP generator expression
if (CMAKE_SYSTEM_VERSION VERSION_GREATER "5.9")
## RESCAN: request the linker to rescan static libraries until there is
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index e7e975d..7600c8d 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -113,6 +113,13 @@ macro(__windows_compiler_clang_gnu lang)
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER)
set(CMAKE_${lang}_STANDARD_LIBRARIES_INIT "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames")
+ # Features for LINK_LIBRARY generator expression
+ if(MSVC_VERSION GREATER "1900")
+ ## WHOLE_ARCHIVE: Force loading all members of an archive
+ set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:/WHOLEARCHIVE:<LIBRARY>")
+ set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+ endif()
+
enable_language(RC)
endmacro()
diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake
index 3c24c21..b464169 100644
--- a/Modules/Platform/Windows-GNU.cmake
+++ b/Modules/Platform/Windows-GNU.cmake
@@ -45,6 +45,31 @@ if("${_help}" MATCHES "GNU ld .* 2\\.1[1-6]")
endif()
+# Features for LINK_LIBRARY generator expression
+## check linker capabilities
+if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE __linker_help
+ ERROR_VARIABLE __linker_help)
+ if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state")
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state")
+ else()
+ set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state")
+ endif()
+ unset(__linker_help)
+endif()
+## WHOLE_ARCHIVE: Force loading all members of an archive
+if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED)
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+else()
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+endif()
+set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+
# Features for LINK_GROUP generator expression
## RESCAN: request the linker to rescan static libraries until there is
## no pending undefined symbols
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index b2cc6f4..e74ec9e 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -331,6 +331,15 @@ else()
endif()
unset(__WINDOWS_MSVC_CMP0091)
+
+# Features for LINK_LIBRARY generator expression
+if(MSVC_VERSION GREATER "1900")
+ ## WHOLE_ARCHIVE: Force loading all members of an archive
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "/WHOLEARCHIVE:<LIBRARY>")
+ set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
+endif()
+
+
macro(__windows_compiler_msvc lang)
if(NOT MSVC_VERSION LESS 1400)
# for 2005 make sure the manifest is put in the dll with mt
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake
index 349310f..021de41 100644
--- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/RunCMakeTest.cmake
@@ -67,8 +67,8 @@ if ((RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Xcode"
if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
OR (CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER "1900")
OR (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux"))
- run_cmake(whole_archive)
- run_cmake_target(whole_archive link-exe main)
+ run_cmake(load_archive)
+ run_cmake_target(load_archive link-exe main)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
run_cmake(weak_library)
@@ -110,3 +110,13 @@ endif()
if (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION GREATER_EQUAL "12")
run_cmake_target(apple_library needed_library main-needed_library)
endif()
+
+# WHOLE_ARCHIVE feature
+if ((CMAKE_SYSTEM_NAME STREQUAL "Windows" AND
+ ((DEFINED MSVC_VERSION AND MSVC_VERSION GREATER "1900") OR (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND NOT CMAKE_C_SIMULATE_ID STREQUAL "MSVC")))
+ OR (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND
+ (NOT CMAKE_C_COMPILER_ID STREQUAL "SunPro" OR CMAKE_C_COMPILER_VERSION GREATER "5.9"))
+ OR CMAKE_SYSTEM_NAME MATCHES "Darwin|iOS|tvOS|watchOS|Linux|BSD|MSYS|CYGWIN")
+ run_cmake(feature-WHOLE_ARCHIVE)
+ run_cmake_target(feature-WHOLE_ARCHIVE link-exe main)
+endif()
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/feature-WHOLE_ARCHIVE.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/feature-WHOLE_ARCHIVE.cmake
new file mode 100644
index 0000000..e525325
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/feature-WHOLE_ARCHIVE.cmake
@@ -0,0 +1,11 @@
+
+enable_language(C)
+
+add_library(base STATIC base.c unref.c)
+target_compile_definitions(base PUBLIC STATIC_BASE)
+
+add_library(lib SHARED lib.c)
+target_link_libraries(lib PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,base>")
+
+add_executable(main main.c)
+target_link_libraries(main PRIVATE lib)
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/load_archive.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/load_archive.cmake
new file mode 100644
index 0000000..a0bbb43
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/load_archive.cmake
@@ -0,0 +1,34 @@
+
+enable_language(C)
+
+set(CMAKE_C_LINK_LIBRARY_USING_load_archive_SUPPORTED TRUE)
+if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
+ 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")
+ execute_process(COMMAND "${CMAKE_LINKER}" --help
+ OUTPUT_VARIABLE linker_help
+ ERROR_VARIABLE linker_help)
+ if(linker_help MATCHES "--push-state" AND linker_help MATCHES "--pop-state")
+ set(CMAKE_C_LINK_LIBRARY_USING_load_archive "LINKER:--push-state,--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--pop-state")
+ else()
+ set(CMAKE_C_LINK_LIBRARY_USING_load_archive "LINKER:--whole-archive"
+ "<LINK_ITEM>"
+ "LINKER:--no-whole-archive")
+ endif()
+elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ 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_load_archive_SUPPORTED FALSE)
+endif()
+
+add_library(base STATIC base.c unref.c)
+target_compile_definitions(base PUBLIC STATIC_BASE)
+
+add_library(lib SHARED lib.c)
+target_link_libraries(lib PRIVATE "$<LINK_LIBRARY:load_archive,base>")
+
+add_executable(main main.c)
+target_link_libraries(main PRIVATE lib)
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/whole_archive.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/whole_archive.cmake
deleted file mode 100644
index 93082a4..0000000
--- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/whole_archive.cmake
+++ /dev/null
@@ -1,34 +0,0 @@
-
-enable_language(C)
-
-set(CMAKE_C_LINK_LIBRARY_USING_whole_archive_SUPPORTED TRUE)
-if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
- set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "-force_load <LIB_ITEM>")
-elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
- execute_process(COMMAND "${CMAKE_LINKER}" --help
- OUTPUT_VARIABLE linker_help
- ERROR_VARIABLE linker_help)
- if(linker_help MATCHES "--push-state" AND linker_help MATCHES "--pop-state")
- set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "LINKER:--push-state,--whole-archive"
- "<LINK_ITEM>"
- "LINKER:--pop-state")
- else()
- set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "LINKER:--whole-archive"
- "<LINK_ITEM>"
- "LINKER:--no-whole-archive")
- endif()
-elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
- set(CMAKE_C_LINK_LIBRARY_USING_whole_archive "/WHOLEARCHIVE:<LIBRARY>")
-else()
- # feature not yet supported for the other environments
- set(CMAKE_C_LINK_LIBRARY_USING_whole_archive_SUPPORTED FALSE)
-endif()
-
-add_library(base STATIC base.c unref.c)
-target_compile_definitions(base PUBLIC STATIC_BASE)
-
-add_library(lib SHARED lib.c)
-target_link_libraries(lib PRIVATE "$<LINK_LIBRARY:whole_archive,base>")
-
-add_executable(main main.c)
-target_link_libraries(main PRIVATE lib)