find_package(): fails because static library is not installed

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

find_package(): fails because static library is not installed

Kim Walisch

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)

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
  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)

Do you know any library which has already implemented this?



Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: