Added ASan and TSan instrumented build to CMake
authorkhizmax <libcds.dev@gmail.com>
Sun, 5 Jun 2016 06:04:18 +0000 (09:04 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sun, 5 Jun 2016 06:04:18 +0000 (09:04 +0300)
CMakeLists.txt

index bcb8143..893f616 100644 (file)
@@ -9,6 +9,8 @@ set(PROJECT_VERSION 2.2.0)
 option(WITH_TESTS "Build unit tests" OFF)
 option(WITH_TESTS_COVERAGE "Analyze test coverage using gcov (only for gcc)" OFF)
 option(WITH_BOOST_ATOMIC "Use boost atomics (only for boost >= 1.54)" OFF)
+option(WITH_ASAN "Build AddressSantinizer instrumented code" OFF)
+option(WITH_TSAN "Build ThreadSantinizer instrumented code" OFF)
 
 find_package(Threads REQUIRED)
 find_package(Boost 1.50 COMPONENTS system thread REQUIRED)
@@ -22,6 +24,26 @@ if(WITH_BOOST_ATOMIC)
   endif()
 endif(WITH_BOOST_ATOMIC)
 
+if(WITH_ASAN)
+  if(CMAKE_COMPILER_IS_GNUCXX)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -pie")
+  else()
+    message(WARNING "Compiler does not support AddressSanitizer")
+  endif()
+endif(WITH_ASAN)
+
+if(WITH_TSAN)
+  if(CMAKE_COMPILER_IS_GNUCXX)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
+    set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
+  else()
+    message(WARNING "Compiler does not support ThreadSanitizer")
+  endif()
+endif(WITH_TSAN)
+
 if(WITH_TESTS_COVERAGE)
   if(CMAKE_COMPILER_IS_GNUCXX)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")