From c4b3f46af893e7f9067c6f4c63c901af52edfe6c Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Sat, 30 Oct 2021 18:04:33 +0100 Subject: [PATCH] cmake: Allow to build clazy with ASAN/UBSAN For clazy's own development only --- CMakeLists.txt | 8 ++++++++ CMakePresets.json | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e649bfe..6daa6f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,14 @@ option(CLAZY_AST_MATCHERS_CRASH_WORKAROUND "Disable AST Matchers if being built option(LINK_CLAZY_TO_LLVM "Links the clazy plugin to LLVM. Switch to OFF if your clang binary has all symbols already. Might need to be OFF if your LLVM is static." ON) option(APPIMAGE_HACK "Links the clazy plugin to the clang tooling libs only. For some reason this is needed when building on our old CentOS 6.8 to create the AppImage." OFF) option(CLAZY_MAN_PAGE "Builds the man page." ON) +option(CLAZY_ENABLE_SANITIZERS "Builds clazy with ASAN/UBSAN. For clazy's own development only." OFF) + +if (CLAZY_ENABLE_SANITIZERS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + if (NOT MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + endif() +endif() if (CLAZY_AST_MATCHERS_CRASH_WORKAROUND AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") message("Enabling AST Matchers workaround. Consider building with gcc instead. See bug #392223.") diff --git a/CMakePresets.json b/CMakePresets.json index f1ec4772..6e0071f7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -12,6 +12,18 @@ "CMAKE_EXPORT_COMPILE_COMMANDS" : "ON" } }, + { + "name": "dev-asan", + "displayName": "dev-asan", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build-dev-asan", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CLAZY_MAN_PAGE" : "OFF", + "CMAKE_EXPORT_COMPILE_COMMANDS" : "ON", + "CLAZY_ENABLE_SANITIZERS" : "ON" + } + }, { "name": "profile", "displayName": "profile",