目标输出文件的路径 [英] Path to target output file

查看:194
本文介绍了目标输出文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 add_library 创建的.so库目标,并且需要将此库的绝对路径传递到外部脚本。现在我有 $ {LIBRARY_OUTPUT_PATH} / $ {CMAKE_SHARED_LIBRARY_PREFIX} LangShared $ {CMAKE_SHARED_LIBRARY_SUFFIX} LIBRARY_OUTPUT_PATH my CMakeLists.txt )。这看起来像硬编码给我,因为它会破裂,只要目标被重命名或其某些属性更改。有没有办法获得 add_library 的输出的绝对路径?

I have a .so library target created by add_library, and need to pass an absolute path to this library to an external script. Now I have ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}LangShared${CMAKE_SHARED_LIBRARY_SUFFIX} for that (LIBRARY_OUTPUT_PATH is defined in my CMakeLists.txt). This looks like hard-coding to me, because it will break as soon as the target is renamed or some of its properties are changed. Is there a way to get an absolute path to add_library's output?

推荐答案

您应该使用生成器表达式 this。

You should use a generator expression for this.

add_custom_command 和生成器表达式的文档:

From the docs for add_custom_command and the docs for generator expressions:


参数 COMMAND 可以使用生成器表达式...

Arguments to COMMAND may use "generator expressions"...

生成器表达式在构建系统生成期间被评估,

Generator expressions are evaluted during build system generation to produce information specific to each build configuration.

在这种情况下,假设您的库目标称为MyLib,生成器表达式表示完整路径建立的库将是:

In this case, assuming your library target is called "MyLib", the generator expression representing the full path to the built library would be:

$<TARGET_FILE:MyLib>

这篇关于目标输出文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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