elseif(${ALLOCATOR} STREQUAL "jemalloc")
find_package(JeMalloc REQUIRED)
set(HAVE_LIBJEMALLOC ${JEMALLOC_FOUND})
+ set(HAVE_JEMALLOC 1)
endif()
else(ALLOCATOR)
find_package(gperftools)
add_definitions(-D__linux__)
endif(LINUX)
+# ASAN and friends
+option(WITH_ASAN "build with ASAN" OFF)
+option(WITH_ASAN_LEAK "explicitly enable ASAN leak detection" OFF)
+
+if(WITH_ASAN)
+ set(ASAN_CFLAGS "-fsanitize=address -fno-omit-frame-pointer")
+ if(WITH_ASAN_LEAK)
+ set(ASAN_CFLAGS "${ASAN_CFLAGS} -fsanitize=leak")
+ endif()
+ set(ASAN_LFLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ASAN_CFLAGS} -lasan")
+ set(CMAKE_EXE_LINKER_FLAGS "${ASAN_LFLAGS}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_CFLAGS}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ASAN_CFLAGS}")
+ if(HAVE_JEMALLOC)
+ message(FATAL "ASAN does not work well with JeMalloc")
+ endif()
+endif()
+
+option(WITH_TSAN "build with TSAN" OFF)
+if(WITH_TSAN)
+ if (WITH_ASAN AND WITH_ASAN_LEAK)
+ message(FATAL_ERROR "Cannot combine -fsanitize-leak w/-fsanitize-thread")
+ endif()
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -pie -ltsan ")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -fPIC")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fno-omit-frame-pointer -fPIC")
+ if(HAVE_JEMALLOC)
+ message(FATAL "TSAN does not work well with JeMalloc")
+ endif()
+endif()
+
+option(WITH_UBSAN "build with UBSAN" OFF)
+if(WITH_UBSAN)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
+ if(HAVE_JEMALLOC)
+ message(FATAL "UBSAN does not work well with JeMalloc")
+ endif()
+endif()
+
# Boost
option(WITH_SYSTEM_BOOST "require and build with system Boost" OFF)