diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e2ede86fd..5f6f13f426 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -603,12 +603,7 @@ add_subdirectory(lib) # property which is set implicitly for custom command outputs include(misc/generated/CMakeLists.txt) -if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) - add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) -else() - add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) -endif() - +add_subdirectory(soc) add_subdirectory(boards) add_subdirectory(subsys) add_subdirectory(drivers) diff --git a/arch/CMakeLists.txt b/arch/CMakeLists.txt index ef30d760bb..e93b810fb0 100644 --- a/arch/CMakeLists.txt +++ b/arch/CMakeLists.txt @@ -1,5 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +add_compile_options($) + add_definitions(-D__ZEPHYR_SUPERVISOR__) include_directories( diff --git a/boards/CMakeLists.txt b/boards/CMakeLists.txt index 943e52667e..02e9e158bb 100644 --- a/boards/CMakeLists.txt +++ b/boards/CMakeLists.txt @@ -8,6 +8,11 @@ if(EXISTS ${BOARD_DIR}/CMakeLists.txt) set(build_dir boards/${ARCH}/${BOARD}) else() unset(build_dir) + + # FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. + # + # For now, only enable warning for shadow variables for in-tree boards. + add_compile_options($) endif() add_subdirectory(${BOARD_DIR} ${build_dir}) diff --git a/cmake/compiler/arcmwdt/compiler_flags.cmake b/cmake/compiler/arcmwdt/compiler_flags.cmake index 2b85dadf5a..8eeaf2fa37 100644 --- a/cmake/compiler/arcmwdt/compiler_flags.cmake +++ b/cmake/compiler/arcmwdt/compiler_flags.cmake @@ -203,3 +203,6 @@ if(CONFIG_ARCMWDT_LIBC) # to ASM builds (which may use 'stdbool.h'). set_property(TARGET asm APPEND PROPERTY required "-I${NOSTDINC}") endif() + +# Remove after testing that -Wshadow works +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/cmake/compiler/armclang/compiler_flags.cmake b/cmake/compiler/armclang/compiler_flags.cmake index 3d0f713da4..8cb3c46ae0 100644 --- a/cmake/compiler/armclang/compiler_flags.cmake +++ b/cmake/compiler/armclang/compiler_flags.cmake @@ -7,3 +7,6 @@ set_property(TARGET asm APPEND PROPERTY required "--target=${triple}") # Only the ARM Compiler C library is currently supported. set_compiler_property(PROPERTY nostdinc) + +# Remove after testing that -Wshadow works +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index 5f15d1b800..1476c45e85 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -130,3 +130,6 @@ set_compiler_property(PROPERTY no_position_independent) # gen_kobject_list.py is does not understand it and end up identifying objects as if # they had the same address. set_compiler_property(PROPERTY no_global_merge) + +# Compiler flag for warning about shadow variables +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 741d49074f..b77dfa4123 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -225,3 +225,5 @@ set_compiler_property(PROPERTY no_position_independent ) set_compiler_property(PROPERTY no_global_merge "") + +set_compiler_property(PROPERTY warning_shadow_variables -Wshadow) diff --git a/cmake/compiler/icx/compiler_flags.cmake b/cmake/compiler/icx/compiler_flags.cmake index 5476c6603f..1e038caaf9 100644 --- a/cmake/compiler/icx/compiler_flags.cmake +++ b/cmake/compiler/icx/compiler_flags.cmake @@ -1,2 +1,5 @@ include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake) + +# Remove after testing that -Wshadow works +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/cmake/compiler/xcc/compiler_flags.cmake b/cmake/compiler/xcc/compiler_flags.cmake index d6affa48ad..28f76d5d80 100644 --- a/cmake/compiler/xcc/compiler_flags.cmake +++ b/cmake/compiler/xcc/compiler_flags.cmake @@ -12,3 +12,6 @@ set_compiler_property(PROPERTY warning_error_misra_sane) # XCC does not support -fno-pic and -fno-pie set_compiler_property(PROPERTY no_position_independent "") + +# Remove after testing that -Wshadow works +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/cmake/compiler/xt-clang/compiler_flags.cmake b/cmake/compiler/xt-clang/compiler_flags.cmake index 62c50316b0..593e384284 100644 --- a/cmake/compiler/xt-clang/compiler_flags.cmake +++ b/cmake/compiler/xt-clang/compiler_flags.cmake @@ -31,3 +31,6 @@ endif() # Clang version used by Xtensa does not support -fno-pic and -fno-pie set_compiler_property(PROPERTY no_position_independent "") + +# Remove after testing that -Wshadow works +set_compiler_property(PROPERTY warning_shadow_variables) diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index a9caf9f032..749285d29a 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,5 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +add_compile_options($) + add_definitions(-D__ZEPHYR_SUPERVISOR__) add_subdirectory(disk) diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 9e7602bfbd..087e96b081 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -38,6 +38,9 @@ target_link_libraries(kernel INTERFACE ${libkernel}) else() +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +add_compile_options($) + list(APPEND kernel_files main_weak.c banner.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index dec4150c9c..6fe18f6399 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +add_compile_options($) + add_subdirectory(crc) if(NOT CONFIG_EXTERNAL_LIBC) add_subdirectory(libc) diff --git a/soc/CMakeLists.txt b/soc/CMakeLists.txt new file mode 100644 index 0000000000..6706168281 --- /dev/null +++ b/soc/CMakeLists.txt @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: Apache-2.0 + +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +# +# Limit warning of shadow variables to in-tree SoC files for now. +cmake_path(IS_PREFIX ZEPHYR_BASE "${SOC_DIR}" NORMALIZE _SOC_IS_IN_TREE) +if(_SOC_IS_IN_TREE) + add_compile_options($) +endif() +unset(_SOC_IS_IN_TREE) + +if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt) + add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH}) +else() + add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH}) +endif() diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index de5c85f51b..3c508d6e8e 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -1,5 +1,16 @@ # SPDX-License-Identifier: Apache-2.0 +# FIXME: SHADOW_VARS: move this before adding shadow variable warning below. +# This is because, in some build configurations, the external lorawan module +# is pulled in as though the source files are in main repo. This results in +# shadow variable warnings being active on these files. Until the module has +# fixed those shadow variables, keep this here before add_compile_options() +# below. +add_subdirectory_ifdef(CONFIG_LORAWAN lorawan) + +# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally. +add_compile_options($) + add_subdirectory(canbus) add_subdirectory(debug) add_subdirectory(fb) @@ -29,7 +40,6 @@ add_subdirectory_ifdef(CONFIG_EMUL emul) add_subdirectory_ifdef(CONFIG_IMG_MANAGER dfu) add_subdirectory_ifdef(CONFIG_INPUT input) add_subdirectory_ifdef(CONFIG_JWT jwt) -add_subdirectory_ifdef(CONFIG_LORAWAN lorawan) add_subdirectory_ifdef(CONFIG_NET_BUF net) add_subdirectory_ifdef(CONFIG_RETENTION retention) add_subdirectory_ifdef(CONFIG_SENSING sensing)