Skip to content
Permalink
Browse files

Check ASAN support when `ENABLE_ASAN=ON`.

We check if the compiler has asan support when the option is enabled.
If it does not, then we stop compiling with the proper message.

To test this, we use `gcc (GCC) 4.4.7` (no asan support) and
`gcc (GCC) 9.1.0` (asan is supported). Call cmake like this:

`cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=On` and
`CXX=g++-4.4 cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=On`

we then check that it fails for the older version and it works for
the newer gcc, like expected.

- Fix #409.
  • Loading branch information
denisfa authored and rkitover committed Sep 2, 2019
1 parent ade64db commit f1438e0f0a5912f412c14b42338e928bcf54b7ae
Showing with 9 additions and 3 deletions.
  1. +9 −3 CMakeLists.txt
@@ -480,6 +480,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(MY_C_DBG_FLAGS -g -fno-omit-frame-pointer)
endif()

include(CheckCXXCompilerFlag)

if(ENABLE_ASAN)
string(TOLOWER ${CMAKE_BUILD_TYPE} build)
if(NOT build STREQUAL "debug")
@@ -490,7 +492,13 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
if(SANITIZER STREQUAL "on" OR SANITIZER STREQUAL "true")
set(SANITIZER address)
endif()
set(MY_C_DBG_FLAGS ${MY_C_DBG_FLAGS} -fsanitize=${SANITIZER} -lasan)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-lasan")
check_cxx_compiler_flag("-fsanitize=${SANITIZER} -lasan" ASAN_SUPPORT_FLAG)
if(${ASAN_SUPPORT_FLAG})
set(MY_C_DBG_FLAGS ${MY_C_DBG_FLAGS} -fsanitize=${SANITIZER} -lasan)
else()
message(FATAL_ERROR "asan not available to compiler.")
endif()
endif()

# common flags
@@ -500,8 +508,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(MY_C_FLAGS ${MY_C_FLAGS} -fPIC)
endif()

include(CheckCXXCompilerFlag)

# check if ssp flags are supported for this version of gcc
if(CMAKE_COMPILER_IS_GNUCXX)
if(ENABLE_SSP)

0 comments on commit f1438e0

Please sign in to comment.
You can’t perform that action at this time.