Page MenuHomePhabricator

[CMAKE] Check for linker flag support
ClosedPublic

Authored by Fabien on Mar 6 2019, 14:18.

Details

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.

Diff Detail

Repository
rABC Bitcoin ABC
Branch
cmake_check_linker_flags
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 5201
Build 8465: Bitcoin ABC Buildbot (legacy)
Build 8464: arc lint + arc unit

Event Timeline

This revision is now accepted and ready to land.Mar 12 2019, 20:15
This revision was automatically updated to reflect the committed changes.