Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

unix - Create a custom symbolic link to a library at install time with CMake

Under Linux with CMake, I'm building a shared library libIex-2_0.so.10.0.1

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

The 10.0.1 version is set with a call to

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, to match previous builds made with another build system, I need to add a legacy symbolic link, stripping the 2_0 suffix :

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

What would be the proper CMake way to create such a link ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way to do it could be using CMake add_custom_command and add_custom_target. In your case it would 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 a target install_legacy in your generated Makefile with the correct dependency to generate libIex.so.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...