If you want to support consumers that are building shared and static libraries themselves you can do this by using an import library with a generator expression. A simplified version of how do this, besides the import library can be found at:
https://github.com/robertmaynard/Sandbox/blob/master/CMakeInterfaceChangesLibrary/CMakeLists.txt On Wed, Feb 14, 2018 at 11:34 AM, ThePhD <[email protected]> wrote: > I think you can use what's called an "Alias Library": > https://cmake.org/cmake/help/latest/command/add_library.html#alias-libraries > > if (BUILD_SHARED_LIBS) > add_library(my_libprimesieve ALIAS libprimesieve) > else > add_library(my_libprimesieve ALIAS libprimesieve-static) > endif(BUILD_SHARED_LIBS) > > Then, set it properly to Primesieve::Primesieve and it should work. > > > On Wed, Feb 14, 2018 at 10:21 AM, Kim Walisch <[email protected]> wrote: >> >> 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 >> >> -- >> >> Powered by www.kitware.com >> >> Please keep messages on-topic and check the CMake FAQ at: >> http://www.cmake.org/Wiki/CMake_FAQ >> >> Kitware offers various services to support the CMake community. For more >> information on each offering, please visit: >> >> CMake Support: http://cmake.org/cmake/help/support.html >> CMake Consulting: http://cmake.org/cmake/help/consulting.html >> CMake Training Courses: http://cmake.org/cmake/help/training.html >> >> Visit other Kitware open-source projects at >> http://www.kitware.com/opensource/opensource.html >> >> Follow this link to subscribe/unsubscribe: >> https://cmake.org/mailman/listinfo/cmake >> > > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
