diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-26 15:43:29 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-08 10:13:40 +0100 |
commit | 254feb0acd0d8db95fbb2e435c0a1086ebf8cd35 (patch) | |
tree | 444899160bf283d20e46c07577270bade7222748 /CMakeLists.txt | |
parent | ca1fe7ff7d7a020421191c92f2db09f00bbd2e1c (diff) |
Add address sanitizer option to cmake file.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 52c8b10f..7e560198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -26,6 +26,18 @@ if(ASSOC_DHT) | |||
26 | add_definitions(-DENABLE_ASSOC_DHT=1) | 26 | add_definitions(-DENABLE_ASSOC_DHT=1) |
27 | endif() | 27 | endif() |
28 | 28 | ||
29 | option(ASAN "Enable address-sanitizer to detect invalid memory accesses" OFF) | ||
30 | if(ASAN) | ||
31 | include(CheckCCompilerFlag) | ||
32 | set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") | ||
33 | set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address") | ||
34 | check_c_compiler_flag("-fsanitize=address" HAVE_ASAN) | ||
35 | if(HAVE_ASAN) | ||
36 | set(CMAKE_C_FLAGS "-fsanitize=address") | ||
37 | endif() | ||
38 | set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}") | ||
39 | endif() | ||
40 | |||
29 | find_package(PkgConfig REQUIRED) | 41 | find_package(PkgConfig REQUIRED) |
30 | find_package(Threads REQUIRED) | 42 | find_package(Threads REQUIRED) |
31 | 43 | ||