Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Allow configuring different sanitizers from cmake
Browse files Browse the repository at this point in the history
This will make it easier to enable these sanitizers with a simple
command-line switch, and potentially enable them on Travis.
  • Loading branch information
sas committed Nov 17, 2016
1 parent 1f9b3c2 commit df22763
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Unused language features.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")

#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# These flags must be set before we include subdirectories so subprojects
# have these options enabled as well.
if (SANITIZER)
set(COMMON_FLAGS "${COMMON_FLAGS} -g -fno-omit-frame-pointer")
endif ()

if (SANITIZER STREQUAL "asan")
set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=address")
elseif (SANITIZER STREQUAL "ubsan")
set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=integer -fsanitize=undefined")
elseif (SANITIZER STREQUAL "tsan")
set(COMMON_FLAGS "${COMMON_FLAGS} -fsanitize=thread")
endif ()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
endif ()

# Enable all warnings.
add_compile_options(-Wall -Werror)
Expand Down

0 comments on commit df22763

Please sign in to comment.