cmake-scripts
cmake-scripts copied to clipboard
Check compiler support for optional sanitizer flags
Hi.
When setting compiler options for sanitizers with set_sanitizer_options(address DEFAULT -fno-omit-frame-pointer), this will fail on MSVC because the flag is not supported. I would suggest either using different defaults (we probably want to enable -fno-omit-frame-pointer systematically for Clang/GCC), or using check_cxx_compiler_flag (and cache the result) to see if a specific flag is supported by a compiler.
I've added a check for the flag with commit dd981c94609e83242ace8ad9e63b77ab656d453f, so it shouldn't be an issue any more, at least with that specific flag.
Hmm I see. That only works with the "legacy" way to setting up the sanitizers though. I was thinking you may want to add the flag check inside the set_sanitizer_options() function itself, or is that too much?
It is already in there, albeit just on WIN32, I'll change it to be on all platforms.
In set_sanitizer_options(), to test the 'availability' of an option set it calls test_san_flags(), which goes through and checks each flag via check_cxx_compiler_flag, and then finally that all the flags can be used together via check_cxx_source_compiles. If any single flag is not available or all the flags don't work together, the sanitizer is then marked as 'not available'.
This process also occurs for add_sanitizer_support, when checking the combination of sanitizer sets if they seemingly work together.
I otherwise wanted to move away from defining option sets beyond what would remain (mostly) compatible with the sets from before, as I don't really use the new ones like DataFlowSanitizer or RealTimeSanitizer.
Now, beyond the basic legacy set, users should be able to support odd compiler/platform combinations, like GCC via MinGW or whatever.
I've updated the latest release with use of check_cxx_compiler_flag.
Thanks!