cancel
Showing results for 
Search instead for 
Did you mean: 

Feature request: Add custom compiler flags to CMake generated project

fz_gabriel
Associate

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

2 REPLIES 2
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   

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