在安装时使用CMake创建到库的自定义符号链接 [英] Create a custom symbolic link to a library at install time with CMake

查看:632
本文介绍了在安装时使用CMake创建到库的自定义符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有CMake的Linux下,我正在构建一个共享库libIex-2_0.so.10.0.1

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")

10.0.1版本设置为调用

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

但是,要匹配使用其他构建系统进行的先前构建,我需要添加一个旧的符号链接,并删除2_0后缀:

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

创建此类链接的正确CMake方法是什么?

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

推荐答案

一种解决方法是使用CMake add_custom_command add_custom_target 。在您的情况下,将类似于以下内容:

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} )

此时,您应该在生成的Makefile中有一个目标 install_legacy ,并具有正确的依赖性以生成 libIex.so

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

这篇关于在安装时使用CMake创建到库的自定义符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆