Skip to content

Commit 2d0e502

Browse files
committed
Add sanitizer options
1 parent 8b2a0c5 commit 2d0e502

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ cmake_minimum_required(VERSION 3.12)
88

99
option(JAM_COMPATIBLE "Build compatible with JAM-codec" OFF)
1010
option(CUSTOM_CONFIG_SUPPORT "Support custom config of coder" OFF)
11-
set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation")
12-
1311
option(BUILD_TESTS "Whether to include the test suite in build" OFF)
1412

13+
option(SCALE_ASAN "Build with address sanitizer" OFF)
14+
option(SCALE_UBSAN "Build with undefined behavior sanitizer" OFF)
15+
option(SCALE_TSAN "Build with thread sanitizer" OFF)
16+
17+
set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation")
18+
1519
if (PACKAGE_MANAGER)
1620
if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$")
1721
message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set")
@@ -66,6 +70,19 @@ SET(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}")
6670
set(CUSTOM_CONFIG_ENABLED "${CUSTOM_CONFIG_SUPPORT}")
6771
configure_file("${CMAKE_SOURCE_DIR}/include/scale/definitions.hpp.in" "${CMAKE_BINARY_DIR}/include/scale/definitions.hpp")
6872

73+
if (SCALE_ASAN)
74+
add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer)
75+
add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer)
76+
endif()
77+
if (SCALE_UBSAN)
78+
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
79+
add_link_options(-fsanitize=undefined -fno-omit-frame-pointer)
80+
endif()
81+
if (SCALE_TSAN)
82+
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
83+
add_link_options(-fsanitize=thread -fno-omit-frame-pointer)
84+
endif()
85+
6986
add_subdirectory(src)
7087

7188
if (BUILD_TESTS)

0 commit comments

Comments
 (0)