Open ZedThree opened 3 years ago
Sorry for the long delay. One might really hope there was a standard CMake convention for this issue, as lots of projects surely encounter the same forces. We really ought to be able to provide both versions of the library with the same base name - lots of projects ship with a foo.a
and a foo.so
.
I don't think the existing pFUnit documentation directly addresses building shared libraries, so for now I will defer to your choice for solving this. I'll then test with a couple of downstream projects that need the shared libraries to be sure things still work before I role out a release.
No worries. Yeah, it's a pain for sure. There are libraries that can handle building both static and shared, SUNDIALS for one. I'll have a look through their CMake again and see how they handle it.
This is only a real problem if the Ninja generator is used, as it errors due to two targets trying to build e.g.
libfunit.so
. Makefiles doesn't seem to care.The cause is this snippet:
If
BUILD_SHARED_LIBS
is on, thenadd_library(pfunit)
creates a shared library. This conflicts with setting theOUTPUT_NAME
ofpfunit_shared
topfunit
-- bothpfunit
andpfunit_shared
try to createlibpfunit.so
, which is an error with Ninja.(This also applies to
funit
too)I think there are two solutions:
add_library(pfunit STATIC)
, always build the static library and optionally the shared library. You then likePFUNIT::pfunit
to alias the shared library if available.if (BUILD_SHARED_LIBS)
block and only build either the static or the shared. You would probably still need to keep the alias forPFUNIT::pfunit_shared
to not break existing codeI'm happy to implement either fix, depending on what you think is best to do. Personally, I'd probably pick option 2, as I don't really ever want both static and shared libraries.