cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX 6.14 changed CMake generation, breaks project where generated code is static library

tdecker2
Associate III

I used to have the CubeMX generated code as a library in my main project: /BSP/CubeMX/ contains the .ioc and generated code.

I could include the CubeMX 6.13 (and earlier I think) generated CmakeLists.txt and have all generated code compiled as a static library:

project(BSP)
add_library(${PROJECT_NAME} STATIC)
add_subdirectory(CubeMX/cmake/stm32cubemx SYSTEM)
target_link_libraries(${PROJECT_NAME} PRIVATE stm32cubemx)

# Suppress compile warnings in 3rd-party C code
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter #-Wno-conversion)

#expose header files from stm32cubemx to public
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC "$<TARGET_PROPERTY:stm32cubemx,INTERFACE_INCLUDE_DIRECTORIES>")

I needed some workarounds for getting everything to work, but I had a environment where I could re-generate CubeMX code and the whole project keeps on compiling without the need to fix something manually.

Now the CubeMX generated CMakeLists.txt changed its content and I'm having some trouble to get my project adapted to the new situation.

add_library(stm32cubemx INTERFACE)
[...]
add_library(STM32_Drivers OBJECT)
[...]
set(MX_Application_Src
    ${CMAKE_SOURCE_DIR}/Core/Src/main.c
    ${CMAKE_SOURCE_DIR}/Core/Src/gpio.c
    ${CMAKE_SOURCE_DIR}/Core/Src/adc.c
[...]
}
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
target_link_libraries(${CMAKE_PROJECT_NAME} STM32_Drivers)

 

The CMakeList.txt now adds "itself" to the top-level CMake project ($CMAKE_PROJECT_NAME). I think this is very weird behaviour. But I'm not a CMake expert. Now I get CMake errors:

Cannot specify sources for target "TopLevelName" which is not built by this project.

I'm not sure if I can fix this by changing my CMake config outside the CubeMX folder. I don't like the idea of git-reverting and fixing the CubeMX generated CMakeLists.txt after each generate. Any suggestions or tips? How do you manage CMake projects, where CubeMX code is only a library?

0 REPLIES 0