From 717c01c7ddcfde9384bb265d719ab8a9789f18fc Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Tue, 2 Jul 2019 08:03:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BB=D0=B0=D0=B3=D0=B8=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=B0=D0=BC=D1=8F=D1=82=D0=B8=20=D0=B8=20=D0=BF=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMLibCommon.cmake | 1 + CMLibSanitizers.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 CMLibSanitizers.cmake diff --git a/CMLibCommon.cmake b/CMLibCommon.cmake index b7f1415..5a69215 100644 --- a/CMLibCommon.cmake +++ b/CMLibCommon.cmake @@ -34,6 +34,7 @@ include(CMLibCodeAnalysisPvsStudio) include(CMLibCodeAnalysisClangAnalyze) include(CMLibCodeAnalysisClangTidy) include(CMLibCodeAnalysisClazy) +include(CMLibSanitizers) include(cotire) include(CMLibBreathe) diff --git a/CMLibSanitizers.cmake b/CMLibSanitizers.cmake new file mode 100644 index 0000000..bc57a4b --- /dev/null +++ b/CMLibSanitizers.cmake @@ -0,0 +1,25 @@ +if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_GCC) + + if(SANITIZE_THREAD AND SANITIZE_ADDRESS) + message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.") + endif() + + if(SANITIZE_ADDRESS) + message(STATUS "AddressSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=address,undefined") + check_enable_cxx_flag(-fno-sanitize=signed-integer-overflow) + endif() + + if(SANITIZE_THREAD) + message(STATUS "ThreadSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=thread") + endif() + + if(SANITIZE_THREAD OR SANITIZE_ADDRESS) + check_enable_cxx_flag(${SANITIZER_FLAGS}) + check_enable_cxx_flag("-fno-sanitize-recover=all") + check_enable_cxx_flag("-fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold") + endif() +endif() +