[CMake] Single library with both shared and static binaries

Simon Richter Simon.Richter at hogyros.de
Thu Sep 26 08:28:56 EDT 2019


Hi,

On Tue, Sep 24, 2019 at 11:41:54PM +0300, Avraham Shukron wrote:

> I have a library which I want to distribute in both shared object and
> static library forms.

Is that a requirement for your project, or a requirement for the system
integrator?

With my Debian Developer hat on, I'm always grateful when a project's build
system doesn't do anything unexpected.

We know that libtool generates shared and static libraries at the same
time, and so when wrapping an autoconf based project, we use a single build
tree and expect both to pop up.

With CMake, we know that the build system cannot generate both at the same
time. It would be cool if it could, but the expectation is that a library
project will have to be built twice, and our tools mirror that expectation.

If the majority of your users compile from source and need both shared and
static libraries to be built, it makes sense to have two targets.
Otherwise, the principle of least surprise applies.

That said, a hypothetical future version of CMake that makes this easier so
we can at some point remove the requirement to build twice would be
awesome.

   Simon


More information about the CMake mailing list