<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">What about this:</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><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.</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Björn Blissing <bjorn.blissing@vti.se><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</font>
<div> </div>
</div>
<meta content="text/html; charset=iso-8859-1">
<meta name="x_Generator" content="Microsoft Word 15 (filtered medium)">
<style>
<!--
@font-face
{font-family:"Cambria Math"}
@font-face
{font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
a:x_link, span.x_MsoHyperlink
{color:blue;
text-decoration:underline}
a:x_visited, span.x_MsoHyperlinkFollowed
{color:purple;
text-decoration:underline}
p.x_msonormal0, li.x_msonormal0, div.x_msonormal0
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
p.x_xmsonormal, li.x_xmsonormal, div.x_xmsonormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
p.x_xmsonormal0, li.x_xmsonormal0, div.x_xmsonormal0
{margin-right:0cm;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
p.x_xmsochpdefault, li.x_xmsochpdefault, div.x_xmsochpdefault
{margin-right:0cm;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
span.x_xe-postmall18
{font-family:"Calibri",sans-serif;
color:windowtext}
span.x_E-postmall24
{font-family:"Calibri",sans-serif;
color:windowtext}
.x_MsoChpDefault
{font-size:10.0pt}
@page WordSection1
{margin:70.85pt 70.85pt 70.85pt 70.85pt}
div.x_WordSection1
{}
-->
</style>
<div lang="SV" link="blue" vlink="purple">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span lang="EN-US" style="">Hi Andrew,</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="">When I put the genex inside double quotes I get:<br>
<br>
</span></p>
<p class="x_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,</span></p>
<p class="x_xmsonormal"><span lang="EN-US">Björn</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </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="x_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</p>
</div>
</div>
<p class="x_MsoNormal"> </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></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">target_link_libraries(my_exe</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> PUBLIC</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> "$<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}>"</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> "$<$<BOOL:${USE_BARLIB}>:bar>"</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">)</span></p>
</div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div class="x_MsoNormal" align="center" style="text-align:center">
<hr size="3" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="x_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>
</p>
<div>
<p class="x_MsoNormal"> </p>
</div>
</div>
<div>
<div>
<p class="x_xmsonormal">Hi Eric,</p>
<p class="x_xmsonormal"> </p>
<p class="x_xmsonormal"><span lang="EN-US">I tried to do a self contained minimal example:
</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">cmake_minimum_required(VERSION 3.12)</span></p>
<p class="x_xmsonormal"><span lang="EN-US">project(expension_error LANGUAGES CXX)</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">add_executable(my_exe main.cpp)</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">option(USE_FOOLIB "Use foo.lib" ON)</span></p>
<p class="x_xmsonormal"><span lang="EN-US">option(USE_BARLIB "Use bar.lib" ON)</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES optimized foo)</span></p>
<p class="x_xmsonormal"><span lang="EN-US">list(APPEND FOO_LIBRARIES debug foo_d)</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">target_link_libraries(my_exe</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> PUBLIC</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> $<$<BOOL:${USE_FOOLIB}>:${FOO_LIBRARIES}></span></p>
<p class="x_xmsonormal"><span lang="EN-US"> $<$<BOOL:${USE_BARLIB}>:bar></span></p>
<p class="x_xmsonormal"><span lang="EN-US">)</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">But when I run this script using CMake 3.12.2, it expands to something even worse:</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;foo_d>.lib;bar.lib --- for debug builds</span></p>
<p class="x_xmsonormal"><span lang="EN-US">$<1:optimized;foo.lib;>.lib;bar.lib-- for release builds</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_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></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US">Regards,</span></p>
<p class="x_xmsonormal"><span lang="EN-US">Björn</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </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="x_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></p>
</div>
</div>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<div>
<p class="x_xmsonormal" style="margin-bottom:12.0pt"><span lang="EN-US"> </span></p>
<div>
<div>
<p class="x_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 :</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="x_xmsonormal"><span lang="EN-US">Hello Eric,</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_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> </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="x_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></p>
</div>
</div>
</blockquote>
<div>
<p class="x_xmsonormal"> </p>
</div>
<div>
<p class="x_xmsonormal">Sometimes the devil is hiding in the details.</p>
</div>
<div>
<p class="x_xmsonormal">Do ou manage to reproduce the genex expansion error on a toy example?</p>
</div>
<div>
<p class="x_xmsonormal"> </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="x_xmsonormal"><span lang="EN-US">I do agree that using it would be simpler if I could use:</span></p>
<p class="x_xmsonormal"><span lang="EN-US"> $<$<CONFIG:Debug>:${MYLIBS_DEBUG}></span></p>
<p class="x_xmsonormal"><span lang="EN-US"> $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}></span></p>
<p class="x_xmsonormal"><span lang="EN-US"> </span></p>
<p class="x_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></p>
</div>
</div>
</blockquote>
<div>
<p class="x_xmsonormal"> </p>
</div>
<div>
<p class="x_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.</p>
</div>
<div>
<p class="x_xmsonormal">This way you don't have to rewrite 3rd party code and keep your code clean.</p>
</div>
</div>
<div>
<p class="x_xmsonormal"> </p>
</div>
<p class="x_xmsonormal">-- </p>
<div>
<div>
<div>
<div>
<div>
<p class="x_xmsonormal">Eric</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>