Creating a custom symbolic library link during installation using CMake

On Linux with CMake, I am creating the libIex-2_0.so.10.0.1 shared library

ADD_LIBRARY (Iex SHARED [*.cpp] ) SET_TARGET_PROPERTIES(Iex PROPERTIES OUTPUT_NAME "Iex-2_0") 

Version 10.0.1 installed with a call

 SET_TARGET_PROPERTIES ( Iex PROPERTIES VERSION 10.0.1 SOVERSION 10 ) 

In the installation folder, these links are created

 libIex-2_0.so -> libIex-2_0.so.10 libIex-2_0.so.10 -> libIex-2_0.so.10.0.1 libIex-2_0.so.10.0.1 

However, in order to match previous builds done with a different build system, I need to add an outdated symlink, splitting the suffix 2_0:

 libIex.so -> libIex-2_0.so.10.0.1 

What will be the CMake way to create such a link?

+6
source share
1 answer

One way to do this could be to use CMake add_custom_command and add_custom_target . In your case, it will be something like the following:

  SET( legacy_link ${CMAKE_INSTALL_PREFIX}/libIex.so) SET( legacy_target ${CMAKE_INSTALL_PREFIX}/libIex-2_0.so.10.0.1) ADD_CUSTOM_COMMAND( OUTPUT ${legacy_link} COMMAND ln -s ${legacy_target} ${legacy_link} DEPENDS install ${legacy_target} COMMENT "Generating legacy symbolic link") ADD_CUSTOM_TARGET( install_legacy DEPENDS ${legacy_link} ) 

At this point, you should have the target install_legacy in the generated Makefile with the correct dependency to generate libIex.so .

+6
source

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


All Articles