From 1a3bb66608b2f96407d14fe13b782626990060f1 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Tue, 20 Nov 2018 08:20:13 +0100 Subject: [PATCH] CMakeLists.txt: conditionally use -fsanitize=address Check that compiler supports -fsanitize=address before using it Fixes: - http://autobuild.buildroot.net/results/221d6a418e75b39fe645c3a56cee676518d2cff6 Signed-off-by: Fabrice Fontaine --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e8e07e..c3f71ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,11 @@ if(COMPILER_SUPPORTS_WPEDANTIC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic") endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -O0 -fsanitize=address") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3 -O0") + check_c_compiler_flag("-fsanitize=address -Werror" COMPILER_SUPPORTS_SANITIZE_ADDRESS) + if(COMPILER_SUPPORTS_SANITIZE_ADDRESS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + endif() set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_pie,") else() if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") -- 2.14.1