Feature request: Add custom compiler flags to CMake generated project
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-13 6:52 AM - edited ‎2025-02-13 6:54 AM
The new CMake generation is great! It's very tastefully done (toochain file, presets, simple CMakeLists.txt, etc).
My request: I want to add some additional compiler flags (like `-Wconversion`) to my project.
In the top CMakeLists.txt I did:
```cmake
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
"-Wconversion"
)
```
The problem is that it applies to the HAL as well, generating an endless stream of errors.
I could create a new cmake target for my own functions, but I wish the generated CMake template would support this out of the box.
Regards,
Gabriel
- Labels:
-
STM32CubeMX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-13 8:03 AM - edited ‎2025-02-13 8:03 AM
Hello @fz_gabriel
Thank you for your contribution!
Have you tried to add the flags in gcc-arm-none-eabi.cmake file under the MCU specific flags section?
BR,
Souhaib
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-13 10:05 AM
Hi Souhaib,
Thanks for your answer.
I would prefer not to touch the toolchain file.
In my opinion, the toolchain file should be reserved for making the toolchain work (i.e. providing the linker flags), not for project-specific development flags like `-Wshadow` or `-Wpedantic`.
In an ideal world, I could add development flags to everything except the ST-HAL and CMSIS Driver.
Does that make sense?
Best,
Gabriel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-13 11:24 AM
Could this be done as the post-generation custom action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-14 9:32 AM
> Could this be done as the post-generation custom action?
Of course. I opened a feature request because, in my opinion, the generated CMake should separate ST-HAL from the rest of the program so I can use stricter debug flags on my code and not on ST's code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-18 2:44 AM
Hello @fz_gabriel
Actually, this request has been discussed in this thread, and an improvement of the CMake structure will be implemented in the coming CubeMX releases.
BR,
Souhaib
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.
