Skip to content

Commit

Permalink
cmake: add option ENABLE_SANITIZERS
Browse files Browse the repository at this point in the history
This option enables Sanitizers for Addresses, Leaks and Undefinied
Behaviour.
  • Loading branch information
arogge committed Feb 24, 2022
1 parent cb634fc commit 02b8d10
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/CMakeLists.txt
Expand Up @@ -55,6 +55,19 @@ endif(CCACHE_FOUND)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ENABLE_SANITIZERS "Build with ASan/LSan/UBSan enabled" OFF)
if(ENABLE_SANITIZERS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -fno-sanitize-recover")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fsanitize=address -fno-sanitize-recover")
else()
message(
FATAL_ERROR
"Cannot (yet) compile with sanitizers on ${CMAKE_C_COMPILER_ID}"
)
endif()
endif()

option(ENABLE_STATIC_RUNTIME_LIBS "Link C and C++ runtime libraries statically"
OFF
)
Expand Down

0 comments on commit 02b8d10

Please sign in to comment.