how to append sources to custom target?

断了今生、忘了曾经 提交于 2020-07-23 06:45:26

问题


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

The named target must have been created by a command such as add_executable() or add_library() and must not be an IMPORTED 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

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


回答1:


Awards should give to @Tsyvarev

Short answer:

set_property(TARGET my_custom_target PROPERTY SOURCES APPEND world.x)

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

set_property do support APPEND option:

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



来源:https://stackoverflow.com/questions/62965596/how-to-append-sources-to-custom-target

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!