<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
{mso-style-name:x_msonormal;
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.xmsonormal0, li.xmsonormal0, div.xmsonormal0
{mso-style-name:x_msonormal0;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.xmsochpdefault, li.xmsochpdefault, div.xmsochpdefault
{mso-style-name:x_msochpdefault;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.xe-postmall18
{mso-style-name:x_e-postmall18;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.E-postmall24
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="SV" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Hi Andrew,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">When I put the genex inside double quotes I get:<br>
<br>
<o:p></o:p></span></p>
<p class="xmsonormal"><span lang="EN-US">optimized.lib;foo.lib;debug.lib;foo_d.lib;bar.lib; --- for both debug and release builds<br>
<br>
Regards,<o:p></o:p></span></p>
<p class="xmsonormal"><span lang="EN-US">Björn<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>From:</b> Andrew Fuller <afuller@teradici.com> <br>
<b>Sent:</b> Thursday, October 4, 2018 5:54 PM<br>
<b>To:</b> Björn Blissing <bjorn.blissing@vti.se>; Eric Noulard <eric.noulard@gmail.com><br>
<b>Cc:</b> CMake Mailinglist <cmake@cmake.org><br>
<b>Subject:</b> Re: [CMake] Trouble with conditional generator expression inside target_link_libraries<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">What happens if you put the genex inside double quotes?<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">target_link_libraries(my_exe<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"> PUBLIC<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"> "$<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}>"<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"> "$<$<BOOL:${USE_BARLIB}>:bar>"<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">)<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> CMake <<a href="mailto:cmake-bounces@cmake.org">cmake-bounces@cmake.org</a>> on behalf of Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>><br>
<b>Sent:</b> October 4, 2018 8:49:19 AM<br>
<b>To:</b> Eric Noulard<br>
<b>Cc:</b> CMake Mailinglist<br>
<b>Subject:</b> Re: [CMake] Trouble with conditional generator expression inside target_link_libraries</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal">Hi Eric,<o:p></o:p></p>
<p class="xmsonormal"> <o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">I tried to do a self contained minimal example:
</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">cmake_minimum_required(VERSION 3.12)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">project(expension_error LANGUAGES CXX)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">add_executable(my_exe main.cpp)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">option(USE_FOOLIB "Use foo.lib" ON)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">option(USE_BARLIB "Use bar.lib" ON)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES optimized foo)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES debug foo_d)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">target_link_libraries(my_exe</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> PUBLIC</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> $<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}></span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> $<$<BOOL:${USE_BARLIB}>:bar></span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">)</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">But when I run this script using CMake 3.12.2, it expands to something even worse:</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;foo_d>.lib;bar.lib --- for debug builds</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;>.lib;bar.lib-- for release builds</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">So something goes really wrong when I try to use a list inside a conditional generator expression inside target_link_libraries().</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">Regards,</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">Björn</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="xmsonormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Eric Noulard <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>>
<br>
<b>Sent:</b> Thursday, October 4, 2018 5:10 PM<br>
<b>To:</b> Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>><br>
<b>Cc:</b> CMake Mailinglist <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>><br>
<b>Subject:</b> Re: [CMake] Trouble with conditional generator expression inside target_link_libraries</span><o:p></o:p></p>
</div>
</div>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<div>
<p class="xmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<div>
<div>
<p class="xmsonormal">Le jeu. 4 oct. 2018 ā 16:53, Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>> a écrit :<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="xmsonormal"><span lang="EN-US">Hello Eric,</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">The minimal example was just to display the expansion error. In real life the code uses a Boolean variable (and the rest of the CMake code is much larger as well).</span> <o:p></o:p></p>
</div>
</div>
</blockquote>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="xmsonormal"><span lang="EN-US">It was just to show the expansion error you get if you try to use a conditional generator expression inside a target_link_libraries function.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="xmsonormal"> <o:p></o:p></p>
</div>
<div>
<p class="xmsonormal">Sometimes the devil is hiding in the details.<o:p></o:p></p>
</div>
<div>
<p class="xmsonormal">Do ou manage to reproduce the genex expansion error on a toy example?<o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="xmsonormal"><span lang="EN-US">I do agree that using it would be simpler if I could use:</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> $<$<CONFIG:Debug>:${MYLIBS_DEBUG}></span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}></span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US">But since I use a third party find module the MYLIB_LIBRARIES variable is not separated into these categories. I was hoping to avoid rewriting this external find module.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="xmsonormal"> <o:p></o:p></p>
</div>
<div>
<p class="xmsonormal">You can perfectly write a CMake helper function which takes MYLIB_LIBRARIES as input and spit out MYLIBS_DEBUG, MYLIBS_OPTIMIZED as an output.<o:p></o:p></p>
</div>
<div>
<p class="xmsonormal">This way you don't have to rewrite 3rd party code and keep your code clean.<o:p></o:p></p>
</div>
</div>
<div>
<p class="xmsonormal"> <o:p></o:p></p>
</div>
<p class="xmsonormal">-- <o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<p class="xmsonormal">Eric<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>