<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;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.xxmsonormal, li.xxmsonormal, div.xxmsonormal
        {mso-style-name:x_xmsonormal;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.xxmsonormal0, li.xxmsonormal0, div.xxmsonormal0
        {mso-style-name:x_xmsonormal0;
        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.xxmsochpdefault, li.xxmsochpdefault, div.xxmsochpdefault
        {mso-style-name:x_xmsochpdefault;
        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:10.0pt;
        font-family:"Calibri",sans-serif;}
span.xxe-postmall18
        {mso-style-name:x_xe-postmall18;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.xe-postmall24
        {mso-style-name:x_e-postmall24;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.E-postmall28
        {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 style="mso-fareast-language:EN-US">Hi Andrew,<o:p></o:p></span></p>
<p class="MsoNormal"><span 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">That works, but as previously said. The third party find module I am using do not differentiate between debug and release libraries. To make matters even worse the keywords “optimized”
 and “debug” is already in the variable list, trying to split them will be painful.<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">The workaround I am using right now is to have an IF-statement for the list option:<br>
<br>
if(${USE_FOOLIB})<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">    target_link_libraries(my_exe<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">    PUBLIC<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">        ${FOO_LIBRARIES}<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">endif()<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>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">target_link_libraries(my_exe<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">    PUBLIC<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">         $<$<BOOL:${USE_BARLIB}>:bar><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>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">But that breaks the pattern with using generator expressions, as I do for the rest of my options.<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">I don’t know if this should be considered a bug, but it seems really strange that generator expressions should break down for only this special case, i.e. the combination using lists
 with the conditional operator BOOL and using it inside target_link_libraries. <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">I don’t know if other CMake functions will react similarly bad to the list/bool operator combo.<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">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language: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 6:16 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 about this:<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
<p><span style="font-size:12.0pt;color:black"><br>
list(APPEND FOO_LIBRARIES_OPT foo) <br>
list(APPEND FOO_LIBRARIES_DBG foo_d) <br>
<br>
target_link_libraries(my_exe <br>
   PUBLIC <br>
        debug "$<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES_DBG}>" <br>
        optimized "$<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES_OPT}>" <br>
        "$<$<BOOL:${USE_BARLIB}>:bar>" <br>
)<br>
<br>
A little more verbose.<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"> Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>><br>
<b>Sent:</b> October 4, 2018 9:00:28 AM<br>
<b>To:</b> Andrew Fuller; 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"><span lang="EN-US">Hi Andrew,</span><o:p></o:p></p>
<p class="xmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US">When I put the genex inside double quotes I get:</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">optimized.lib;foo.lib;debug.lib;foo_d.lib;bar.lib; --- for both debug and release builds<br>
<br>
Regards,</span><o:p></o:p></p>
<p class="xxmsonormal"><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>
<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>From:</b> Andrew Fuller <<a href="mailto:afuller@teradici.com">afuller@teradici.com</a>>
<br>
<b>Sent:</b> Thursday, October 4, 2018 5:54 PM<br>
<b>To:</b> Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>>; Eric Noulard <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</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<o:p></o:p></p>
</div>
</div>
<p class="xmsonormal"> <o:p></o:p></p>
<div id="x_divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">What happens if you put the genex inside double quotes?</span><o:p></o:p></p>
<p><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">target_link_libraries(my_exe</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">    PUBLIC</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">         "$<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}>"</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">         "$<$<BOOL:${USE_BARLIB}>:bar>"</span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black">)</span><o:p></o:p></p>
</div>
<p class="xmsonormal"><span style="font-size:12.0pt;color:black"> </span><o:p></o:p></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="xmsonormal"><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="xmsonormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xxmsonormal">Hi Eric,<o:p></o:p></p>
<p class="xxmsonormal"> <o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">I tried to do a self contained minimal example:
</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">cmake_minimum_required(VERSION 3.12)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">project(expension_error LANGUAGES CXX)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">add_executable(my_exe main.cpp)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">option(USE_FOOLIB "Use foo.lib" ON)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">option(USE_BARLIB "Use bar.lib" ON)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES optimized foo)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES debug foo_d)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">target_link_libraries(my_exe</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">    PUBLIC</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">         $<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}></span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">         $<$<BOOL:${USE_BARLIB}>:bar></span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">)</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><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="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;foo_d>.lib;bar.lib --- for debug builds</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;>.lib;bar.lib-- for release builds</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><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="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">Regards,</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">Björn</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><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="xxmsonormal"><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="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<div>
<p class="xxmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US"> </span><o:p></o:p></p>
<div>
<div>
<p class="xxmsonormal">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="xxmsonormal"><span lang="EN-US">Hello Eric,</span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><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="xxmsonormal"><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="xxmsonormal"> <o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal">Sometimes the devil is hiding in the details.<o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal">Do ou manage to reproduce the genex expansion error on a toy example?<o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal"> <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="xxmsonormal"><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="xxmsonormal"><span lang="EN-US">     $<$<CONFIG:Debug>:${MYLIBS_DEBUG}></span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US">     $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}></span><o:p></o:p></p>
<p class="xxmsonormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="xxmsonormal"><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="xxmsonormal"> <o:p></o:p></p>
</div>
<div>
<p class="xxmsonormal">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="xxmsonormal">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="xxmsonormal"> <o:p></o:p></p>
</div>
<p class="xxmsonormal">-- <o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<p class="xxmsonormal">Eric<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>