[CMake] Config.cmake.in: Conditionally serve static or shared library

Kim Walisch kim.walisch at gmail.com
Wed Feb 14 10:21:59 EST 2018


Hi,

My primesieve project builds as both a static and a shared library, hence
there are 2 targets in my main CMakeLists.txt:

1) libprimesieve (shared library)
2) libprimesieve-static

I am now trying to add support for find_package(Primesieve). Ideally I
would like that users can link against libprimesieve as follows:

find_package(Primesieve REQUIRED)
target_link_libraries(user_library Primesieve::Primesieve)

And I want Primesieve::Primesieve to be an alias for
Primesieve::libprimesieve if BUILD_SHARED_LIBS=ON (in the user's
CMakeLists.txt) and and alias for Primesieve::libprimesieve-static if
BUILD_SHARED_LIBS=OFF (or if it is not set).

Is this possible?
Do you know any library that has already implemented this?

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


More information about the CMake mailing list