MantisBT - CMake
View Issue Details
0012877CMakeCMakepublic2012-01-16 03:492013-06-03 09:05
Petr Kmoch 
 
normalminorN/A
closedduplicate 
CMake 2.8.6 
 
0012877: Support generator expressions in OUTPUT
While $<...> generator expressions in the COMMAND portion of add_custom_command() are useful, I find their use is limited by the fact they cannot be used in other parts of add_custom_command(), such as OUTPUT. For example, in my project, I need a custom command to copy some files to the directory where a target's executable resides. In other words, I need the following:

add_custom_command(
 OUTPUT "$<TARGET_FILE_DIR:MyTarget>/TheExtraFile"
 COMMAND "${CMAKE_EXECUTABLE}" -E copy Path_To/TheExtraFile "$<TARGET_FILE_DIR:MyTarget>/TheExtraFile"
 VERBATIM
)

While in the COMMAND part, the generator expression is interpreted correctly, in OUTPUT it's not, and CMake produces an error: "add_custom_command called with OUTPUT containing a "<". This character is not allowed."

I saw 0009974 which would offer a superset od the above functionality, but the above would offer simpler syntax for this more specific class of uses.
No tags attached.
duplicate of 0013840closed Kitware Robot Allow generator expressions anywhere 
related to 0009974closed Brad King CMake should support custom commands that can vary by configuration. 
Issue History
2012-01-16 03:49Petr KmochNew Issue
2012-01-16 04:25Michael WildNote Added: 0028305
2012-01-16 05:01Petr KmochNote Added: 0028307
2012-01-16 08:42Brad KingRelationship addedrelated to 0009974
2012-01-16 08:52Brad KingNote Added: 0028315
2012-01-16 08:52Brad KingStatusnew => backlog
2013-01-08 11:30Brad KingRelationship addedhas duplicate 0013840
2013-01-08 16:09Brad KingNote Added: 0032007
2013-01-08 16:09Brad KingStatusbacklog => resolved
2013-01-08 16:09Brad KingResolutionopen => duplicate
2013-01-08 16:09Brad KingRelationship replacedduplicate of 0013840
2013-06-03 09:05Robert MaynardNote Added: 0033183
2013-06-03 09:05Robert MaynardStatusresolved => closed

Notes
(0028305)
Michael Wild   
2012-01-16 04:25   
Just as a temporary workaround you can use a stamp-file in your OUTPUT option which you create with "COMMAND ${CMAKE_COMMAND} -E touch stamp_file". Of course, this stamp file should be unique.
(0028307)
Petr Kmoch   
2012-01-16 05:01   
Thanks for the tip. However, there is a problem with trying to generate a unique name for the stamp file in a generator with multiple configurations (Visual Studio). To make it unique, I'd somehow need to embed the name of the configuration into the filename - and that's where I need generator expressions again.

That's how I actually arrived at this problem - no way to smuggle the configuration name into OUTPUT. My current workaround is having one target per configuration (i.e. CopyFiles_Debug, CopyFiles_Release), which is far from ideal, as it clutters "Build All" etc.
(0028315)
Brad King   
2012-01-16 08:52   
Unfortunately this will be very difficult to implement and may need some internal redesign of CMake. We use the output file name for a bunch of things that are needed prior to the completion of the configuration step. The generator expressions cannot be evaluated until generate time which is too late.
(0032007)
Brad King   
2013-01-08 16:09   
Resolving as duplicate of 0013840 because that one subsumes this one.
(0033183)
Robert Maynard   
2013-06-03 09:05   
Closing resolved issues that have not been updated in more than 4 months.