<div dir="ltr">Hi,<div><br></div><div>I recently learned that the COMMAND line in a custom command supports generator expressions. In particular, what makes this powerful is that if the expression evaluates to the empty string, no corresponding code will be added to the target (as documented in the <a href="https://cmake.org/cmake/help/v3.11/command/add_custom_command.html?highlight=add_custom_command">docs</a>).</div><div><br></div><div>While this works very nicely for single-string command, I fail to make it work for commands consisting of multiple space-separated strings:</div><div><br></div><div>```<br></div><div><div>~/tmp/genex_with_spaces$ cat CMakeLists.txt                                                                                      cmake_minimum_required(VERSION 3.6)</div><div><br></div><div>add_custom_target(foo)</div><div>add_custom_command(TARGET foo POST_BUILD</div><div>  COMMAND $<1:echo bar></div><div>  )</div></div><div><br></div><div><div>~/tmp/genex_with_spaces$ grep bar build/CMakeFiles/foo.dir/build.make                                                    "\$$<1:echo" bar></div></div><div>```</div><div><br></div><div>As can be seen, the generator expression is not expanded.</div><div><br></div><div>My question is now whether I am doing something wrong (is there a correct way of dealing with spaces in the context of generator expressions?) or might this be an inherent limitation of generator expression in general?</div><div><br></div><div>As a workaround, the only thing that seems to work is to put each of the space-separated components of the command in (typically identical) genexes:<br></div><div><br></div><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">```<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><div>~/tmp/genex_with_spaces$ cat CMakeLists.txt                                                                                      cmake_minimum_required(VERSION 3.6)</div><div><br></div><div>add_custom_target(foo)</div><div>add_custom_command(TARGET foo POST_BUILD</div><div>  

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">COMMAND $<1:echo> $<1:bar></span>

</div><div>  )</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="text-align:start;text-indent:0px;text-decoration-style:initial;text-decoration-color:initial"><div>~/tmp/genex_with_spaces$ grep bar build/CMakeFiles/foo.dir/build.make                                                echo bar</div><div>```</div></div><br class="gmail-Apple-interchange-newline">

Of course, while this works, things becomes very unreadable if the genex is more complex.</div><div><br></div><div>Other things that I have tried but failed:</div><div><ul><li>escape the space with a backslash -> this quotes the entire expression inside the genex.<br></li><li>define the command directly as a list inside the genex -> this removes spaces between the different components of the command and quotes that result.</li><li>treat the command as a list, perform string operations to wrap each element in the desired regex and convert semicolon to spaces -> again results in the command being quoted as a whole.</li></ul></div><div><br></div><div>Any advice is highly appreciated.</div><div><br></div><div>Thanks,</div><div>Yves</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>