如何将来源附加到自定义目标? [英] how to append sources to custom target?

查看:83
本文介绍了如何将来源附加到自定义目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 target_sources ,我们可以轻松地将源添加到先前创建的目标中,但是正如手册所述:

With target_sources we can easily add sources to target created previously, but as the manual said:


命名的目标必须由诸如 add_executable()之类的命令创建add_library(),并且不能是导入目标。

The named target must have been created by a command such as add_executable() or add_library() and must not be an IMPORTED Target.

那么如何向 add_custom_target 已创建的目标中添加更多源?

So how to add more sources to a target already created by add_custom_target?

考虑到我有一个项目结构化的波纹管:

Considering I have a project structured bellow:

hello
`- CMakeLists.txt      # level 1
`- hello.x
`- world/
   `-- CMakeLists.txt  # level 2
   `-- world.x

有没有更好的方法扩展在1级中创建的自定义目标,而不是将变量 set PARENT_SCOPE

Is there any better way to extend the custom target created in level 1 rather than using variable set with PARENT_SCOPE

推荐答案

奖励应给予@Tsyvarev

Awards should give to @Tsyvarev

简短答案:

set_property(TARGET my_custom_target APPEND PROPERTY SOURCES world.x)

目标的来源可以通过 get_property / get_target_property set_property 进行访问和修改/ set_target_properties

The SOURCES of a target can be accessed and modified by get_property/get_target_property and set_property/set_target_properties.

set_property 支持 APPEND 选项:


如果给出了 APPEND 选项,则该列表将附加到任何现有属性值之后。

If the APPEND option is given the list is appended to any existing property value.

这篇关于如何将来源附加到自定义目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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