Skip to content

Commit

Permalink
Move sanitizer to a seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Twon committed Nov 10, 2023
1 parent 2212bfa commit 0007bbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
41 changes: 0 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,6 @@ if (${CPP_VALUE_TYPES_IS_NOT_SUBPROJECT})
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)

if (ENABLE_SANITIZERS)
set(SANITIZER_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer")
set(SANITIZER_FLAGS_UBSAN "-fsanitize=undefined")

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("${SANITIZER_FLAGS_ASAN}" COMPILER_SUPPORTS_ASAN)
check_cxx_compiler_flag("${SANITIZER_FLAGS_UBSAN}" COMPILER_SUPPORTS_UBSAN)

if (COMPILER_SUPPORTS_ASAN)
add_library(asan INTERFACE IMPORTED)
set_target_properties(asan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_ASAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_ASAN}"
)
target_link_libraries(indirect_test
PRIVATE
asan
)
target_link_libraries(polymorphic_test
PRIVATE
asan
)
endif(COMPILER_SUPPORTS_ASAN)

if (COMPILER_SUPPORTS_UBSAN)
add_library(ubsan INTERFACE IMPORTED)
set_target_properties(ubsan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
)
target_link_libraries(indirect_test
PRIVATE
ubsan
)
target_link_libraries(polymorphic_test
PRIVATE
ubsan
)
endif(COMPILER_SUPPORTS_UBSAN)
endif(ENABLE_SANITIZERS)

enable_testing()

if (ENABLE_CODE_COVERAGE)
Expand Down
26 changes: 26 additions & 0 deletions cmake/sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include_guard(GLOBAL)

if (ENABLE_SANITIZERS)
set(SANITIZER_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer")
set(SANITIZER_FLAGS_UBSAN "-fsanitize=undefined")

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("${SANITIZER_FLAGS_ASAN}" COMPILER_SUPPORTS_ASAN)
check_cxx_compiler_flag("${SANITIZER_FLAGS_UBSAN}" COMPILER_SUPPORTS_UBSAN)

if (COMPILER_SUPPORTS_ASAN)
add_library(asan INTERFACE IMPORTED)
set_target_properties(asan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_ASAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_ASAN}"
)
endif(COMPILER_SUPPORTS_ASAN)

if (COMPILER_SUPPORTS_UBSAN)
add_library(ubsan INTERFACE IMPORTED)
set_target_properties(ubsan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
)
endif(COMPILER_SUPPORTS_UBSAN)
endif(ENABLE_SANITIZERS)
4 changes: 4 additions & 0 deletions cmake/vt_add_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function(vt_add_test)

endif (NOT TARGET common_compiler_settings)

include(sanitizers)

add_executable(${VALUE_TYPES_NAME} "")
target_sources(${VALUE_TYPES_NAME}
PRIVATE
Expand All @@ -52,6 +54,8 @@ function(vt_add_test)
${VALUE_LINK_LIBRARIES}
GTest::gtest_main
common_compiler_settings
$<$<BOOL:${COMPILER_SUPPORTS_ASAN}>:asan>
$<$<BOOL:${COMPILER_SUPPORTS_USAN}>:ubsan>
)

set_target_properties(${VALUE_TYPES_NAME} PROPERTIES
Expand Down

0 comments on commit 0007bbc

Please sign in to comment.