mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Merge d3f42fa08f
into 66aa6a47bd
This commit is contained in:
commit
6a9b4394a9
2 changed files with 32 additions and 10 deletions
|
@ -186,16 +186,8 @@ string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}")
|
||||||
|
|
||||||
set(configure_warnings)
|
set(configure_warnings)
|
||||||
|
|
||||||
include(CheckPIESupported)
|
include(CheckLinkerSupportsPIE)
|
||||||
check_pie_supported(OUTPUT_VARIABLE check_pie_output LANGUAGES CXX)
|
check_linker_supports_pie(configure_warnings)
|
||||||
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
||||||
elseif(NOT WIN32)
|
|
||||||
# The warning is superfluous for Windows.
|
|
||||||
message(WARNING "PIE is not supported at link time: ${check_pie_output}")
|
|
||||||
list(APPEND configure_warnings "Position independent code disabled.")
|
|
||||||
endif()
|
|
||||||
unset(check_pie_output)
|
|
||||||
|
|
||||||
# The core_interface library aims to encapsulate common build flags.
|
# The core_interface library aims to encapsulate common build flags.
|
||||||
# It is a usage requirement for all targets except for secp256k1, which
|
# It is a usage requirement for all targets except for secp256k1, which
|
||||||
|
|
30
cmake/module/CheckLinkerSupportsPIE.cmake
Normal file
30
cmake/module/CheckLinkerSupportsPIE.cmake
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Copyright (c) 2024-present The Bitcoin Core developers
|
||||||
|
# Distributed under the MIT software license, see the accompanying
|
||||||
|
# file COPYING or https://opensource.org/license/mit/.
|
||||||
|
|
||||||
|
include_guard(GLOBAL)
|
||||||
|
|
||||||
|
function(check_linker_supports_pie warnings)
|
||||||
|
# This forces running a linker.
|
||||||
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
|
||||||
|
|
||||||
|
# Workaround for a bug in the check_pie_supported() function.
|
||||||
|
# See:
|
||||||
|
# - https://gitlab.kitware.com/cmake/cmake/-/issues/26463
|
||||||
|
# - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10034
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.32)
|
||||||
|
# CMAKE_CXX_COMPILE_OPTIONS_PIE is a list, whereas CMAKE_REQUIRED_FLAGS
|
||||||
|
# must be a string. Therefore, a proper conversion is required.
|
||||||
|
list(JOIN CMAKE_CXX_COMPILE_OPTIONS_PIE " " CMAKE_REQUIRED_FLAGS)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CheckPIESupported)
|
||||||
|
check_pie_supported(OUTPUT_VARIABLE output LANGUAGES CXX)
|
||||||
|
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE)
|
||||||
|
elseif(NOT WIN32)
|
||||||
|
# The warning is superfluous for Windows.
|
||||||
|
message(WARNING "PIE is not supported at link time: ${output}")
|
||||||
|
set(${warnings} ${${warnings}} "Position independent code disabled." PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
Loading…
Reference in a new issue