CMake:如何将一个目标安装到两个名称不同的地方? [英] CMake: how to install one target into two places with different name?

查看:50
本文介绍了CMake:如何将一个目标安装到两个名称不同的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个跨平台的音频插件.在MacOSX中,需要将其安装在两个位置:〜/Library/Audio/Plug-Ins/Components/并重命名为XXX.component,〜/Library/Audio/Plug-Ins/VST/并重命名为XXX.vst.

I am developing a cross-platform audio plugin. In MacOSX, it needs to be installed into two places: ~/Library/Audio/Plug-Ins/Components/ and rename to XXX.component, ~/Library/Audio/Plug-Ins/VST/ and rename to XXX.vst.

但是,INSTALL命令的TARGETS模式不能重命名,而FILES模式不能获取目标的真实文件名.

However, the TARGETS mode for INSTALL command cannot do rename, while the FILES mode cannot get target's real file name.

推荐答案

您可以使用该目标的属性获取目标的真实文件名:

You can get target's real file name using properties of that target:

get_target_property(MY_LIB_PREFIX <my-lib> PREFIX)
get_target_property(MY_LIB_SUFFIX <my-lib> SUFFIX)
set(MY_LIB_FILENAME "${MY_LIB_PREFIX}<my-lib>${SUFFIX}")

,然后使用 install(FILES ...)命令使用新名称安装文件.

and then use install(FILES ...) command for install file with new name.

此外,您可以更改使用其 SUFFIX 属性构建的目标的扩展名.这使您可以使用 install(TARGETS ...)命令执行一次安装.其他安装仍然需要 install(FILES ...)命令.

Also, you can change extension of target built using its SUFFIX property. This allows you to perform one install using install(TARGETS ...) command. Other installation will require install(FILES ...) command anyway.

如果您拥有CMake 3.0或更高版本,请

If you have CMake of version 3.0 or higher, generator-expressions provide simpler way for get full path of the file::

install(FILES $<TARGET_FILE:my-lib> ...)

这篇关于CMake:如何将一个目标安装到两个名称不同的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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