HomePhabricator

[CMAKE] Allow to use sanitizers with cmake

Description

[CMAKE] Allow to use sanitizers with cmake

Summary:
To use any sanitizer(s), add it to the ENABLE_SANITIZERS list on
the CMake command line.
Examples:

cmake -GNinja .. -DENABLE_SANITIZERS=undefined
cmake -GNinja .. -DENABLE_SANITIZERS=address;leak

This requires an additional dependency to work:

ECM (Extra Cmake Modules, https://api.kde.org/ecm/index.html)

To install on Debian/Ubuntu:

sudo apt install extra-cmake-modules

This dependency is only required if the ENABLE_SANITIZERS variable
is set, it is not necessary to do a standard build.

The ECM package will check for compiler compatibility and set the
appropriated options for each sanitizer. It will eventually remove the
optimization options that may conflict with the selected sanitizers.

Test Plan:
With ECM *not* installed:

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

The build should be successful.

rm -rf *
cmake -GNinja .. -DENABLE_SANITIZERS=undefined

CMake should return en error:

ECM is required to enable the sanitizers

(https://api.kde.org/ecm/index.html)

Install ECM (instructions for Debian/Ubuntu):

sudo apt install extra-cmake-modules

Then

rm -rf *
cmake -GNinja .. -DENABLE_SANITIZERS=undefined
ninja -v

The build should enable the sanitizer (check the build commands for
-fsanitize=undefined)

rm -rf *
cmake -GNinja .. -DENABLE_SANITIZERS="address;leak"

Note: if you need to disable assembly instructions, add
-DUSE_ASM_X86_64=OFF to the CMake command line.

ninja -v

The build should enable the sanitizers (check the build commands for
-fsanitize=address and -fsanitize=leak)

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

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

Details

Provenance
FabienAuthored on May 3 2019, 12:16
deadalnixPushed on May 16 2019, 11:47
Reviewer
Restricted Project
Differential Revision
D3041: [CMAKE] Allow to use sanitizers with cmake
Parents
rSTAGING116f9831e6c5: [CMAKE] Fix missing protobuf include directory
Branches
Unknown
Tags
Unknown