Allow STATIC libraries to depend on STATIC libraries without requiring build order
In this thread: https://cmake.org/pipermail/cmake/2019-February/069015.html I asked about the following scenario:
I have a bunch of very large STATIC
libraries which are linked together into a few executables. Additionally, these static libraries are layered (4-5 layers deep in some places), so that library A needs the header files, defines, and options for library B which itself requires these properties of library C etc.
So, I'm using target_link_libraries()
to propagate that information and it works well.
However, there is a problem: because our code base is large and these libraries are large, developers have a habit of checking their work by building just the library they're working on, without trying to build the executable. So for example they might say make -j8 A
.
Using target_link_libraries()
for dependencies makes this much less useful, because rebuilding library A causes cmake to rebuild library B and C as well, even though there's no need to build those libraries just to build library A (these are all static libraries remember); we won't need libraries B and C until we try to link an executable at the end.
I haven't investigated deeply but it seems to me that this would also reduce the ability to fully utilize parallel builds: if we force the entirety of library B and C to be complete before we start to build library C.
If the target in target_link_libraries()
is a STATIC
library, and the library is either STATIC
or SHARED
(but not OBJECT
), then we could avoid adding that library to the target's LINK_LIBRARIES
property and only include it in the INTERFACE_LINK_LIBRARIES
property, and that would give a much nicer behavior.
Are there situations where we do need the library to be added to LINK_LIBRARIES
? Maybe, for example, if library B causes some generated files to be created including header files that library A needs to exist? But shouldn't that be reflected in other properties such as OBJECT_DEPENDS
or similar?
If you think this dependency is required to ensure 100% correct builds in odd situations, maybe we can have a shortcut for the (very common) case where it's NOT needed, similar to the LINK_DEPENDS_NO_SHARED
property we can use to avoid relinking shared libraries?