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) set (CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_PROTOTYPES YES)
endif() 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 # Make it easy to enable Clang's/gcc's analyzers
# Travis, so don't enable it for gcc by default set(USE_SANITIZER "" CACHE STRING "Sanitizers to enable on the build.")
if(NOT USE_SANITIZER) foreach(san "${USE_SANITIZER}")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND message(STATUS "Enabling sanitizer: '${san}'")
NOT ("${CMAKE_GENERATOR}" STREQUAL "Xcode") AND
("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" if("${san}" STREQUAL address)
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")) add_compile_options(-fno-omit-frame-pointer)
message(STATUS "Enabling address sanitizer; set USE_SANITIZER=none to prevent this") link_libraries(-fno-omit-frame-pointer)
set(USE_SANITIZER address)
else()
set(USE_SANITIZER none)
endif() endif()
endif()
if(NOT ("${USE_SANITIZER}" STREQUAL "none")) if(NOT("${san}" STREQUAL "none"))
message(STATUS "Sanitizer set to ${USE_SANITIZER}") add_compile_options("-fsanitize=${san}")
add_compile_options(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) link_libraries("-fsanitize=${san}")
link_libraries(-fno-omit-frame-pointer -fsanitize=${USE_SANITIZER}) endif()
endif() endforeach()
include(GNUInstallDirs) include(GNUInstallDirs)
include(AnalyzeBuild) include(AnalyzeBuild)