I build a static library and then want to add two more static libs to it after it is built.
The documentation for add_custom_command/“BUILD EVENTS” says
The command becomes part of the target and will only execute when the target itself is built. If the target is already built, the command will not execute.
Maybe explain what you’re trying to achieve by adding other libraries to a static library. That seems strange, and likely isn’t what you’re ultimately needing to do, but without understanding the use case, it’s hard to tell.
For better or worse, we want to deliver a single library to our clients. This library includes code we build as well as two third party libraries. So we build our lib, then add the other two after it has built.
That is unlikely to work. You’d need to add the contents of the other two libraries, not the libraries themselves. This has come a few times before, but I wasn’t able to find the past posts here in this form or the CMake issue tracker from a very quick scan. This stackoverflow answer contains the general gist though.
Edit: This issue is probably getting closer to discussing your scenario.
I would expect to get a file named foo.txt but only when building “something”. As it is, I get a file named foo.txt even though “something” isn’t rebuilt. Am I misinterpreting the documentation for add_custom_target?
If the target is already built, the command will not execute.
The goal of the feature WHOLE_ARCHIVE, which must be used with $<LINK_LIBRARY> genex, is to load all objects of an archive file specified during the link of a shared library or an executable.
This is not at all usable to aggregate multiple archives into another one.
Another discussion for this problem in this issue.