问题
With target_sources we can easily add sources to target created previously, but as the manual said:
The named
targetmust have been created by a command such asadd_executable()oradd_library()and must not be anIMPORTEDTarget.
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
APPENDoption is given the list is appended to any existing property value.
来源:https://stackoverflow.com/questions/62965596/how-to-append-sources-to-custom-target