Skip to main content
Graduate
October 24, 2025
Question

can't modify gcc compile options from CMakeList

  • October 24, 2025
  • 4 replies
  • 464 views

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

 
    This topic has been closed for replies.

    4 replies

    Graduate II
    October 24, 2025
    ST Employee
    October 24, 2025

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

    dvescoviAuthor
    Graduate
    October 25, 2025

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

     

    Graduate II
    October 25, 2025

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

    Graduate II
    October 24, 2025

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

    October 24, 2025

    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 .

    dvescoviAuthor
    Graduate
    October 25, 2025

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