cancel
Showing results for 
Search instead for 
Did you mean: 

Feature request: Add custom compiler flags to CMake generated project

fz_gabriel
Associate II

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

5 REPLIES 5
Souhaib MAZHOUD
ST Employee

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.

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

 

Pavel A.
Super User

Could this be done as the post-generation custom action?

 

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

 

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.