Build all-inclusive static library
In my projects, I need to build an all-inclusive static library -- i.e., when smaller static libraries are combined together into a single (bigger) one.
For *nix it can be done via MRI file for ar
. For MS Windows the lib.exe
can do that:
$ lib.exe /out:all_in_one.lib lib1.lib lib2.lib ...
Nowadays I use a custom target for that and it's quite complicated especially when I need to build a list of *.a
files having imported targets and generator expressions in the list of target dependencies.
The desired code may look like this:
add_library(all_in_one STATIC)
target_link_libraries(
all_in_one
PUBLIC
some_static_lib
Vendor::imported_static_lib
$<ANY_GENEX:conditional_static_lib>
...
)
In other words, if a static library has no sources it means combine listed static libs dependencies into a single library. Or maybe it could be "marked" to do so:
add_library(all_in_one STATIC COMBINED ...) # Or a single "keyword" ?
...
because (at least for ar
) it's possible to combine object files and other static libraries (meaning that, added library may have sources).
Maybe someone (@brad.king) may have other opinions?
I'm really eager to work on it. However, I'm not really familiar w/ generators in CMake yet. I need some direction to learn how the internal representation of targets and sources turns into particular build instructions... So any advice is very welcome ;-) -- i.e. brief story on how everything works, where to look for examples, etc.