Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent CMake from creating a symlink for shared libraries on install?

Is there a way to prevent CMake from creating a symlink for shared libraries like libfoo.so when you are using so-versioning (which means you would have something like libfoo.so.0.8)?

The reason why I am asking this is that I have a project where I would like to make multiple versions of that project installable in parallel. Most package managers however reject a parallel installation if a file like the symlink is present in multiple packages.

As a background info: we are using CPack to build the packages and ultimately I think it is a flaw of CPack that you cannot prevent this symlink or at least being able to separate dev and runtime packages e.g. for debian. However, so far I have the illusions that just preventing CMake from creating the symlink at all might be the easier thing to do than patching CPack.

like image 715
languitar Avatar asked Aug 08 '12 14:08

languitar


1 Answers

For shared libraries you can use the NAMELINK_SKIP option of the install command to prevent the generation of the versionless library name symbolic link to the versioned library file. The generated CPack installer will honor that setting upon installation. The library version has to specified by setting the SOVERSION property of the shared library target:

The following sample code sketches the required steps:

add_library(foo SHARED foo.c)

set_target_properties(foo PROPERTIES SOVERSION "0.8")

install(TARGETS foo LIBRARY DESTINATION lib NAMELINK_SKIP)

include(CPack)
like image 107
sakra Avatar answered Oct 05 '22 17:10

sakra