I’m working on a project using a lib create as an INTERFACE (stm32cubemx lib, generate by STM32CubeMX, so I cannot change it )
I have a lib, libPWM that have to link to the stm32cubemx lib. In my lib, I like to reduce possible error so I add -Wconversion -Werror as compile option in the libPWM CMakeLists.txt
My problem is that, when compiling the libPWM, as the stm32cubemx lib is define as an INTERFACE, it is regenerate using its own compile option PLUS the libPWM compile option. As the ST code is not perfect, the stm32cubemx lib do not compile.
SO, how to link with an interface lib, without propagating the compile option of the lib linking to it?
Here is a copy of the stm32cubemx CMakeLists.txt file:
cmake_minimum_required(VERSION 3.22)
project(stm32cubemx)
add_library(stm32cubemx INTERFACE)
# Enable CMake support for ASM and C languages
enable_language(C ASM)
target_compile_definitions(stm32cubemx INTERFACE
USE_HAL_DRIVER
STM32F030x6
$<$<CONFIG:Debug>:DEBUG>
)
target_include_directories(stm32cubemx INTERFACE
../../Core/Inc
../../Drivers/STM32F0xx_HAL_Driver/Inc
../../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy
../../Drivers/CMSIS/Device/ST/STM32F0xx/Include
../../Drivers/CMSIS/Include
)
target_sources(stm32cubemx INTERFACE
../../Core/Src/main.c
#list of all the stm32 source files
)
target_link_directories(stm32cubemx INTERFACE
)
target_link_libraries(stm32cubemx INTERFACE
)
# Validate that STM32CubeMX code is compatible with C standard
if(CMAKE_C_STANDARD LESS 11)
message(ERROR "Generated code requires C11 or higher")
endif()
As I said, this file is auto generated by STM32CubeMX. My first intention was to keep it with no modification. But from what I understand (I’m starting with CMake, so I’m not an expert using it), it will not be possible to use it like I want (no modification of the compile options when linking to another lib among other things) as long as it is defined as an interface.
I think I will change the lib to be a non interface and modify the file generated. I do not understand why STM32CubeMX is generated an interface. But I will have to de with it
This says “add these sources to the source list of anything that links to stm32cubemx”. Is this what you intend? Is it these files you’re seeing be compiled when you say:
If so, these files are, at the time, part of libPWM and, as such, they will get libPWM’s flags. If you want them compile separately, make stm32cubemx a non-INTERFACE library. Making it an OBJECT library is probably closest to the desired behavior, but I’m not sure.
Ok thanks.
For me, it is not the case in the STM32CubeMX project, but I understand the normal goal of interface lib. And the fact that it cannot do what I want. I will try to modify it.
Thank you