[CMake] Feature suggestion: cmake -E do_nothing -- useful to simulate configuration-specific commands
Anders Lindgren
andlind at gmail.com
Wed Jun 18 12:20:25 EDT 2014
Hi!
In my project, I have a situation where I would like to perform an action
as post build step, but only for the Debug configuration. (In the example
below I copy a file.)
Unfortunately, it's not possible to apply add_custom_command to a specific
configuration (at least when using a multi-configuration generator like the
ones for Visual Studio).
My current solution is to use something like:
add_custom_command(...
COMMAND
$<$<CONFIG:Debug>:${CMAKE_COMMAND}>$<$<NOT:$<CONFIG:Debug>>:true> -E copy
...)
Explanation: In the Debug configuration, this expands to "cmake -E copy
...", in other configurations it expands to "true -E ...". ("true" is a
standard UNIX command that accepts any options and always succeeds -- kind
of a generic "no-op" command.)
This has the drawback that this relies on me having an external command
"true". This is a standard UNIX command but isn't installed on standard
Windows machine.
By having a "cmake -E do_nothing" the command could instead look like:
add_custom_command(...
COMMAND ${CMAKE_COMMAND} -E
$<$<CONFIG:Debug>:copy>$<$<NOT:$<CONFIG:Debug>>:do_nothing> ...)
The difference is that this doesn't rely on any system-specific external
command.
Of course, this would not be needed if add_custom_command could be
configuration-specific...
In addition, it would be nice if other fields, like COMMENT, could support
generator expressions.
Sincerely,
Anders Lindgren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140618/835bd626/attachment.html>
More information about the CMake
mailing list