Skip to content

Commit

Permalink
cmake: Add easy sanitizers option
Browse files Browse the repository at this point in the history
Set -DSANITIZE to a comma-separated list of options to pass to
-fsanitize=, like -DSANITIZE=address,undefined
  • Loading branch information
nadiaholmquist committed Oct 19, 2024
1 parent 216b8e0 commit fbf7532
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include(CMakeDependentOption)
include(CheckIPOSupported)

include(SetupCCache)
include(Sanitizers)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")

Expand Down
8 changes: 8 additions & 0 deletions cmake/Sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(SANITIZE "" CACHE STRING "Sanitizers to enable.")

string(REGEX MATCHALL "[^,]+" ENABLED_SANITIZERS "${SANITIZE}")

foreach(SANITIZER ${ENABLED_SANITIZERS})
add_compile_options("-fsanitize=${SANITIZER}")
add_link_options("-fsanitize=${SANITIZER}")
endforeach()

0 comments on commit fbf7532

Please sign in to comment.