Combine static libraries

I’ve seen a bunch of related questions here and across the internet. However, most are pretty old and/or have different circumstances. So apologies for the potential repeat.

I have a project that organizes its files into several directories – each resulting in a static library. All of these libs are linked together with a main() to build the primary executable.

I also would like to combine those libs together into a single library – so users of my API can deal with just a single file. Some of my library users are not CMake users, so providing a single static library and an includes directory with what they need is the best way to go.

This seems like a very basic feature that CMake apparently lacks. I’ve found many old solutions, but some are limited (say only for OBJECT libraries), or are not cross-platform. I need a solution that works for Linux/Mac/Windows – gcc/clang/msvc.

Any help is appreciated,

Rob

1 Like

@ramcdona, did you find an elegant solution to your liking? If so could you share it?

My shop has done static library combos at times. It works, but I also question if there is a better CMake way of doing it.

We ended up creating two calling hierarchies. One for doing it on Windows (MSVC) and another for doing it on Linux (gcc), and a common interface call that would branch to Windows or Linux based on the machine we are running on. It “works” for the setup we have but we don’t do, and with this logic we cannot support, cross compilation.’

This is a long-running CMake request, the related issue is: https://gitlab.kitware.com/cmake/cmake/-/issues/19224