Don't turn on sanitizers for debug builds by default (#408)

Also, allow multiple sanitizers.
Signed-off-by: Dan Rose <dan@digilabs.io>
This commit is contained in:
Dan Rose 2020-02-29 01:38:40 -06:00 committed by GitHub
parent d72ebb0ed3
commit e8b0931798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -170,25 +170,23 @@ if(${CMAKE_GENERATOR} STREQUAL "Xcode")
set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES YES)
endif()
# Make it easy to enable one of Clang's/gcc's analyzers, and default to using
# the address sanitizer for ordinary debug builds; gcc is giving some grief on
# Travis, so don't enable it for gcc by default
if(NOT USE_SANITIZER)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND
NOT ("${CMAKE_GENERATOR}" STREQUAL "Xcode") AND
("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang"
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang"))
message(STATUS "Enabling address sanitizer; set USE_SANITIZER=none to prevent this")
set(USE_SANITIZER address)
else()
set(USE_SANITIZER none)
# Make it easy to enable Clang's/gcc's analyzers
set(USE_SANITIZER "" CACHE STRING "Sanitizers to enable on the build.")
foreach(san "${USE_SANITIZER}")
message(STATUS "Enabling sanitizer: '${san}'")
if("${san}" STREQUAL address)
add_compile_options(-fno-omit-frame-pointer)
link_libraries(-fno-omit-frame-pointer)
endif()
if(NOT("${san}" STREQUAL "none"))
add_compile_options("-fsanitize=${san}")
link_libraries("-fsanitize=${san}")
endif()
if(NOT ("${USE_SANITIZER}" STREQUAL "none"))
message(STATUS "Sanitizer set to ${USE_SANITIZER}")
add_compile_options(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER})
link_libraries(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER})
endif()
endforeach()
include(GNUInstallDirs)
include(AnalyzeBuild)