Skip to content

Commit 5d382fa

Browse files
Nikolay Agishevcfriedt
authored andcommitted
toolchain: Move extra warning options to toolchain abstraction
Move extra warning option from generic twister script into compiler-dependent config files. ARCMWDT compiler doesn't support extra warning options ex. "-Wl,--fatal-warnings". To avoid build fails flag "disable_warnings_as_errors" should be passed to twister. This allows all warning messages and make atomatic test useles. Signed-off-by: Nikolay Agishev <[email protected]> (cherry picked from commit 0dec4cf)
1 parent e677cfd commit 5d382fa

File tree

10 files changed

+40
-8
lines changed

10 files changed

+40
-8
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ zephyr_compile_options(${OPTIMIZATION_FLAG})
162162
# @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig
163163
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,required>>)
164164

165+
# Extra warnings options for twister run
166+
if (CONFIG_COMPILER_WARNINGS_AS_ERRORS)
167+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warnings_as_errors>>)
168+
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,warnings_as_errors>>)
169+
zephyr_link_libraries($<TARGET_PROPERTY:linker,warnings_as_errors>)
170+
endif()
171+
165172
# @Intent: Obtain compiler specific flags for compiling under different ISO standards of C++
166173
if(CONFIG_CPLUSPLUS)
167174
# From kconfig choice, pick a single dialect.

Kconfig.zephyr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,13 @@ config NO_OPTIMIZATIONS
305305
help
306306
Compiler optimizations will be set to -O0 independently of other
307307
options.
308-
309308
endchoice
310309

310+
config COMPILER_WARNINGS_AS_ERRORS
311+
bool "Treat warnings as errors"
312+
help
313+
Turn on "warning as error" toolchain flags
314+
311315
config COMPILER_COLOR_DIAGNOSTICS
312316
bool "Enable colored diganostics"
313317
default y

cmake/compiler/arcmwdt/compiler_flags.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "")
132132
set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 "")
133133
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "")
134134

135+
# Flags for set extra warnigs (ARCMWDT asm can't recognize --fatal-warnings. Skip it)
136+
set_property(TARGET compiler PROPERTY warnings_as_errors -Werror)
137+
set_property(TARGET asm PROPERTY warnings_as_errors -Werror)
138+
135139
# Disable exeptions flag in C++
136140
set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions")
137141

cmake/compiler/compiler_flags_template.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a)
6565
set_property(TARGET compiler-cpp PROPERTY dialect_cpp20)
6666
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b)
6767

68+
# Extra warnings options for twister run
69+
set_property(TARGET compiler PROPERTY warnings_as_errors)
70+
set_property(TARGET asm PROPERTY warnings_as_errors)
71+
6872
# Flag for disabling exeptions in C++
6973
set_property(TARGET compiler-cpp PROPERTY no_exceptions)
7074

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 "-std=c++20"
137137
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "-std=c++2b"
138138
"-Wno-register" "-Wno-volatile")
139139

140+
# Flags for set extra warnigs (ARCMWDT asm can't recognize --fatal-warnings. Skip it)
141+
set_property(TARGET compiler PROPERTY warnings_as_errors -Werror)
142+
set_property(TARGET asm PROPERTY warnings_as_errors -Werror)
143+
140144
# Disable exeptions flag in C++
141145
set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions")
142146

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# Extra warnings options for twister run
4+
set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings)

cmake/linker/ld/clang/linker_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ if (NOT CONFIG_COVERAGE_GCOV)
33
set_property(TARGET linker PROPERTY coverage --coverage)
44
endif()
55

6+
# Extra warnings options for twister run
7+
set_property(TARGET linker PROPERTY ld_extra_warning_options -Wl,--fatal-warnings)
8+
69
# ld/clang linker flags for sanitizing.
710
check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address -fsanitize=address)
811

cmake/linker/ld/gcc/linker_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ if (NOT CONFIG_COVERAGE_GCOV)
77
set_property(TARGET linker PROPERTY coverage -lgcov)
88
endif()
99

10+
# Extra warnings options for twister run
11+
set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings)
12+
1013
# ld/gcc linker flags for sanitizing.
1114
check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address -lasan)
1215
check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_address -fsanitize=address)

cmake/linker/linker_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ check_set_linker_property(TARGET linker APPEND PROPERTY sanitize_undefined)
1414
# If memory reporting is a post build command, please use
1515
# cmake/bintools/bintools.cmake insted.
1616
check_set_linker_property(TARGET linker PROPERTY memusage)
17+
18+
# Extra warnings options for twister run
19+
set_property(TARGET linker PROPERTY warnings_as_errors)

scripts/pylib/twister/twisterlib.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,21 +2017,17 @@ def run_build(self, args=[]):
20172017
def run_cmake(self, args=[]):
20182018

20192019
if self.warnings_as_errors:
2020-
ldflags = "-Wl,--fatal-warnings"
2021-
cflags = "-Werror"
2022-
aflags = "-Wa,--fatal-warnings"
2020+
warnings_as_errors = 'y'
20232021
gen_defines_args = "--edtlib-Werror"
20242022
else:
2025-
ldflags = cflags = aflags = ""
2023+
warnings_as_errors = 'n'
20262024
gen_defines_args = ""
20272025

20282026
logger.debug("Running cmake on %s for %s" % (self.source_dir, self.platform.name))
20292027
cmake_args = [
20302028
f'-B{self.build_dir}',
20312029
f'-S{self.source_dir}',
2032-
f'-DEXTRA_CFLAGS="{cflags}"',
2033-
f'-DEXTRA_AFLAGS="{aflags}',
2034-
f'-DEXTRA_LDFLAGS="{ldflags}"',
2030+
f'-DCONFIG_COMPILER_WARNINGS_AS_ERRORS={warnings_as_errors}',
20352031
f'-DEXTRA_GEN_DEFINES_ARGS={gen_defines_args}',
20362032
f'-G{self.generator}'
20372033
]

0 commit comments

Comments
 (0)