HomePhabricator

[CMAKE] Use CMake built-in to set PIC and PIE

Description

[CMAKE] Use CMake built-in to set PIC and PIE

Summary:
This diff makes proper use of the cmake POSITION_INDEPENDENT_CODE
property to enforce building PIC/PIE.
Because this property does not enforce PIE before version 3.14, the
previous method is kept as a fallback, so the behavior is unchanged.

Test Plan:

mkdir buildcmake && cd buildcmake
cmake -GNinja ..
ninja check-security

Check there is no error with both cmake < 3.14 and >= 3.14.

Check it works when cross building for windows (no PIC nor PIE
required), requires D4155 to succeed:

rm -rf *
cmake -GNinja .. -DBUILD_BITCOIN_SEEDER=OFF \
  -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Win64.cmake
ninja check-security

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

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

Details

Provenance
FabienAuthored on Sep 26 2019, 13:05
FabienPushed on Sep 30 2019, 10:57
Reviewer
Restricted Project
Differential Revision
D4156: [CMAKE] Use CMake built-in to set PIC and PIE
Parents
rABCa456acd71455: [CMAKE] Fix check-security to allow running on windows executables
Branches
Unknown
Tags
Unknown