From cbbbdeaae52725f8fd4c35044f2694c9ecbb6831 Mon Sep 17 00:00:00 2001 From: Danny Oerndrup Date: Mon, 6 May 2019 15:21:58 +0200 Subject: [PATCH] cmake: Toolchain abstraction: Introduce toolchain_cc_warning_extended This is placeholder for extended warning flags, likely to change between toolchains. The intent here is to abstract Zephyr's dependence on toolchains, thus allowing for easier porting to other, perhaps commercial, toolchains and/or usecases. No functional change expected. Signed-off-by: Danny Oerndrup --- CMakeLists.txt | 28 ++----- cmake/compiler/clang/target.cmake | 2 +- cmake/compiler/clang/target_warnings.cmake | 96 ++++++++++++++++++++++ cmake/compiler/gcc/target_warnings.cmake | 8 ++ 4 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 cmake/compiler/clang/target_warnings.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 993b91ccd4e..44aafae039c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,8 @@ if(W MATCHES "3") toolchain_cc_warning_dw_3() endif() +# @Intent Add extended, more specific, toolchain warning flags +toolchain_cc_warning_extended() # Allow the user to inject options when calling cmake, e.g. # 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..' @@ -274,29 +276,9 @@ zephyr_compile_options(${COMPILER_OPT_AS_LIST}) # TODO: Include arch compiler options at this point. -if(CMAKE_C_COMPILER_ID STREQUAL "Clang") - zephyr_cc_option( - #FIXME: need to fix all of those - -Wno-sometimes-uninitialized - -Wno-shift-overflow - -Wno-missing-braces - -Wno-self-assign - -Wno-address-of-packed-member - -Wno-unused-function - -Wno-initializer-overrides - -Wno-section - -Wno-unknown-warning-option - -Wno-unused-variable - -Wno-format-invalid-specifier - -Wno-gnu - # comparison of unsigned expression < 0 is always false - -Wno-tautological-compare - ) -else() # GCC assumed - zephyr_cc_option( - -Wno-unused-but-set-variable - -fno-reorder-functions - ) +if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang") + # GCC assumed + zephyr_cc_option(-fno-reorder-functions) if(NOT ${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "xcc") zephyr_cc_option(-fno-defer-pop) diff --git a/cmake/compiler/clang/target.cmake b/cmake/compiler/clang/target.cmake index a78dd0e524d..31b53ce8df1 100644 --- a/cmake/compiler/clang/target.cmake +++ b/cmake/compiler/clang/target.cmake @@ -79,7 +79,7 @@ include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_optimizations.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_cpp.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_asm.cmake) include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_baremetal.cmake) -include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_warnings.cmake) +include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake) macro(toolchain_cc_security_fortify) # No op, clang doesn't understand fortify at all diff --git a/cmake/compiler/clang/target_warnings.cmake b/cmake/compiler/clang/target_warnings.cmake new file mode 100644 index 00000000000..42591b09bc2 --- /dev/null +++ b/cmake/compiler/clang/target_warnings.cmake @@ -0,0 +1,96 @@ +# SPDX-License-Identifier: Apache-2.0 + +# See root CMakeLists.txt for description and expectations of this macro + +macro(toolchain_cc_warning_base) + + zephyr_compile_options( + -Wall + -Wformat + -Wformat-security + -Wno-format-zero-length + -Wno-main + ) + + zephyr_cc_option(-Wno-pointer-sign) + + # Prohibit void pointer arithmetic. Illegal in C99 + zephyr_cc_option(-Wpointer-arith) + +endmacro() + +macro(toolchain_cc_warning_dw_1) + + zephyr_compile_options( + -Wextra + -Wunused + -Wno-unused-parameter + -Wmissing-declarations + -Wmissing-format-attribute + -Wold-style-definition + ) + zephyr_cc_option( + -Wmissing-prototypes + -Wmissing-include-dirs + -Wunused-but-set-variable + -Wno-missing-field-initializers + ) + +endmacro() + +macro(toolchain_cc_warning_dw_2) + + zephyr_compile_options( + -Waggregate-return + -Wcast-align + -Wdisabled-optimization + -Wnested-externs + -Wshadow + ) + zephyr_cc_option( + -Wlogical-op + -Wmissing-field-initializers + ) + +endmacro() + +macro(toolchain_cc_warning_dw_3) + + zephyr_compile_options( + -Wbad-function-cast + -Wcast-qual + -Wconversion + -Wpacked + -Wpadded + -Wpointer-arith + -Wredundant-decls + -Wswitch-default + ) + zephyr_cc_option( + -Wpacked-bitfield-compat + -Wvla + ) + +endmacro() + +macro(toolchain_cc_warning_extended) + + zephyr_cc_option( + #FIXME: need to fix all of those + -Wno-sometimes-uninitialized + -Wno-shift-overflow + -Wno-missing-braces + -Wno-self-assign + -Wno-address-of-packed-member + -Wno-unused-function + -Wno-initializer-overrides + -Wno-section + -Wno-unknown-warning-option + -Wno-unused-variable + -Wno-format-invalid-specifier + -Wno-gnu + # comparison of unsigned expression < 0 is always false + -Wno-tautological-compare + ) + +endmacro() \ No newline at end of file diff --git a/cmake/compiler/gcc/target_warnings.cmake b/cmake/compiler/gcc/target_warnings.cmake index 775273d202e..9b3cb384afa 100644 --- a/cmake/compiler/gcc/target_warnings.cmake +++ b/cmake/compiler/gcc/target_warnings.cmake @@ -72,3 +72,11 @@ macro(toolchain_cc_warning_dw_3) ) endmacro() + +macro(toolchain_cc_warning_extended) + + zephyr_cc_option( + -Wno-unused-but-set-variable + ) + +endmacro()