diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 75a448f0b3..2289e59cd1 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -854,6 +854,7 @@ libclang libcrc libgtest libiconv +libsan LIBLOC lic lifecycle diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fb298f1ef..1377e502f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,17 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") $<$:-Wno-zero-length-array> ) endif() +set(SAN_STATIC_FLAG -static-libasan) +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10) + set(SAN_STATIC_FLAG -static-libasan) +endif() + + find_program(VALGRIND valgrind) # Find valgrind, and use it instead of leak check # For this testing cmake project, enable AddressSanitizer, a runtime memory sanitizer, on all unit tests if (BUILD_TESTING AND NOT VALGRIND) - add_compile_options(-fno-omit-frame-pointer -fsanitize=address -fsanitize=leak -fsanitize=undefined -static-libasan) - add_link_options(-fno-omit-frame-pointer -fsanitize=address -fsanitize=leak -fsanitize=undefined -static-libasan) + add_compile_options(-fno-omit-frame-pointer -fsanitize=address -fsanitize=leak -fsanitize=undefined ${SAN_STATIC_FLAG}) + add_link_options(-fno-omit-frame-pointer -fsanitize=address -fsanitize=leak -fsanitize=undefined ${SAN_STATIC_FLAG}) endif() include("${CMAKE_CURRENT_LIST_DIR}/cmake/FPrime-Code.cmake")