Add options to enable Sanitizers to CMake build
Tested to work with gcc 5.4.0, 7.1.0 and clang 4.0.1
@@ -118,6 +118,19 @@ if (USE_VALGRIND)
set(TEST_RUNNER "${VALGRIND_EXECUTABLE} --leak-check=full --show-leak-kinds=definite --errors-for-leak-kinds=definite --error-exitcode=42 --suppressions=${CMAKE_SOURCE_DIR}/tests/valgrind.supp")
endif()
+option(USE_SANITIZERS "Compile with sanitizers (ASan, UBSan, TSan); incompatible with Valgrind" OFF)
+if (USE_SANITIZERS)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -fsanitize=undefined")
+ add_compile_options(-g)
+ add_compile_options(-fno-omit-frame-pointer)
+endif (USE_SANITIZERS)
+
+option(USE_TSAN "Compile with ThreadSanitizer (TSan); incompatible with Valgrind" OFF)
+if (USE_TSAN)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
+ add_compile_options(-g)
+ add_compile_options(-fno-omit-frame-pointer)
+endif (USE_TSAN)
##
## Include directories used by all sub-directories.
