cmake/compiler: Limit warning flag usage to compatible toolchains

New C++ versions have deprecated "register" variables and restricted
"volatile" semantics, so new gcc's will emit warnings when they see
that syntax.  Zephyr uses both in our C headers (though we should
probably get rid of register and unify with C++'s volatile model), so
we're disabling the resulting warnings.

But OLD gcc variants (like xcc, sigh) don't understand new -Wvolatile
and -Wregister on the command line, so they get confused.  Limit the
uses to the standard versions for which gcc would emit warnigns; xcc
doesn't support those anyway.

Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
Andy Ross 2023-02-28 13:19:01 -08:00 committed by Christopher Friedt
commit 728230a241

View file

@ -119,10 +119,15 @@ set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx "-nostdinc++")
# Required C++ flags when using gcc # Required C++ flags when using gcc
set_property(TARGET compiler-cpp PROPERTY required "-fcheck-new") set_property(TARGET compiler-cpp PROPERTY required "-fcheck-new")
# GCC compiler flags for C++ dialects # GCC compiler flags for C++ dialect: "register" variables and some
# "volatile" usage generates warnings by default in standard versions
# higher than 17 and 20 respectively. Zephyr uses both, so turn off
# the warnings where needed (but only on the compilers that generate
# them, older toolchains like xcc don't understand the command line
# flags!)
set_property(TARGET compiler-cpp PROPERTY dialect_cpp98 "-std=c++98") set_property(TARGET compiler-cpp PROPERTY dialect_cpp98 "-std=c++98")
set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11" "-Wno-register") set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11")
set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14" "-Wno-register") set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14")
set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "-std=c++17" "-Wno-register") set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "-std=c++17" "-Wno-register")
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "-std=c++2a" set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "-std=c++2a"
"-Wno-register" "-Wno-volatile") "-Wno-register" "-Wno-volatile")