aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-06-14 14:52:01 -0700
committerAnders Broman <a.broman58@gmail.com>2016-06-15 06:02:51 +0000
commitc19e6c24067fd0aa1ea628de85f25ef9ece08839 (patch)
tree623b2cff865b384319b0612bb3c7970f349c233b /CMakeLists.txt
parent3a590217ac60d626cb126aff593b43901585224c (diff)
cmake: fix ENABLE_ASAN detection
Do not add -fsanitize=undefined when ASAN is requested, UBSAN is a different feature (which could be added later as desired). This makes the -DENABLE_ASAN=1 option match the autotools --enable-asan option. Fail hard if ASAN support is requested but not supported, this avoids surprises when something is wrong. Fix ASAN detection by setting the linker option too. Note: if you have previously set ENABLE_ASAN=1 with the broken ASAN detection, you have to clear your CMakeCache.txt file to redo the detection. Change-Id: Iba6ca0da0336eccedd0cf31a251baad9d1aff5b4 Reviewed-on: https://code.wireshark.org/review/15908 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt27
1 files changed, 12 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d1d948367..4405cbce7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -472,21 +472,6 @@ else()
)
endif()
- set(WIRESHARK_ASAN_FLAGS
- # With Clang >= 3.5 Leak detection is enable by default
- # and no yet all leak is fixed...
- # use ASAN_OPTIONS=detect_leaks=0 to disable detect_leaks
- -fsanitize=address
- -fsanitize=undefined # compile and runtime checks
- # -fsanitize=float-divide-by-zero
- # -fsanitize=float-cast-overflow
- # -fno-sanitize-recover # Abort during runtime
- )
-
- if(ENABLE_ASAN)
- set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_ASAN_FLAGS})
- endif()
-
if(ENABLE_EXTRA_COMPILER_WARNINGS) # This overrides -Werror
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_EXTRA_COMPILER_COMMON_FLAGS})
set(WIRESHARK_C_ONLY_FLAGS ${WIRESHARK_C_ONLY_FLAGS} ${WIRESHARK_EXTRA_COMPILER_C_ONLY_FLAGS})
@@ -541,6 +526,18 @@ foreach(THIS_FLAG ${CXX_FLAG_TESTS})
endforeach()
set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
+if(ENABLE_ASAN)
+ set(CMAKE_REQUIRED_LIBRARIES "-fsanitize=address")
+ check_c_compiler_flag(-fsanitize=address C__fsanitize_address_VALID)
+ check_cxx_compiler_flag(-fsanitize=address CXX__fsanitize_address_VALID)
+ set(CMAKE_REQUIRED_LIBRARIES "")
+ if(NOT C__fsanitize_address_VALID OR NOT CXX__fsanitize_address_VALID)
+ message(FATAL_ERROR "ENABLE_ASAN was requested, but not supported!")
+ endif()
+ set(CMAKE_C_FLAGS "-fsanitize=address ${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS "-fsanitize=address ${CMAKE_CXX_FLAGS}")
+endif()
+
if(NOT DISABLE_WERROR AND NOT ENABLE_EXTRA_COMPILER_WARNINGS)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(WERROR_COMMON_FLAGS "/WX")