cancel
Showing results for 
Search instead for 
Did you mean: 

stm32cubemx cmake code generation

Tizio1234
Associate II

I've been using the recently added CMake generation feature of cubemx, as of now it creates an INTERFACE library for both project related and drivers related sources, the problem is that those sources get propagated for every external library that needs stm32cube drivers.

One workaround is creating a STATIC wrapper library like this:

# Retrieve properties from the INTERFACE library generated by STM32CubeMX
get_target_property(STM32_SOURCES stm32cubemx SOURCES)
get_target_property(STM32_INCLUDE_DIRS stm32cubemx INCLUDE_DIRECTORIES)
get_target_property(STM32_COMPILE_DEFINITIONS stm32cubemx COMPILE_DEFINITIONS)
get_target_property(STM32_LINK_DIRECTORIES stm32cubemx LINK_DIRECTORIES)
get_target_property(STM32_LINK_LIBRARIES stm32cubemx LINK_LIBRARIES)

# Log the properties
message(STATUS "STM32_SOURCES: ${STM32_SOURCES}")
message(STATUS "STM32_INCLUDE_DIRS: ${STM32_INCLUDE_DIRS}")
message(STATUS "STM32_COMPILE_DEFINITIONS: ${STM32_COMPILE_DEFINITIONS}")
message(STATUS "STM32_LINK_DIRECTORIES: ${STM32_LINK_DIRECTORIES}")
message(STATUS "STM32_LINK_LIBRARIES: ${STM32_LINK_LIBRARIES}")

The problem is that the INTERFACE library must still be linked against the root project because there are some sources that need to be propagated to the project, but drivers don't need to be propagated.

This causes the compilation of stm32cubemx sources twice, and I believe it consumes more flash space because of cloned sources(doing this the normal way, sources would get recompiled every time a library needs the drivers), and it's pretty annoying.

Is this going to get fixed(by creating an INTERFACE library for project related and a STATIC library for driver related, for example)?

0 REPLIES 0