<div dir="ltr">There is no real need to go through an intermediate variable. The following should work:<div><br></div><div>
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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">add_compile_options(</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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"> "$<$<CXX_COMPILER_ID:GNU>:-Wall;-Wextra;-Werror>"</span><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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">)</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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"><br></span></div><div><span style="font-size:12.8px">Yves</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;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"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 24, 2018 at 6:58 PM, Elvis Stansvik <span dir="ltr"><<a href="mailto:elvis.stansvik@orexplore.com" target="_blank">elvis.stansvik@orexplore.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2018-04-23 14:11 GMT+02:00 CHEVRIER, Marc <<a href="mailto:marc.chevrier@sap.com">marc.chevrier@sap.com</a>>:<br>
> The space is used to separate arguments passed to COMMAND. So your generator<br>
> expression is splitted before evaluation and elements are no longer valid<br>
> generator expression.<br>
><br>
><br>
><br>
> So, to solve your problem, encapsulate the generator expression inside<br>
> quotes. And apply the following advices for correct result:<br>
><br>
> Separate command from args<br>
> Use variable to list your arguments and add option COMMAND_EXPAND_LISTS<br>
> (available with version 3.8) to avoid “spurious” semi-colons in the result<br>
><br>
><br>
><br>
> Your example reworked:<br>
><br>
><br>
><br>
> Set (args foo bar)<br>
><br>
> add_custom_target(foo)<br>
><br>
> add_custom_command(TARGET foo POST_BUILD<br>
><br>
> COMMAND $<1:echo> "$<1 :${args}>"<br>
><br>
> COMMAND_EXPAND_LISTS<br>
><br>
> )<br>
><br>
<br>
</span>Interesting thread. I was sort of in the same boat, having a<br>
<br>
add_compile_options(<br>
"$<$<CXX_COMPILER_ID:GNU>:-<wbr>Wall>"<br>
"$<$<CXX_COMPILER_ID:GNU>:-<wbr>Wextra>"<br>
"$<$<CXX_COMPILER_ID:GNU>:-<wbr>Werror>"<br>
<br>
"$<$<CXX_COMPILER_ID:Clang>:-<wbr>Wall>"<br>
"$<$<CXX_COMPILER_ID:Clang>:-<wbr>Wextra>"<br>
"$<$<CXX_COMPILER_ID:Clang>:-<wbr>Werror>"<br>
<br>
"$<$<CXX_COMPILER_ID:<wbr>AppleClang>:-Wall>"<br>
"$<$<CXX_COMPILER_ID:<wbr>AppleClang>:-Wextra>"<br>
"$<$<CXX_COMPILER_ID:<wbr>AppleClang>:-Werror>"<br>
)<br>
<br>
and of course wishing I could just write something like<br>
<br>
add_compile_options(<br>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Werror><br>
$<$<CXX_COMPILER_ID:Clang>:-<wbr>Wall -Wextra -Werror><br>
$<$<CXX_COMPILER_ID:<wbr>AppleClang>:-Wall -Wextra -Werror><br>
)<br>
<br>
instead.<br>
<br>
I can't depend on CMake 3.8+ just yet, but I'll remember your solution<br>
for when I can.<br>
<br>
I don't quite like having to introduce variables though. Is there no<br>
way to solve this without having to first stuff the elements in a list<br>
and use that?<br>
<br>
Cheers,<br>
Elvis<br>
<div><div class="h5"><br>
><br>
><br>
><br>
><br>
> From: CMake <<a href="mailto:cmake-bounces@cmake.org">cmake-bounces@cmake.org</a>> on behalf of Yves Frederix<br>
> <<a href="mailto:yves.frederix%2Bcmake@gmail.com">yves.frederix+cmake@gmail.com</a><wbr>><br>
> Date: Monday 23 April 2018 at 13:08<br>
> To: "<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>" <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>><br>
> Subject: [CMake] Generator expressions containing spaces<br>
><br>
><br>
><br>
> Hi,<br>
><br>
><br>
><br>
> I recently learned that the COMMAND line in a custom command supports<br>
> generator expressions. In particular, what makes this powerful is that if<br>
> the expression evaluates to the empty string, no corresponding code will be<br>
> added to the target (as documented in the docs).<br>
><br>
><br>
><br>
> While this works very nicely for single-string command, I fail to make it<br>
> work for commands consisting of multiple space-separated strings:<br>
><br>
><br>
><br>
> ```<br>
><br>
> ~/tmp/genex_with_spaces$ cat CMakeLists.txt<br>
> cmake_minimum_required(VERSION 3.6)<br>
><br>
><br>
><br>
> add_custom_target(foo)<br>
><br>
> add_custom_command(TARGET foo POST_BUILD<br>
><br>
> COMMAND $<1:echo bar><br>
><br>
> )<br>
><br>
><br>
><br>
> ~/tmp/genex_with_spaces$ grep bar build/CMakeFiles/foo.dir/<wbr>build.make<br>
> "\$$<1:echo" bar><br>
><br>
> ```<br>
><br>
><br>
><br>
> As can be seen, the generator expression is not expanded.<br>
><br>
><br>
><br>
> My question is now whether I am doing something wrong (is there a correct<br>
> way of dealing with spaces in the context of generator expressions?) or<br>
> might this be an inherent limitation of generator expression in general?<br>
><br>
><br>
><br>
> As a workaround, the only thing that seems to work is to put each of the<br>
> space-separated components of the command in (typically identical) genexes:<br>
><br>
><br>
><br>
> ```<br>
><br>
> ~/tmp/genex_with_spaces$ cat CMakeLists.txt<br>
> cmake_minimum_required(VERSION 3.6)<br>
><br>
><br>
><br>
> add_custom_target(foo)<br>
><br>
> add_custom_command(TARGET foo POST_BUILD<br>
><br>
> COMMAND $<1:echo> $<1:bar><br>
><br>
> )<br>
><br>
><br>
><br>
> ~/tmp/genex_with_spaces$ grep bar build/CMakeFiles/foo.dir/<wbr>build.make<br>
> echo bar<br>
><br>
> ```<br>
><br>
><br>
> Of course, while this works, things becomes very unreadable if the genex is<br>
> more complex.<br>
><br>
><br>
><br>
> Other things that I have tried but failed:<br>
><br>
> escape the space with a backslash -> this quotes the entire expression<br>
> inside the genex.<br>
> define the command directly as a list inside the genex -> this removes<br>
> spaces between the different components of the command and quotes that<br>
> result.<br>
> treat the command as a list, perform string operations to wrap each element<br>
> in the desired regex and convert semicolon to spaces -> again results in the<br>
> command being quoted as a whole.<br>
><br>
><br>
><br>
> Any advice is highly appreciated.<br>
><br>
><br>
><br>
> Thanks,<br>
><br>
> Yves<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
</div></div>> --<br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at:<br>
> <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more<br>
> information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/<wbr>listinfo/cmake</a><br>
><br>
</blockquote></div><br></div>