Skip to content

Commit

Permalink
Introduce "Sanitize" build type
Browse files Browse the repository at this point in the history
Remove sanitizer flags from regular debug builds, impractical due to
performance hit
  • Loading branch information
ypnos committed Dec 21, 2020
1 parent 00d2202 commit 6109b86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmake/behavior.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
"Debug" "Release" "RelWithDebInfo" "Sanitize") # see also flags.cmake
endif()

# STATIC stuff (Windows)
Expand Down
11 changes: 7 additions & 4 deletions cmake/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ set(FLAGS_DEBUG
-g -Og -fno-omit-frame-pointer
# -Werror

# Sanitizers:
-fsanitize=address,leak,undefined

# All kinds of pedantic warnings:
-pedantic -Wall -Wextra
-Wnull-dereference -Wdouble-promotion -Wformat=2 #-Wshadow
Expand All @@ -38,12 +35,18 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
)
endif()

set(FLAGS_SANITIZE
${FLAGS_DEBUG} # start with debug flag set
# Add sanitizers:
-fsanitize=address,leak,undefined
)

# Note: it is discouraged in CMake to alter these variables, but instead you
# should set flags on the target. However, those flags are hidden from the
# user. In our case, we want the user to be able to see and alter the
# flags of the build type.
set(TYPES CXX;EXE_LINKER)
set(BUILDS DEBUG;RELEASE)
set(BUILDS DEBUG;RELEASE;SANITIZE)
foreach (BUILD ${BUILDS})
string(REPLACE ";" " " FLAGS_${BUILD} "${FLAGS_${BUILD}}")
foreach (TYPE ${TYPES})
Expand Down

0 comments on commit 6109b86

Please sign in to comment.