[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