- if(address IN_LIST ENABLE_SANITIZERS OR asan IN_LIST ENABLE_SANITIZERS)
- cmake_push_check_state(RESET)
- set(CMAKE_REQUIRED_LIBRARIES asan)
- check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN)
- cmake_pop_check_state()
- if(HAVE_ASAN)
- add_compile_definitions(HAVE_ASAN)
- add_compile_options(-fsanitize=address)
- if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v -fsanitize=address")
- endif()
- link_libraries(asan)
- check_flag(-fsanitize-recover=address IGNORE)
- endif()
- endif()
-
- if(undefined IN_LIST ENABLE_SANITIZERS OR ubsan IN_LIST ENABLE_SANITIZERS)
- cmake_push_check_state(RESET)
- set(CMAKE_REQUIRED_LIBRARIES ubsan)
- check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN)
- cmake_pop_check_state()
- if(HAVE_UBSAN)
- add_compile_definitions(HAVE_UBSAN)
- add_compile_options(-fsanitize=undefined)
- if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -v -fsanitize=undefined")
- endif()
- link_libraries(ubsan)
- check_flag(-fsanitize-recover=undefined IGNORE)
- endif()
- endif()
+ check_sanitizer(ENABLE_SANITIZERS address asan)
+ check_sanitizer(ENABLE_SANITIZERS undefined ubsan)
+ check_sanitizer(ENABLE_SANITIZERS thread tsan)
+ check_sanitizer(ENABLE_SANITIZERS leak lsan)