如何将来源附加到自定义目标? [英] how to append sources to custom target?
问题描述
使用 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 asadd_executable()
oradd_library()
and must not be anIMPORTED
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屋!