From 7071cb42fa657e791d8084eff4d0978c5028bc9a Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 20 Oct 2021 11:59:56 -0400 Subject: [PATCH] [cmake] add USE_ASAN option to build with addresssanitizer --- CMakeLists.txt | 6 ++++++ INSTALL.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1d2ef75d..2ecd88b84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ include(FeatureSummary) ###################### USER-SELECTABLE OPTIONS ########################### # BUILD_TESTING is defined by CTest option(DFSG_BUILD "DFSG build (no non-free media/code)" OFF) +option(USE_ASAN "Build with AddressSanitizer" OFF) option(USE_COVERAGE "Assess code coverage with llvm-cov/lcov" OFF) option(USE_CPP "Build C++ code" ON) cmake_dependent_option( @@ -118,6 +119,11 @@ endif() add_compile_options(-Wall -Wextra -W -Wshadow) add_compile_options(-ffast-math -fexceptions -fstrict-aliasing) +if(${USE_ASAN}) +add_compile_options(-fsanitize=address) +add_link_options(-fsanitize=address) +endif() + # don't use REQUIRED with subsequent find_package() operations; we use # feature_summary + set_package_properties to fail in one fell swoop. find_package(Threads) diff --git a/INSTALL.md b/INSTALL.md index 86b063c45..b596db736 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -95,6 +95,7 @@ but must be `Debug` for use of `USE_COVERAGE`. * `DFSG_BUILD`: leave out all content considered non-free under the Debian Free Software Guidelines * `BUILD_TESTING`: build test targets +* `USE_ASAN`: build with AddressSanitizer * `USE_CPP`: build C++ code (requires a C++ compiler) * `USE_COVERAGE`: build coverage support (for developers, requires use of Clang) * `USE_DOCTEST`: build `notcurses-tester` with Doctest, requires `BUILD_TESTING`