HomePhabricator

[CMAKE] Check for linker flag support

Description

[CMAKE] Check for linker flag support

Summary:
CMake provides no facility to test wheter a linker flag is supported by
the compiler or not. However the CMP0056 policy (Cmake 3.2) enforces
passing the CMAKE_EXE_LINKER_FLAGS to the try_compile() function.
This offers a workaround for testing linker flag validity before adding
them, which is implemented in this diff.

Depends on D2653

Test Plan:
In src/CMakeLists.txt replace the line add_linker_flag(-pie) with
add_linker_flag(-pie -foo).
Then:

mkdir buildcmake && cd buildcmake
cmake -GNinja ..
ninja -v

Cmake should output a Performing Test have_linker_foo - Failed line.
Check that the -pie flag is passed on the linker command line but not
the -foo flag.

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: teamcity, schancel

Differential Revision: https://reviews.bitcoinabc.org/D2657

Details

Provenance
FabienAuthored on Mar 6 2019, 14:08
FabienPushed on Mar 13 2019, 13:51
Reviewer
Restricted Project
Differential Revision
D2657: [CMAKE] Check for linker flag support
Parents
rSTAGINGb49e26b77037: [CMAKE] Fix cached variable that prevents testing for flag support
Branches
Unknown
Tags
Unknown