Diclaimer : I am very new to CMake, I may be missing a key concept…
I am using CubeMX to generate hardware-specific code for multiple boards. Each board’s autogenerated files include a CMakeLists.txt that defines a library named stm32cubemx.
I need to include the libraries from two boards (e.g., BoardA and BoardB) and have one executable for each in the same project, but because both libraries have the same name, CMake raises a conflict.
This is what is in BoardA/cmake/CMakeLists.txt :
project(stm32cubemx)
add_library(stm32cubemx INTERFACE) <-- Changing this manually fixes the problem
# Enable CMake support for ASM and C languages
enable_language(C ASM)
target_compile_definitions(stm32cubemx INTERFACE
USE_HAL_DRIVER
STM32F401xE
$<$<CONFIG:Debug>:DEBUG>
)
target_include_directories(stm32cubemx INTERFACE
../../Core/Inc
...
)
...
This is my file structure
project :
|-CMakelists.txt
|-main.cpp
|-Hardwares :
|--|BoardA : <-- This is an autogenerated folder
|--|--|CMakelists.txt <-- Modifiable but does not contain anything important
|--|--|Src & Inc folders
|--|--|cmake : CMakeLists.txt <-- Not modifiable, defines library "stm32cubemx" defines important board-specific options
|--|BoardB : <-- Same as BoardA
|--|--|CMakelists.txt
|--|--|Src & Inc folders
|--|--|cmake : CMakeLists.txt
Changing the library’s name in the generated cmakelists manually fixes the issue but it is overwritten as soon as the hardware is regenerated…
I cannot copy-paste the options from the autogenerated CMakeLists.txt because it can change with hardware-configuration and create confusion for other developpers
I have tried adding the library with an ALIAS but it fails as soon as I use
add_subdirectory(BoardX/cmake)
I have also looked into the cubeMX generator’s settings and it does not allow setting the library name manually (to my knowledge)
Making a Python script that modifies the BoardA/cmake/CMakeLists.txt after every generation seems like an option but there must be a cleaner way…
Is there a way to isolate or rename the autogenerated libraries, or to work around the conflict ?
Thanks in advance
2