From 8650b150b9b55319dd52a43650f0401daba3d60c Mon Sep 17 00:00:00 2001 From: Danny Oerndrup Date: Mon, 6 May 2019 14:34:43 +0200 Subject: [PATCH] cmake: Toolchain abstraction: Introduce toolchain_cc_warning_dw_[1-3] The introduced macros are placeholders for the cmake parameter warning level. 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 | 43 ++---------------- cmake/compiler/clang/target.cmake | 1 + cmake/compiler/gcc/target.cmake | 1 + cmake/compiler/gcc/target_warnings.cmake | 57 ++++++++++++++++++++++++ cmake/compiler/host-gcc/target.cmake | 1 + cmake/compiler/xcc/target.cmake | 1 + 6 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 cmake/compiler/gcc/target_warnings.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1672389fffa..a9073bd28b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,52 +240,17 @@ endif() # W=2 - warnings that occur quite often but may still be relevant # W=3 - the more obscure warnings, can most likely be ignored # ========================================================================== +# @Intent Add cmake -DW toolchain supported warnings, if any if(W MATCHES "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 - ) + toolchain_cc_warning_dw_1() endif() if(W MATCHES "2") - zephyr_compile_options( - -Waggregate-return - -Wcast-align - -Wdisabled-optimization - -Wnested-externs - -Wshadow - ) - zephyr_cc_option( - -Wlogical-op - -Wmissing-field-initializers - ) + toolchain_cc_warning_dw_2() endif() if(W MATCHES "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 - ) + toolchain_cc_warning_dw_3() endif() diff --git a/cmake/compiler/clang/target.cmake b/cmake/compiler/clang/target.cmake index 00bb8dd2618..a78dd0e524d 100644 --- a/cmake/compiler/clang/target.cmake +++ b/cmake/compiler/clang/target.cmake @@ -79,6 +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) macro(toolchain_cc_security_fortify) # No op, clang doesn't understand fortify at all diff --git a/cmake/compiler/gcc/target.cmake b/cmake/compiler/gcc/target.cmake index 47d8741c5c8..f717fb9a373 100644 --- a/cmake/compiler/gcc/target.cmake +++ b/cmake/compiler/gcc/target.cmake @@ -139,3 +139,4 @@ include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_optimizations.cmake) include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_cpp.cmake) include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_asm.cmake) include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_baremetal.cmake) +include(${ZEPHYR_BASE}/cmake/compiler/${COMPILER}/target_warnings.cmake) diff --git a/cmake/compiler/gcc/target_warnings.cmake b/cmake/compiler/gcc/target_warnings.cmake new file mode 100644 index 00000000000..19cc146b394 --- /dev/null +++ b/cmake/compiler/gcc/target_warnings.cmake @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: Apache-2.0 + +# See root CMakeLists.txt for description and expectations of these macros + +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() diff --git a/cmake/compiler/host-gcc/target.cmake b/cmake/compiler/host-gcc/target.cmake index 8eaf816e62a..0ccd4d8dee3 100644 --- a/cmake/compiler/host-gcc/target.cmake +++ b/cmake/compiler/host-gcc/target.cmake @@ -88,3 +88,4 @@ 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) diff --git a/cmake/compiler/xcc/target.cmake b/cmake/compiler/xcc/target.cmake index 1db90770bfe..779dc6ca5f2 100644 --- a/cmake/compiler/xcc/target.cmake +++ b/cmake/compiler/xcc/target.cmake @@ -82,3 +82,4 @@ 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)