if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
    set(SANITIZERS "")

    option(SANITIZERS_ENABLE_ADDRESS "Enable address sanitizer" FALSE)
    if(SANITIZERS_ENABLE_ADDRESS)
        log_option_enabled("address sanitizer")
        list(APPEND SANITIZERS "address")
    else()
        log_option_disabled("address sanitizer")
    endif()

    option(SANITIZERS_ENABLE_LEAK "Enable leak sanitizer" FALSE)
    if(SANITIZERS_ENABLE_LEAK)
        log_option_enabled("leak sanitizer")
        list(APPEND SANITIZERS "leak")
    else()
        log_option_disabled("leak sanitizer")
    endif()

    option(SANITIZERS_ENABLE_UB "Enable UB sanitizer" FALSE)
    if(SANITIZERS_ENABLE_UB)
        log_option_enabled("ub sanitizer")
        list(APPEND SANITIZERS "undefined")
    else()
        log_option_disabled("ub sanitizer")
    endif()

    # Always run this sanitizer alone, all previous sanitizers should be disabled
    option(SANITIZERS_ENABLE_MEMORY "Enable memory sanitizer" FALSE)
    if(SANITIZERS_ENABLE_MEMORY)
        log_option_enabled("memory sanitizer")
        list(APPEND SANITIZERS "memory")
    else()
        log_option_disabled("memory sanitizer")
    endif()

    list(JOIN SANITIZERS "," LIST_OF_SANITIZERS)
endif()

if(LIST_OF_SANITIZERS)
    if(NOT "${LIST_OF_SANITIZERS}" STREQUAL "")
        target_compile_options(common_build_options INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
        target_link_options(common_build_options INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
    endif()
endif()
