<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 7, 2019 at 12:27 AM Tadeusz A. Kadłubowski <<a href="mailto:tadeusz.kadlubowski@pix4d.com">tadeusz.kadlubowski@pix4d.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I have an `INTERFACE IMPORTED` library target that depends on a bunch<br>
of optional dependencies. Please see the snippet below:<br>
<br>
cmake_minimum_required(VERSION 3.14)<br>
<br>
add_library(example INTERFACE IMPORTED)<br>
set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES<br>
$<$<CONFIG:Debug>:${undefined_dependency_one}<br>
${undefined_dependency_two}><br>
)<br></blockquote><div><br></div><div>If your generator expression contains spaces, you need to surround the whole expression with quotes:</div><div><br></div><div>set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES<br>    "$<$<CONFIG:Debug>:${undefined_dependency_one} ${undefined_dependency_two}>"<br>)<br></div><div><br></div><div>Note that in this case, the space is unlikely to actually be what you want because the above would end up adding a single library named</div><div><br></div><div>"${undefined_dependency_one} ${undefined_dependency_two}"</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
It so happens that both of the optional dependencies<br>
`${undefined_dependency_one}` and `${undefined_dependency_two}` are<br>
set to empty/undefined on my system, which is perfectly fine.<br>
<br>
I want to do some postprocessing to the dependencies  of my target:<br>
<br>
get_target_property(all_dependencies example INTERFACE_LINK_LIBRARIES)<br>
foreach(lib IN LISTS all_dependencies)<br>
    message(STATUS "dependency on " ${lib})<br>
endforeach()<br>
<br>
This `foreach()` loop gets confused about the generator expression.<br>
The output of the `message(STATUS ...)` calls in the snippet above is:<br>
<br>
-- dependency on $<$<CONFIG:Debug>:<br>
-- dependency on ><br>
<br>
Please note that the generator expression got mangled into two pieces<br>
by the `foreach()` loop. I was expecting to see a single line of<br>
`$<$<CONFIG:Debug>:>`<br>
<br>
I experimented with different versions of this test case and found<br>
variants that do not get mangled in the `foreach()` loop. In a<br>
modification when there is only one empty/undefined dependency the<br>
`foreach()` loop works as expected.<br>
<br>
set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES<br>
$<$<CONFIG:Debug>:${undefined_dependency_one}><br>
)<br>
<br>
A modification in which each empty/undefined dependency is surrounded<br>
with its own generator expression works correctly too:<br>
<br>
set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES<br>
$<$<CONFIG:Debug>:${undefined_dependency_one}><br>
$<$<CONFIG:Debug>:${undefined_dependency_two}><br>
)<br></blockquote><div><br></div><div>This would be the way to achieve what you seem to be wanting to do.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Is that a bug in how CMake handles generator expressions? Am I<br>
misunderstanding some CMake language concepts here?<br>
<br>
(all code tested with CMake 3.14.3 on Ubuntu 18.04)<br>
<br>
I would be grateful on any feedback about what's going on in that<br>
`foreach` loop.<br></blockquote><div> </div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>Get the hand-book for every CMake user: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>