Skip to content

Commit 436197e

Browse files
carlescufinordicjm
authored andcommitted
[nrf fromtree] cmake: Add a new no_deprecation_warning compiler flag
Commit be40d854c2ccacf14ca3fcfb01bffdc9b075c6c9 introduced the ability of building Zephyr with deprecation warnings enabled, by making COMPILER_WARNINGS_AS_ERRORS depend on the newly added DEPRECATION_TEST Kconfig option. This has the downside of disabling **all** warnings, not only the deprecation ones. This patch instead makes DEPRECATION_TEST disable only the deprecation warning, but leaves COMPILER_WARNINGS_AS_ERRORS enabled. This has the advantage of being able to see other unrelated warnings (and fail if they appear) but has the disadvantage of not printing out the deprecation warnings themselves (since they are disabled). Signed-off-by: Carles Cufi <[email protected]> (cherry picked from commit 892ac07)
1 parent 1eb30be commit 436197e

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,19 @@ zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_str
159159
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler-cpp,no_strict_aliasing>>)
160160

161161
# Extra warnings options for twister run
162-
if (CONFIG_COMPILER_WARNINGS_AS_ERRORS)
162+
if(CONFIG_COMPILER_WARNINGS_AS_ERRORS)
163163
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,warnings_as_errors>>)
164164
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,warnings_as_errors>>)
165165
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,warnings_as_errors>>)
166166
zephyr_link_libraries($<TARGET_PROPERTY:linker,warnings_as_errors>)
167167
endif()
168168

169+
if(CONFIG_DEPRECATION_TEST)
170+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_deprecation_warning>>)
171+
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,no_deprecation_warning>>)
172+
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,no_deprecation_warning>>)
173+
endif()
174+
169175
# @Intent: Set compiler flags to enable buffer overflow checks in libc functions
170176
# @details:
171177
# Kconfig.zephyr "Detect buffer overflows in libc calls" is a kconfig choice,

Kconfig.zephyr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ config LTO
542542

543543
config COMPILER_WARNINGS_AS_ERRORS
544544
bool "Treat warnings as errors"
545-
depends on !DEPRECATION_TEST
546545
help
547546
Turn on "warning as error" toolchain flags
548547

cmake/compiler/compiler_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ set_compiler_property(PROPERTY no_strict_aliasing)
7676
set_property(TARGET compiler PROPERTY warnings_as_errors)
7777
set_property(TARGET asm PROPERTY warnings_as_errors)
7878

79+
set_property(TARGET compiler PROPERTY no_deprecation_warning)
80+
set_property(TARGET asm PROPERTY no_deprecation_warning)
81+
7982
# Flag for disabling exceptions in C++
8083
set_property(TARGET compiler-cpp PROPERTY no_exceptions)
8184

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ set_compiler_property(PROPERTY no_strict_aliasing -fno-strict-aliasing)
153153
set_property(TARGET compiler PROPERTY warnings_as_errors -Werror)
154154
set_property(TARGET asm PROPERTY warnings_as_errors -Werror -Wa,--fatal-warnings)
155155

156+
# Deprecation warning
157+
set_property(TARGET compiler PROPERTY no_deprecation_warning -Wno-deprecated-declarations)
158+
set_property(TARGET asm PROPERTY no_deprecation_warning -Wno-deprecated-declarations)
159+
156160
# Disable exceptions flag in C++
157161
set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions")
158162

include/zephyr/toolchain/gcc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,13 @@ do { \
334334
#define __WARN1(s) _Pragma(#s)
335335

336336
/* Generic message */
337-
#ifndef __DEPRECATED_MACRO
337+
#ifndef CONFIG_DEPRECATION_TEST
338338
#define __DEPRECATED_MACRO __WARN("Macro is deprecated")
339339
/* When adding this, remember to follow the instructions in
340340
* https://docs.zephyrproject.org/latest/develop/api/api_lifecycle.html#deprecated
341341
*/
342+
#else
343+
#define __DEPRECATED_MACRO
342344
#endif
343345

344346
/* These macros allow having ARM asm functions callable from thumb */

include/zephyr/toolchain/iar/iccarm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,14 @@ do { \
243243
#define __WARN1(s) __PRAGMA(message = #s)
244244

245245
/* Generic message */
246-
#ifndef __DEPRECATED_MACRO
246+
#ifndef CONFIG_DEPRECATION_TEST
247247
#define __DEPRECATED_MACRO __WARN("Macro is deprecated")
248+
#else
249+
#define __DEPRECATED_MACRO
248250
#endif
249251

252+
253+
250254
/* These macros allow having ARM asm functions callable from thumb */
251255

252256
#if defined(_ASMLANGUAGE)

tests/kernel/pipe/deprecated/pipe/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
cmake_minimum_required(VERSION 3.20.0)
4-
set(CMAKE_C_FLAGS "-D__deprecated=\"/* deprecated */\" -D__DEPRECATED_MACRO=\"/* deprecated_macro*/\"")
54
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
65
project(pipe)
76

tests/kernel/workq/work/src/main.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
* about the use of that API.
99
*/
1010
#include <zephyr/toolchain.h>
11-
#undef __deprecated
12-
#define __deprecated
13-
#undef __DEPRECATED_MACRO
14-
#define __DEPRECATED_MACRO
15-
1611
#include <zephyr/ztest.h>
1712

1813
#define STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)

tests/kernel/workq/work_queue/src/main.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
* about the use of that API.
1111
*/
1212
#include <zephyr/toolchain.h>
13-
#undef __deprecated
14-
#define __deprecated
15-
#undef __DEPRECATED_MACRO
16-
#define __DEPRECATED_MACRO
17-
1813
#include <zephyr/kernel.h>
1914
#include <zephyr/ztest.h>
2015
#include <zephyr/tc_util.h>

0 commit comments

Comments
 (0)