DEV Community

Discussion on: CMake on STM32 | Episode 1: the beginning

Collapse
 
pgradot profile image
Pierre Gradot • Edited

Glad you enjoyed the series :)

To be very honnest, I didn't write the toolchain myself. We have been using this file since 2018 and I don't remember how we got it.

Your comment seems pretty legit. I believe the toolchain file is wrong.

After some researches and experiments, I was able to reduce the toolchain file and the projects (both the sample project I am using for this series and the professional projects at my office) keep building successfully.

Here my shrinked file:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
Enter fullscreen mode Exit fullscreen mode

Since I never write toolchain files, I may be missing some points. For instance, I know that CMAKE_SYSTEM_VERSION should be set:

CMAKE_SYSTEM_NAME may be set explicitly when first configuring a new build tree in order to enable cross compiling. In this case the CMAKE_SYSTEM_VERSION variable must also be set explicitly.

But I have no idea of the value I should give it... The official toolchain file samples don't always set it.