2024-10-07 11:42 AM
I used STM32CubeMX to create cmake project for STM32F411CEUx. In the cmake\stm32cubemx directory there is a CMakeLists.txt file which defines a library called "stm32cubemx". This library contains all the code. Why STM32CubeMX uses such approach to project structure? Why treat all code as a library?
I have problem with extending such project. There is a simple library I created for earlier project: a directory containing CMakeLists.txt and library source files. How can I add this lib to my project? In the past I used to insert the add_subdirectory(mylib) directive to the main CMakeLists.txt file but it doesn't work here. My lib is ignored and lib's include directories are not seen in main.c. I can add the directive inside cmake\stm32cubemx\CMakeLists.txt but then I get an error informing that my lib dir is not a subdirectory of cmake\stm32cubemx.
I can add my lib files next to Drivers, Core, and Middleware and add their paths to cmake\stm32cubemx\CMakeLists.txt, but then my lib is no longer a lib, it's just all the files merged together, without separate CMakeLists.txt for the lib. It looks like the stm32cubemx lib is a closed item, which can't reference external CMakeLists.txt.
2024-10-07 02:13 PM
CMake is too complicated. Stack Overflow is a good place to discuss it.
> Why treat all code as a library?
Why not treat the Cube generated stuff as library - vs. the user code?
2024-10-07 02:30 PM
I agree. But then STM32CubeMX shouldn't include main.c in the lib. That's the place where users start to add their code.
2024-10-08 10:09 AM
@Pavel A. While I agree that CMake can be complicated, it is not much more complicated than adding files to STM32CubeIDE based projects. Also, the model that ST chose for their CMake project templates should be well documented as it is part of the STM32CubeMX interface that developers are expected to use. ST owes it to the developers to provide documentation, tutorials and examples on best practices for creating projects using STM32CubeMX and CMake. Fumbling around with the exported files to find what works is painful, even for an experienced CMake user.
2024-10-09 05:44 AM - edited 2024-10-09 05:44 AM
> While I agree that CMake can be complicated, it is not much more complicated than adding files to STM32CubeIDE based projects.
What I meant is, there are many ways to add a source file to Cmake project. But in Eclipse CDT there's basically one way. Oh wait, two. And the links. Three. Hmmm. So much pain, everywhere ((