From c19e6c24067fd0aa1ea628de85f25ef9ece08839 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 14 Jun 2016 14:52:01 -0700 Subject: 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 Reviewed-by: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- CMakeLists.txt | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'CMakeLists.txt') 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") -- cgit v1.2.1