2026-01-15 7:48 AM
Hi all,
I've been using CubeIDE for a little while and decided to build my next project using the STM32 VSCode extensions, which I am still figuring out. I am also figuring out CMake for the first time, as I let CubeIDE handle all the build details previously. In the past, CubeIDE let me add .h and .c files through the UI and automatically added them to the build process. I've found that I can make my own files and still build by manually altering the CMakeLists.txt file under the stm32cubemx directory, but I find myself editing the ioc file often enough that I'd rather not do this every single time I want to make a small change, and as the project size grows. All the drivers I've needed so far are part of CubeMX's middlewares, but if I do download a third party driver I foresee this becoming an issue there as well. Are there any workarounds to include manual additions to the generated CMake file? I'd like to utilize an STM feature if possible before I try making my own cmake files or throwing a bash script at the issue. Thanks!
Solved! Go to Solution.
2026-01-15 8:06 AM
Edit: I was not aware there were user sections in the top level CMakeLists, I was looking in cmake/stm32cubemx. Think I figured it out.
2026-01-15 8:06 AM
Edit: I was not aware there were user sections in the top level CMakeLists, I was looking in cmake/stm32cubemx. Think I figured it out.
2026-03-18 2:46 PM
Frankly, I wish the project template would just include the following in the root CMakeLists.txt
After adding this, my life was a whole lot easier. Especially coming in fresh to the CMake realm
## Automagically add all source files in the project
file(GLOB_RECURSE SOURCES
# Add user sources here, e.g.:
"Core/Src/*.c"
"Drivers/STM32F4xx_HAL_Driver/Src/*.c"
#"Middlewares/*.c"
)
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
# Add user defined include paths
Core/Inc
)