Skip to content

Commit

Permalink
Merge pull request arsenm#10 from RWTH-ELP/feature/fewer_messages
Browse files Browse the repository at this point in the history
Show fewer warnings for targets.
  • Loading branch information
arsenm authored Feb 22, 2017
2 parents 37d5ac8 + a1bee9b commit 295c360
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
25 changes: 25 additions & 0 deletions cmake/FindSanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
19 changes: 8 additions & 11 deletions cmake/sanitize-helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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()

Expand Down

0 comments on commit 295c360

Please sign in to comment.