[cmake-developers] Target SOURCES and TARGET_OBJECTS

Stephen Kelly steveire at gmail.com
Fri Feb 21 04:59:16 EST 2014


Stephen Kelly wrote:

> 
> Hi,
> 
> As part of implementing the INTERFACE_SOURCES feature, a SOURCES property
> is required.
> 
> Unfortunately it already exists and does not contain all sources. It omits
> TARGET_OBJECTS items. Backward compatibility must be preserved. I would
> want to turn TARGET_OBJECTS into a 'real' generator expression which
> results in a list of object file paths, and simply process the SOURCES
> like other build properties, allowing that result.
> 
> Configure-time code can not handle generator expressions.
> cmSetSourceFilesPropertiesCommand is documented as being suitable for
> consuming the value of SOURCES from a target. It breaks if a generator
> expression is passed in. Additionally user code can be reading the SOURCES
> property (it is read-only, they can't be writing it), and would break if
> the TARGET_OBJECTS expression were added.
> 
> The cmSetSourceFilesPropertiesCommand can be made to ignore generator
> expressions. An alternative would be to execute the property setting after
> generator expression expansion. However, that would be weird:
> 
>  add_library(bar bar.cpp)
> 
>  add_library(foo foo.cpp $<TARGET_PROPERTY:bar,SOURCES>)
>  # get_target_property(res foo SOURCES)
>  # message("RES: ${res}")
> 
>  get_target_property(foo_srcs foo SOURCES)
>  # Sets bar.cpp property at generate-time:
>  set_source_files_properties(${foo_srcs} PROPERTIES LABELS fooSRCS)
> 
>  get_target_property(bar_srcs bar SOURCES)
>  # Sets bar.cpp property at configure-time:
>  set_source_files_properties(${bar_srcs} PROPERTIES LABELS barSRCS)
> 
> 
> The 'direct' setting of the property is always overridden by the setting
> on foo, because that is evaluated lazily.
> 
> User code must also be able to ignore generator expressions. For that, we
> can add a subcommand string(GENEX_STRIP). An alternative is adding
> string(GENEX_SPLIT) and string(FIND_GENEX) instead.

My preference is adding only string(GENEX_STRIP) to strip out genexes. I'm 
not confident that handling the semicolons in a SPLIT scenario would be fun 
in CMake code.

> An alternative plan would be to deprecate the SOURCES property and
> introduce a new property which contains the generator expressions:
> 
>  prop_tgt/COMPILE_SOURCES
>  command/target_compile_sources
> 
> That name is not great, because the sources may be object files which do
> not get compiled but only linked.

The preference is to stick with SOURCES, right?

Thanks,

Steve.





More information about the cmake-developers mailing list