coding_guideline: Add an option to enforce rules
Add a Kconfig option to enable compiler flags that help to enforce
some code guideline rules.
Note: As the current code base is not in compliance with the adopted
code guideline, some rules will generate warnings during the
build. This is intended to help to spot violations.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f4d078..6985507 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -215,6 +215,14 @@
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${CPP_MISRA_SANE_FLAG}>)
endif()
+# This is intend to be temporary. Once we have fixed the violations that
+# prevents build Zephyr, these flags shall be part of the default flags.
+if(CONFIG_CODING_GUIDELINE_CHECK)
+ # @Intent: Obtain toolchain compiler flags relating to coding guideline
+ toolchain_cc_warning_error_coding_guideline_check(CC_CODING_GUIDELINE_CHECK_FLAG)
+ zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:${CC_CODING_GUIDELINE_CHECK_FLAG}>)
+endif()
+
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
toolchain_cc_imacros(${AUTOCONF_H})
diff --git a/Kconfig.zephyr b/Kconfig.zephyr
index 3fe5f35..a76ca8c 100644
--- a/Kconfig.zephyr
+++ b/Kconfig.zephyr
@@ -171,6 +171,12 @@
menu "Compiler Options"
+config CODING_GUIDELINE_CHECK
+ bool "Enforce coding guideline rules"
+ help
+ Use available compiler flags to check coding guideline rules during
+ the build.
+
config NATIVE_APPLICATION
bool "Build as a native host application"
help
diff --git a/cmake/compiler/clang/target_warnings.cmake b/cmake/compiler/clang/target_warnings.cmake
index cd2b970..3ae0473 100644
--- a/cmake/compiler/clang/target_warnings.cmake
+++ b/cmake/compiler/clang/target_warnings.cmake
@@ -116,6 +116,14 @@
set_ifndef(${dest_var_name} "-Werror=vla")
endmacro()
+macro(toolchain_cc_warning_error_coding_guideline_check dest_var_name)
+ if (NOT ${dest_var_name})
+ set(${dest_var_name}
+ -Wvla
+ )
+ endif()
+endmacro()
+
# List the warnings that are not supported for C++ compilations
list(APPEND CXX_EXCLUDED_OPTIONS
diff --git a/cmake/compiler/gcc/target_warnings.cmake b/cmake/compiler/gcc/target_warnings.cmake
index 34d4406..cb244b0 100644
--- a/cmake/compiler/gcc/target_warnings.cmake
+++ b/cmake/compiler/gcc/target_warnings.cmake
@@ -109,6 +109,14 @@
set_ifndef(${dest_var_name} "-Werror=vla")
endmacro()
+macro(toolchain_cc_warning_error_coding_guideline_check dest_var_name)
+ if (NOT ${dest_var_name})
+ set(${dest_var_name}
+ -Wvla
+ )
+ endif()
+endmacro()
+
# List the warnings that are not supported for C++ compilations
list(APPEND CXX_EXCLUDED_OPTIONS