mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 06:47:08 -05:00
c8f4ae9ccf
d5be7c7f31Linker: Detect GNU push-state/pop-state flags more robustly7b552b9a64Linker: Save GNU push-/pop-state detection with compiler inspection resultsa9b126b0daLinker: Save linker inspection results with compiler inspection results3f5f2b2d49Linker: Honor CMAKE_<LANG>_LINK_LIBRARY_USING_FEATURE_SUPPORTED when FALSE Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !10468
49 lines
2.1 KiB
CMake
49 lines
2.1 KiB
CMake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
# file LICENSE.rst or https://cmake.org/licensing for details.
|
|
|
|
|
|
# This module is shared by multiple languages; use include blocker.
|
|
include_guard()
|
|
|
|
# WHOLE_ARCHIVE Feature for LINK_LIBRARY generator expression
|
|
## check linker capabilities
|
|
function(__cmake_set_whole_archive_feature __linker)
|
|
unset(__lang)
|
|
if(ARGC EQUAL "2")
|
|
set(__lang "${ARGV1}_")
|
|
endif()
|
|
|
|
if(NOT __linker)
|
|
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE)
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED)
|
|
# launch linker to check if push_state/pop_state options are supported
|
|
execute_process(COMMAND "${__linker}" --push-state --pop-state
|
|
OUTPUT_VARIABLE __linker_log
|
|
ERROR_VARIABLE __linker_log)
|
|
if(__linker_log MATCHES "--push-state" OR __linker_log MATCHES "--pop-state")
|
|
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE)
|
|
else()
|
|
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE)
|
|
endif()
|
|
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED ${CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED} PARENT_SCOPE)
|
|
endif()
|
|
## WHOLE_ARCHIVE: Force loading all members of an archive
|
|
if(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED)
|
|
set(CMAKE_${__lang}LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive"
|
|
"<LINK_ITEM>"
|
|
"LINKER:--pop-state" PARENT_SCOPE)
|
|
else()
|
|
set(CMAKE_${__lang}LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive"
|
|
"<LINK_ITEM>"
|
|
"LINKER:--no-whole-archive" PARENT_SCOPE)
|
|
endif()
|
|
set(CMAKE_${__lang}LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE PARENT_SCOPE)
|
|
set(CMAKE_${__lang}LINK_LIBRARY_WHOLE_ARCHIVE_ATTRIBUTES LIBRARY_TYPE=STATIC DEDUPLICATION=YES OVERRIDE=DEFAULT PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
|
|
## Configure system linker
|
|
__cmake_set_whole_archive_feature("${CMAKE_LINKER}")
|