cancel
Showing results for 
Search instead for 
Did you mean: 

can't modify gcc compile options from CMakeList

dvescovi
Associate III

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

 
7 REPLIES 7

Please format your post. https://community.st.com/t5/community-guidelines/how-to-insert-source-code/ta-p/693413

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
Julien D
ST Employee

@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.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Cartu38 OpenDev
Lead III

@dvescovi , sounds weird. Let's have a try to call for an unknown compiler directive:

Cartu38OpenDev_0-1761336387038.png

Myself I'm getting evidence this is considered:

Cartu38OpenDev_1-1761336451018.png

Here I've contributed to top most CMakeLists.txt file (the one not regenerated on next CubeMX code update)

JennyMods
Associate II

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 .

of course not. that is because you are not actually using any of the generated variables like hrtc in any custom code.

 

spam removal removed the "more information" link. Can you please supply as yours is the only reply that looks like it might actually work.

@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.