CMake中是否有LINK_DIRECTORIES或等效属性? [英] Is there a LINK_DIRECTORIES or equivalent property in CMake?

查看:324
本文介绍了CMake中是否有LINK_DIRECTORIES或等效属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含大量link_directories()命令的项目。现在,我想将目录的结果字符串存储到一个变量中。对于include_directories(),使用以下方法很容易

I have created a project with a large number of link_directories() commands. I'd now like to store the resulting string of directories into a variable. For include_directories() this is easy using

get_property( test_INCLUDE_DIRECTORIES TARGET test PROPERTY INCLUDE_DIRECTORIES )

但是似乎没有LINK_DIRECTORIES属性可以做

however there seems to be no LINK_DIRECTORIES property to do

get_property( test_LINK_DIRECTORIES TARGET test PROPERTY LINK_DIRECTORIES )

是否可以获取链接列表用于目标的目录?

Is there a way to get a list of link directories used for a target?

(注意:我意识到自己可以手动跟踪变量中的链接目录,然后使用单个link_directories(),但它不会似乎很干净)

(Note: I realize I could manually track the link directories in a variable myself and then use a single link_directories() but it doesn't seem very clean)

推荐答案

看看 LINK_DIRECTORIES 目录属性

Take a look at the LINK_DIRECTORIES directory property.

重点是 link_directories 在每个目录下运行(该命令会影响同一CMakeLis中定义的所有目标ts以及其所有子目录中的目标),例如 target_include_directories 可以按目标进行操作。

The point is that link_directories operates on a per-directory basis (the command affects all targets defined in the same CMakeLists, as well as targets from all of its subdirectories), unlike, for instance, target_include_directories which works on a per-target basis.

您可以通过以下方式查询属性的值:

You can query the value of the property with:

get_property(test_LINK_DIRECTORIES DIRECTORY PROPERTY LINK_DIRECTORIES)

如果从与 link_directories 调用相同的目录中调用。否则,您需要在 DIRECTORY 之后给出(完整或相对)路径作为附加参数。不幸的是,我不知道如何获取现有目标的匹配目录。

if called from the same directory as the link_directories call. Otherwise, you need to give the (full or relative) path as an additional argument after DIRECTORY. Unfortunately, I know of no way to obtain the matching directory for an existing target.

请注意,通常在CMake中不鼓励使用 link_directories ,这很可能是不能很好地支持它的主要原因。除非有很好的理由,否则应始终坚持将完整的库路径传递给 target_link_libraries 。从长远来看,它将为您节省很多头痛。

Note that in general the use of link_directories is discouraged in CMake, which is probably the main reason why it's not supported very well. Unless you have very good reasons not to, you should always stick with full library paths passed to target_link_libraries. It will save you lots of headaches in the long run.

这篇关于CMake中是否有LINK_DIRECTORIES或等效属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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