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

问题描述

我创建了一个带有大量link_directories()命令的项目。我现在想把结果的目录字符串存储到一个变量。对于include_directories(),这很容易使用

  get_property(test_INCLUDE_DIRECTORIES TARGET测试属性INCLUDE_DIRECTORIES)

但是似乎没有LINK_DIRECTORIES属性。

  get_property(test_LINK_DIRECTORIES TARGET测试PROPERTY LINK_DIRECTORIES)

是否有办法获取链接列表目录用于目标?



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

解决方案

查看。



要点是 link_directories 在每个目录下操作(该命令影响在相同CMakeLists中定义的所有目标,以及来自其所有子目录),不像例如 target_include_directories ,它工作在每个目标基础上。



属性值:

  get_property(test_LINK_DIRECTORIES DIRECTORY PROPERTY LINK_DIRECTORIES)
pre>

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



请注意,通常 link_directories ,但这可能是在CMake中使用的,因为这可能是由于在CMake中使用了 target_link_libraries 的完整的库路径。从长远来看,它会为您节省大量的头痛。


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 )

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?

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

解决方案

Take a look at the LINK_DIRECTORIES directory property.

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)

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.

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或equivilent属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:28