Install the shared imported library with the necessary links

This question asks how to install a shared library with cmake that was imported and not created by the current project:

Can I install a shared imported library?

To repeat the problem:

add_library(libfoobar SHARED IMPORTED) # this install command is illegal install(TARGET libfoobar LIBRARY DESTINATION "${RPMBUILDROOT}${LIBDIR}") 

This was raised as https://gitlab.kitware.com/cmake/cmake/issues/14311|issue] with a closed cmake, effectively with a resolution it will not be fixed. The reason is pretty reasonable that cmake doesn't know enough about the imported target to set it securely.

One point to answer this question is that install (TARGET) will automatically create links from libfoo.so to libfoo.so.major and a version of libfoo.so.minor on GNU / Linux and other Unix-like platforms where this is not required.

Is there a way to capture cmake to handle a custom target, as if it were built by a project, or otherwise convince it to create these links? Sort of:

 add_library(libfoobar SHARED IMPORTED) #? add_custom_target(X libfoobar) install(TARGET X LIBRARY DESTINATION "${RPMBUILDROOT}${LIBDIR}") 

What is the canonical way to do this?

+1
source share
1 answer

When the library is created by CMake, it is CMake , which is assigned to it by soversion numbers (according to the project settings ).

When the library was not created by CMake, CMake does not know soversion , so it cannot create symbolic links for you.

If you are worried that CMake actually sets up a symbolic link instead of a file, allow symbolic links before installation, for example, to this question .


Well, you can ask CMake to guess the soversion of the library (for example, by removing symbolic links and checking their names). But why do you need symbolic links?

The main purpose of the soversion symlink is to resolve compatibility issues with the future update library. But updates are possible only when the library is installed by the project that creates it .

If your project installs a library created by another project, it is unlikely that you want to support updates to install the local library. Thus, you do not need to maintain a relationship.

0
source

Source: https://habr.com/ru/post/975678/


All Articles