Skip to content

Commit 83e4c04

Browse files
authored
Merge pull request #46 from eic/tsan-ubsan-asan
feat(cmake): add TSAN/UBSAN/ASAN options to CMake
2 parents f4846fe + 379eecb commit 83e4c04

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ option(EVALUATION "Build evaluation programs" OFF)
1313
option(DELPHES "Delphes card production" ON)
1414
option(IRT_ROOT_IO "Generate dictionary for ROOT I/O of libIRT objects" ON)
1515

16+
# Sanitizer options (TSAN is mutually exclusive with ASAN/UBSAN)
17+
include(CMakeDependentOption)
18+
option(USE_TSAN "Enable Thread Sanitizer" OFF)
19+
cmake_dependent_option(USE_ASAN "Enable Address Sanitizer" OFF "NOT USE_TSAN" OFF)
20+
cmake_dependent_option(USE_UBSAN "Enable Undefined Behavior Sanitizer" OFF "NOT USE_TSAN" OFF)
21+
1622
#----------------------------------------------------------------------------
1723
# dependencies
1824

@@ -43,6 +49,30 @@ endif()
4349

4450
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla-cxx-extension")
4551

52+
# Thread Sanitizer
53+
if(USE_TSAN)
54+
message(STATUS "Building with Thread Sanitizer enabled")
55+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -g -O1 -fno-omit-frame-pointer")
56+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
57+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
58+
endif()
59+
60+
# Address Sanitizer
61+
if(USE_ASAN)
62+
message(STATUS "Building with Address Sanitizer enabled")
63+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g -O1 -fno-omit-frame-pointer")
64+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
65+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
66+
endif()
67+
68+
# Undefined Behavior Sanitizer
69+
if(USE_UBSAN)
70+
message(STATUS "Building with Undefined Behavior Sanitizer enabled")
71+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -g -O1 -fno-omit-frame-pointer")
72+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
73+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=undefined")
74+
endif()
75+
4676
#----------------------------------------------------------------------------
4777
# IRT library
4878

0 commit comments

Comments
 (0)