From 728230a241bd2a39cf7fa22b0edeb0e09df127d0 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 28 Feb 2023 13:19:01 -0800 Subject: [PATCH] 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 --- cmake/compiler/gcc/compiler_flags.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 08b229672c4..0066ee231a1 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -119,10 +119,15 @@ set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx "-nostdinc++") # Required C++ flags when using gcc 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_cpp11 "-std=c++11" "-Wno-register") -set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14" "-Wno-register") +set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11") +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_cpp2a "-std=c++2a" "-Wno-register" "-Wno-volatile")