-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: library and two executable. stm libs are compiled 3 times? #195
Comments
Hello @andyinno I don't think this question is directly related to this repository https://github.com/ObKo/stm32-cmake but more like a cmake usage problem. |
Hi @andyinno, In this repo INTERFACE libraries are used to define all the libraries, so quoting the documentation : you will build
|
First of all, thank you for the reply.
Yes, that was my workaround for it. I was just unsure if what I was passing to cmake was correct or not. |
@Hish15 : If I am not wrong, this is what you are suggesting. https://github.com/andyinno/stm32-cmake/tree/blinky_lib here I created an example lib, blinky_lib. Trying to compile it, only for F4 devices... output from compilation is: ` Each library C file is compiled twice, once for the library, once for the executable. Is my understanding correct? This is what you meant? |
Hi @andyinno, After some testing (cmake 3.16) it seems that I was wrong : Adding sources to the interface target, populate INTERFACE_SOURCES property. linking against this interface will propagate this property to other targets too. So you will have to compile multiple times as you noticed... The only way to avoid this behavior in your example is to make the target
This postpone the problem, but works in your example. You will have a probleme only when a real output will be need from a target (STATIC/OBJECT/EXECUTABLE) I have no solution on how to avoid that cleanly, but I will think about it. |
Hi @andyinno I built you blinky lib using VScode on windows with GCC and cmake 3.20.2
I Just see the answer from @Hish15 while I'm writing this. And he has not same results as me so we will investigate further :) |
Edit: it did work for @atsju not for me on ubuntu 20.04 |
First of all, thank you both for your tests. I made a test right now with The output is the same as before. It still compiles the imported libraries multiple times.
at the top of my CMakeLists.txt Could this be some bug specific to the linux build? |
Hi @andyinno . I'm pretty sure that @Hish15 built on linux but maybe share your complete configuration to double check (compiler, cmake, linux,...). I also noted that you use |
Why do not use object libraries? |
@ucayalifish, object library does not propagate dependencies:
|
I did not tried with cmake-3.19 on my side on linux. |
I am also having this problem. When several library dependencies exist, the amount of unnecessary building becomes quite significant. Does somebody have a simple project demonstrating a solution? |
@dhoove: The problem arises from the stupid design of the ST HAL libraries and I am afraid stm32-cmake cannot do much about it. Every header file in ST HAL includes The proper solution would be to ask ST to change the architecture. However, from my experience ST engineers seem to be quite unwilling to make changes and follow good programing practice. |
Following this example:
if I have lib foo with common code:
and I link lib foo with:
HAL::STM32::F4::GPIO
and I use this lib with executables bar1 and bar2 linking foo.
I see in the output that lib gpio is compiled 3 times. I was expecting that gpio lib is build only once.
Am I missing something?
This is just an example but basically what I am trying to do is to have some libraries with a lot of common code that compile different executables.
This is happening becaue I think I am forced to add:
target_link_libraries(mygpiolib PUBLIC HAL::STM32::F4::GPIO )
If I make the mygpiolib PRIVATE, then the executable is not able to find the GPIO define and include file because it is not inherited. If I add the HAL::STM32::F4::GPIO to the executable, then it is in any case built twice.
Am I missing something stupid here?
thank you in advance
The text was updated successfully, but these errors were encountered: