[cmake-developers] [CMake] add_custom_command() OUTPUT does not accept generator expressions, why?

Brad King brad.king at kitware.com
Thu Mar 31 09:39:32 EDT 2016


On 03/31/2016 07:26 AM, Yves Frederix wrote:
>> If anyone is interested in trying to implement generator expressions
>> for custom command outputs, I can provide more details to get started.
> 
> I am interested in having a go at this. I recently ran into this issue
> at work as well and actually tried some things already. However, I
> realized it was not that straightforward (not even talking about doing
> it 'right' here ;)). Any pointers are welcome!

Thanks!

The main challenge is shown in the cmTargetTraceDependencies::FollowName
method where it calls cmMakefile::GetSourceFileWithOutput.  This logic
is done without knowledge of the current configuration.  Therefore we
cannot expand generator expressions of the available outputs because
they may contain $<CONFIG>.  Some table of pre-expanded per-config
outputs mapping back to their cmSourceFile instances may need to be
built.  Achieving this may even require adding a generate-time
companion of cmSourceFile that knows its configuration.  It will need
to be investigated further.

cmTargetTraceDependencies::CheckCustomCommand currently has a loop
over all configurations to generate the union of dependencies.  This
is used to allow generator expressions in the DEPENDS option.
The cmTargetTraceDependencies logic may need to be refactored to move
the loop over the configurations out to a higher level.  We may need
to trace dependencies separately for each configuration (for multi-
config generators).

Also see cmCustomCommandGenerator.  The generators will need to
be adapted to use this to get the custom command outputs with
generator expressions expanded.  They already do for the commands
and dependencies.

-Brad


More information about the cmake-developers mailing list