2024-06-19 02:24 AM - edited 2024-06-20 12:34 AM
Hello
After some work with STM32CubeMX CMake generation and discussions with good CMake user, I really think that, when generating a projet with STM32CubeMX, it should not be an INTERFACE library (or at least not only that)
As a CMake user said to me, the purpose of INTERFACE library is the following:
When a target represents some collection of requirements that doesn’t involve an actual library file. For example, a collection of flags or includes.
The main problems I have when using the current CMake generation:
For me, STM32CubeMX CMake generated project should be more like that:
Integrating CMake project generation in STM32CubeMX is really a good idea. For me it is really a major improvement of the Cube suite. But for now it is not usable without some modifications.
I would be really happy to talk of the subject with ST employees and to see (some of) those modifications integrated in the next STM32CubeMX.
Regards
Antoine
2025-01-07 06:41 AM - edited 2025-01-07 06:56 AM
@Stephen_PP wrote:
A relatively low-effort improvement (from the ST side) is to add USER sections to the CMAKE files for when they are generated; same system that already exists for the source files (e.g. main.c).
The idea was to have "separation of concern" between CMake files managed by MX vs what CMake-files you develop as part of your project... This can of course be challenged. But if this request is only because our first CMake structure has some bugs, then I think it is better to try to fix those bugs.
But if you can describe some use cases (beyond INTERFACE bug) where you need to modify what MX generates in terms of CMake-files, then please share your thoughts. We are eager to improve.
@Stephen_PP wrote:
Not to mention that the CubeMx is using a Linker generation script from 2019, even though there is a perfectly up-to-date generation script being used in the CubeIde...
And additional issues, like unsupported/old CMAKE flags from old versions of cmake instead of up-to-date flags. (e.g. using CMAKE_C_LINK_FLAGS instead of CMAKE_EXE_LINKER_FLAGS).
Will bug report this! Ticket number: 199761
2025-01-07 11:12 AM
The request for the USER section is indeed to attempt to fix bugs with the cmake structure.
I suppose i have a few other changes:
Methodology:
I ran a compilation of a project which was created in the STM32CubeIDE (non-Cmake)[this project performed as expected], and checked it against a build done with a project created from the Cmake-Generator in STM32CubeMX.
In doing this comparison, i looked at all statements for all steps (assembler, compiler, linker) and modified the .cmake file (generated by the STM32CubeMX) so that the build commands were identical to the build commands from the STM32CubeIDE project.
Here is a screenshot of a Diff between what the current CubeMX generates in the .cmake file (left) and what I believe is the more correct implementation(Right).
Issues:
CMAKE_C_FLAGS are used for both Linker AND Compiler; Flags for the Assembler should not be included here.
Optimization flags are being placed in the CMAKE_C_FLAGS depending on the CMAKE_BUILD_TYPE - Why do that when cmake provides flags for specific configurations (e.g. CMAKE_C_FLAGS_DEBUG, CMAKE_C_FLAGS_RELEASE, etc.).
Some flags are being included in build steps that don't need them - the optimization flags (e.g. -Og) does not need to be included in the Assembler --- the TARGET_FLAGS do not need to be included in the Linker.
Right now, with just `-Wall` flag, i am getting compilation warnings for MX-Generated/Supplied code - I want a way to turn off compiler warnings for just the MX-generated code (this is difficult right now since the MX-Generated cmake includes the -Wextra and -Wpedantic flags) which i cannot do unless i modify the .cmake file.
Request:
It would be awesome if the STM32CubeMx could use information from a .cproject file to populate things like optimization and other build flags. Really this is what bothers me, since i cannot export my existing STM32CubeIde project to a CMake project and the .cproject contains much of the project-specific information. (I realize this may be outside your area)
Please Note: Some of these things i've mentioned may be fixable with the current cmake structure; However I am unable to figure out how to do so.
2025-01-07 02:21 PM
Thx, I'll look into it tomorrow.
2025-01-13 02:03 AM
Hello @mattias norlander
Sorry I do not have much time this days to have a look at this new feature (working on a project that is no more at a CubeMX phase)
But from a very quick test I made:
It was 2 important point I mentioned in my first post. So for me this new structure seems a good improvement compare to the first one.
Thank
Antoine