From 0533298b25c3911d9f5c92535f9619f6581ce9c9 Mon Sep 17 00:00:00 2001 From: Dipin Hora Date: Fri, 22 Nov 2024 08:56:56 -0500 Subject: [PATCH] Allow multiple sanitizers to be enabled at the same time (#4538) --- CMakeLists.txt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab9affa5f9..33c26f551a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,20 +37,23 @@ endif() if(PONY_USE_THREAD_SANITIZER) set(PONY_OUTPUT_SUFFIX "${PONY_OUTPUT_SUFFIX}-thread_sanitizer") - add_compile_options(-fsanitize=thread -DPONY_SANITIZER=\"thread\") - add_link_options(-fsanitize=thread -DPONY_SANITIZER=\"thread\") + list(APPEND PONY_SANITIZERS_ENABLED "thread") endif() if(PONY_USE_ADDRESS_SANITIZER) set(PONY_OUTPUT_SUFFIX "${PONY_OUTPUT_SUFFIX}-address_sanitizer") - add_compile_options(-fsanitize=address -DPONY_SANITIZER=\"address\") - add_link_options(-fsanitize=address -DPONY_SANITIZER=\"address\") + list(APPEND PONY_SANITIZERS_ENABLED "address") endif() if(PONY_USE_UNDEFINED_BEHAVIOR_SANITIZER) set(PONY_OUTPUT_SUFFIX "${PONY_OUTPUT_SUFFIX}-undefined_behavior_sanitizer") - add_compile_options(-fsanitize=undefined -DPONY_SANITIZER=\"undefined\") - add_link_options(-fsanitize=undefined -DPONY_SANITIZER=\"undefined\") + list(APPEND PONY_SANITIZERS_ENABLED "undefined") +endif() + +if(PONY_SANITIZERS_ENABLED) + list(JOIN PONY_SANITIZERS_ENABLED "," PONY_SANITIZERS_VALUE) + add_compile_options(-fsanitize=${PONY_SANITIZERS_VALUE} -DPONY_SANITIZER=\"${PONY_SANITIZERS_VALUE}\") + add_link_options(-fsanitize=${PONY_SANITIZERS_VALUE} -DPONY_SANITIZER=\"${PONY_SANITIZERS_VALUE}\") endif() if(PONY_USE_COVERAGE)