2025-10-24 4:18 AM - last edited on 2025-10-24 10:56 AM by Julien D
Not sure if this belongs in STM32CubeMX or STM32CubeIDE for VSCode.
I have a CMake project generated from CubeMX.
When I build within VSCode IDE with the STM32 Extension I get several nocent warnings I would like to eliminate.
Some of these are deep in the HAL and/or the generated code produced by CubeMX.
ex:
warning: declaration of 'hrtc' shadows a global declaration
warning: cast increases required alignment of target type [-Wcast-align]
etc...I tried several modifications to my top level CMakeLists.txt suggested by AI to suppress these warnings but NONE work.
I know this line:
include("cmake/gcc-arm-none-eabi.cmake")brings in all the gcc compile options but I don't want to modify this file as it gets regenerated every time I do a CubeMX "GENERATE CODE".
Things I have tried are:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shadow")
target_compile_options(my_target PRIVATE -Wno-shadow)
set(MCU_GCC_FLAGS "${MCU_GCC_FLAGS} -Wno-shadow")
add_compile_options(${MCU_GCC_FLAGS})
add_compile_options(-Wno-shadow)
set(CMAKE_C_FLAGS_INIT "-Wno-shadow") include("cmake/gcc-arm-none-eabi.cmake")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:-Wno-shadow>")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY COMPILE_OPTIONS -Wno-shadow)NONE of these work.
HELP
2025-10-24 5:01 AM
Please format your post. https://community.st.com/t5/community-guidelines/how-to-insert-source-code/ta-p/693413
2025-10-24 11:16 AM
@dvescovi, could you give us more details about your project?
I generated a quick MX project for a random board and configured RTC but none of these warnings are printed at build.
2025-10-24 1:09 PM
@dvescovi , sounds weird. Let's have a try to call for an unknown compiler directive:
Myself I'm getting evidence this is considered:
Here I've contributed to top most CMakeLists.txt file (the one not regenerated on next CubeMX code update)
2025-10-24 1:16 PM - last edited on 2025-10-24 2:40 PM by Pavel A.
Spam link removed. Spam not allowed here.
It looks like the issue is that CubeMX regenerates the toolchain CMake fragments, effectively overwriting user-level flags every time. A more stable approach is to inject your warning suppression flags after the toolchain file is included, using a persistent CMake overlay or a separate post_configure.cmake that gets called manually.
You can also verify whether the CMAKE_TRY_COMPILE_PLATFORM_VARIABLES or global CMAKE_USER_MAKE_RULES_OVERRIDE variable is being respected in your STM32 extension setup — in some VSCode-based STM32 configurations, these overrides are ignored unless explicitly linked to the target through set_target_properties().
For a more detailed explanation on handling regenerated CMake projects and safely extending compile options without touching vendor files, you can check more information .
2025-10-25 4:02 AM
of course not. that is because you are not actually using any of the generated variables like hrtc in any custom code.
2025-10-25 4:08 AM
spam removal removed the "more information" link. Can you please supply as yours is the only reply that looks like it might actually work.
2025-10-25 6:35 AM
@dvescovi possibly share your .ioc file.
Myself I've answered not about any code (htrc or ..) but about fact it sounds ok to add compiler directives Thanks end user CMakeLists.txt which is not regenerated.