[CMake] find_package(): fails because static library is not installed

Kim Walisch kim.walisch at gmail.com
Thu Feb 15 16:04:10 EST 2018


Hi,

I have added support for find_package(primesieve) to my primesieve library
and I have exported 2 targets in my main CMakeLists.txt:

primesieve::libprimesieve (shared library)
primesieve::libprimesieve-static

It works fine if both the static and shared primesieve libraries have
previously
been installed. As a test I have now deleted the static libprimesieve from
my
PC and now find_package(primesieve) fails:

CMake Error at /usr/local/lib/cmake/primesieve/primesieveTargets.cmake:88
(message):
  The imported target "primesieve::libprimesieve-static" references the file
     "/usr/local/lib/libprimesieve.a"
  but this file does not exist.  Possible reasons include...

The error seems reasonable but if I leave my code as is this error will be
triggered if somebody installs the libprimesieve RPM package on Fedora or
Red Hat Linux. The libprimesieve package contains only the shared
libprimesieve. Fedora requires that static libraries are put into a separate
package. Hence the static primesieve library is in libprimesieve-static.

How can I solve this issue? If the shared libprimesieve is installed but the
static libprimesieve is not installed then I would like to only export:

primesieve::libprimesieve (shared library)

But if both the static and shared libprimesieve are installed I would like
to export:

primesieve::libprimesieve (shared library)
primesieve::libprimesieve-static

Do you know any library which has already implemented this?

Thanks,
Kim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180215/a1305d0b/attachment-0001.html>


More information about the CMake mailing list