-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing warnings on subsequent CMake runs #30
Comments
This is a pretty annoying problem, but can be easily fixed by adding a check in the |
Had a quick look in my local fork, and saw I had done something sligthly different: diff --git a/cmake/FindSanitizers.cmake b/cmake/FindSanitizers.cmake
index 6960482..eb1c721 100755
--- a/cmake/FindSanitizers.cmake
+++ b/cmake/FindSanitizers.cmake
@@ -26,6 +26,7 @@
# link against the sanitizers.
option(SANITIZE_LINK_STATIC "Try to link static against sanitizers." Off)
+option(Sanitizers_SUPPRESS_WARNINGS "Suppress Sanitizers module warnings" OFF)
@@ -64,25 +65,31 @@ function(add_sanitizers ...)
# wise sanitizers can't be used and a warning should be printed once.
get_target_property(TARGET_TYPE ${TARGET} TYPE)
if (TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
- message(WARNING "Can't use any sanitizers for target ${TARGET}, "
+ if(NOT Sanitizers_SUPPRESS_WARNINGS)
+ message(WARNING "Can't use any sanitizers for target ${TARGET}, "
"because it is an interface library and cannot be "
"compiled directly.")
+ endif()
continue()
endif ()
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}, "
+ if(NOT Sanitizers_SUPPRESS_WARNINGS)
+ message(WARNING "Can't use any sanitizers for target ${TARGET}, "
"because it will be compiled by incompatible compilers. "
"Target will be compiled without sanitizers.")
+ endif()
continue()
# If the target is compiled by no or no known compiler, give a warning.
elseif (NUM_COMPILERS EQUAL 0)
- message(WARNING "Sanitizers for target ${TARGET} may not be"
- " usable, because it uses no or an unknown compiler. "
+ if(NOT Sanitizers_SUPPRESS_WARNINGS)
+ message(WARNING "Sanitizers for target ${TARGET} may not be "
+ "usable, because it uses no or an unknown compiler. "
"This is a false warning for targets using only "
- "object lib(s) as input.")
+ "object lib(s) as input.")
+ endif()
endif ()
# Add sanitizers for target. |
From what I can see, you've only suppressed the warnings using a cache variable, but not checking if the flags were detected and added to the targets. This would raise the same problem of not showing the warnings when a compiler doesn't support a specific sanitizer in the successive runs. |
Sorry, I mixed up things here. The diff from above does not help at all with the reported problem, but does the opposite. 🙄
No. |
I see. You can still look into my fork if you want. |
When building with GCC and enabling SANITIZE_MEMORY there are only warnings on missing compiler support on the very first run of CMake. There's no warning nor error on missing compiler support once CMake cache is in place. This is bad, because it leads to the false impression everything is fine and the sanitizer is in place. This might lead to thinking code has no flaws.
You can simply reproduce this by building the example from https://github.com/google/sanitizers/wiki/MemorySanitizer with GCC and enable SANITIZE_MEMORY, and run cmake again on the same build folder. Everythings builds fine, no warning at buildtime nor runtime, although the code is clearly buggy and MemorySanitizer with Clang finds it.
The documentation in README.md states:
However this is only the case on the first CMake run, there is no warning on subsequent runs when cache is populated. But there should be!
The text was updated successfully, but these errors were encountered: