From a1bee9b1782597b3b46b3bdf8518d9fd8b5f173e Mon Sep 17 00:00:00 2001 From: Alexander Haase Date: Tue, 21 Feb 2017 16:21:48 +0100 Subject: [PATCH] Show fewer warnings for targets. Instead of printing the same message over and over again, if a target can't use a specific sanitizer, the message will be printed only once for the first affected target now. --- cmake/FindSanitizers.cmake | 25 +++++++++++++++++++++++++ cmake/sanitize-helpers.cmake | 19 ++++++++----------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/cmake/FindSanitizers.cmake b/cmake/FindSanitizers.cmake index 627ee24..71cda38 100644 --- a/cmake/FindSanitizers.cmake +++ b/cmake/FindSanitizers.cmake @@ -53,7 +53,32 @@ function(sanitizer_add_blacklist_file FILE) endfunction() function(add_sanitizers ...) + # If no sanitizer is enabled, return immediately. + if (NOT (SANITZE_ADDRESS OR SANITIZE_MEMORY OR SANITIZE_THREAD OR + SANITIZE_UNDEFINED)) + return() + endif () + foreach (TARGET ${ARGV}) + # Check if this target will be compiled by exactly one compiler. Other- + # wise sanitizers can't be used and a warning should be printed once. + sanitizer_target_compilers(${TARGET} TARGET_COMPILER) + list(LENGTH TARGET_COMPILER NUM_COMPILERS) + if (NUM_COMPILERS GREATER 1) + message(WARNING "Can't use any sanitizers for target ${TARGET}, " + "because it will be compiled by incompatible compilers. " + "Target will be compiled without sanitzers.") + return() + + # If the target is compiled by no known compiler, ignore it. + elseif (NUM_COMPILERS EQUAL 0) + message(WARNING "Can't use any sanitizers for target ${TARGET}, " + "because it uses an unknown compiler. Target will be " + "compiled without sanitzers.") + return() + endif () + + # Add sanitizers for target. add_sanitize_address(${TARGET}) add_sanitize_thread(${TARGET}) add_sanitize_memory(${TARGET}) diff --git a/cmake/sanitize-helpers.cmake b/cmake/sanitize-helpers.cmake index 88da66e..6f3decd 100644 --- a/cmake/sanitize-helpers.cmake +++ b/cmake/sanitize-helpers.cmake @@ -139,6 +139,10 @@ function (sanitizer_check_compiler_flags FLAG_CANDIDATES NAME PREFIX) set(${PREFIX}_${COMPILER}_FLAGS "" CACHE STRING "${NAME} flags for ${COMPILER} compiler.") mark_as_advanced(${PREFIX}_${COMPILER}_FLAGS) + + message(WARNING "${NAME} is not available for ${COMPILER} " + "compiler. Targets using this compiler will be " + "compiled without ${NAME}.") endif () endif () endforeach () @@ -147,19 +151,12 @@ endfunction () # Helper to assign sanitizer flags for TARGET. function (saitizer_add_flags TARGET NAME PREFIX) - # Get list of compilers used by target and check, if target can be checked - # by sanitizer. + # Get list of compilers used by target and check, if sanitizer is available + # for this target. Other compiler checks like check for conflicting + # compilers will be done in add_sanitizers function. sanitizer_target_compilers(${TARGET} TARGET_COMPILER) list(LENGTH TARGET_COMPILER NUM_COMPILERS) - if (NUM_COMPILERS GREATER 1) - message(WARNING "${NAME} disabled for target ${TARGET} because it will " - "be compiled by different compilers.") - return() - - elseif ((NUM_COMPILERS EQUAL 0) OR - ("${${PREFIX}_${TARGET_COMPILER}_FLAGS}" STREQUAL "")) - message(WARNING "${NAME} disabled for target ${TARGET} because there is" - " no sanitizer available for target sources.") + if ("${${PREFIX}_${TARGET_COMPILER}_FLAGS}" STREQUAL "") return() endif()