[cmake] Protect against redefining santizier targets

This commit is contained in:
Nils Wentzell 2023-08-04 14:52:46 -04:00
parent cb99846580
commit c0afc3c44b
1 changed files with 12 additions and 4 deletions

View File

@ -68,24 +68,32 @@ endif()
option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer")
if(ASAN)
find_package(sanitizer REQUIRED COMPONENTS asan)
if(NOT TARGET ASAN)
find_package(sanitizer REQUIRED COMPONENTS asan)
endif()
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:asan>)
endif()
option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer")
if(UBSAN)
find_package(sanitizer REQUIRED COMPONENTS ubsan)
if(NOT TARGET UBSAN)
find_package(sanitizer REQUIRED COMPONENTS ubsan)
endif()
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:ubsan>)
endif()
option(MSAN OFF "Compile library and executables with LLVM Memory Sanitizer")
if(MSAN)
find_package(sanitizer REQUIRED COMPONENTS msan)
if(NOT TARGET MSAN)
find_package(sanitizer REQUIRED COMPONENTS msan)
endif()
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:msan>)
endif()
option(TSAN OFF "Compile library and executables with LLVM Thread Sanitizer")
if(TSAN)
find_package(sanitizer REQUIRED COMPONENTS tsan)
if(NOT TARGET TSAN)
find_package(sanitizer REQUIRED COMPONENTS tsan)
endif()
target_link_libraries(${PROJECT_NAME}_c PUBLIC $<BUILD_INTERFACE:tsan>)
endif()