From 269bb2fb3ca4882961770848ff3a04c951e9b5b7 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 14 Dec 2019 07:33:52 -0600 Subject: [PATCH] cmake: toolchain: generalize exclusion of CXX options -Wold-style-definition is not a supported option for C++ builds. To prevent it being passed: * the list of compiler flags to be excluded from C++ builds is moved to be toolchain-specific; * -Wold-style-definition is added to that list for gcc and clang; * -Wold-style-definition is moved from zephyr_compiler_options to zephyr_cc_option so the option checking code is executed for it. Signed-off-by: Peter A. Bigot --- cmake/compiler/clang/target_warnings.cmake | 9 ++++++++- cmake/compiler/gcc/target_warnings.cmake | 9 ++++++++- cmake/extensions.cmake | 8 ++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cmake/compiler/clang/target_warnings.cmake b/cmake/compiler/clang/target_warnings.cmake index 771726f5a9666..cd2b9700faae0 100644 --- a/cmake/compiler/clang/target_warnings.cmake +++ b/cmake/compiler/clang/target_warnings.cmake @@ -27,9 +27,9 @@ macro(toolchain_cc_warning_dw_1) -Wno-unused-parameter -Wmissing-declarations -Wmissing-format-attribute - -Wold-style-definition ) zephyr_cc_option( + -Wold-style-definition -Wmissing-prototypes -Wmissing-include-dirs -Wunused-but-set-variable @@ -115,3 +115,10 @@ endmacro() macro(toolchain_cc_cpp_warning_error_misra_sane dest_var_name) set_ifndef(${dest_var_name} "-Werror=vla") endmacro() + +# List the warnings that are not supported for C++ compilations + +list(APPEND CXX_EXCLUDED_OPTIONS + -Werror=implicit-int + -Wold-style-definition + ) diff --git a/cmake/compiler/gcc/target_warnings.cmake b/cmake/compiler/gcc/target_warnings.cmake index 48988896f5163..34d4406fab22c 100644 --- a/cmake/compiler/gcc/target_warnings.cmake +++ b/cmake/compiler/gcc/target_warnings.cmake @@ -34,9 +34,9 @@ macro(toolchain_cc_warning_dw_1) -Wno-unused-parameter -Wmissing-declarations -Wmissing-format-attribute - -Wold-style-definition ) zephyr_cc_option( + -Wold-style-definition -Wmissing-prototypes -Wmissing-include-dirs -Wunused-but-set-variable @@ -108,3 +108,10 @@ endmacro() macro(toolchain_cc_cpp_warning_error_misra_sane dest_var_name) set_ifndef(${dest_var_name} "-Werror=vla") endmacro() + +# List the warnings that are not supported for C++ compilations + +list(APPEND CXX_EXCLUDED_OPTIONS + -Werror=implicit-int + -Wold-style-definition + ) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index f52a0da56537e..e4058a3040985 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -851,10 +851,10 @@ function(zephyr_check_compiler_flag lang option check) endfunction() function(zephyr_check_compiler_flag_hardcoded lang option check exists) - # -Werror=implicit-int is not supported for CXX and we are not able - # to automatically test for it because it produces a warning - # instead of an error during the test. - if((${lang} STREQUAL CXX) AND ("${option}" STREQUAL -Werror=implicit-int)) + # Various flags that are not supported for CXX may not be testable + # because they would produce a warning instead of an error during + # the test. Exclude them by toolchain-specific blacklist. + if((${lang} STREQUAL CXX) AND ("${option}" IN_LIST CXX_EXCLUDED_OPTIONS)) set(check 0 PARENT_SCOPE) set(exists 1 PARENT_SCOPE) else()