<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">Le jeu. 4 oct. 2018 à 16:06, Björn Blissing <<a href="mailto:bjorn.blissing@vti.se">bjorn.blissing@vti.se</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="SV">
<div class="gmail-m_8605342384271848267WordSection1">
<p class="MsoNormal">Hello,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span lang="EN-US">I am having trouble with a conditional generator expression inside target link libraries, which seems to expand incorrectly (or at least not the way I expect).<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">In short, I have a list of libraries that is found by a CMake module. The list is composed of a number of elements each preceded by “optimized” or “debug”, depending on if there are built for release or debug. These libraries
should only be included if a boolean is set to true. I have tried to write a generator expression which only includes the list of libraries if this variable is set. But it seems that this expression gets expanded wrong.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">If I try to condense the problem to a minimum example, it would be something like this:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">LIST(APPEND MYLIB_LIBRARIES optimized foo)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">LIST(APPEND MYLIB_LIBRARIES debug foo_d)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">TARGET_LINK_LIBRARIES(target_name<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> PUBLIC <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"> $<$<BOOL:TRUE>:${MYLIB_LIBRARIES}><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">)</span></p></div></div></blockquote><div><br></div><div>I don't quite understand your usage here. The genex $<BOOL:TRUE> is always true?</div><div>You must have something like:</div><div><br></div><div>$<$<BOOL:${CONDVAR}>:${MYLIB_LIBRARIES}> </div><div><br></div><div>with CONDVAR computed before that to HOLD TRUE/1 or FALSE/0</div><div>or something similar?</div><div><br></div><div>I would try to build a proper MYLIBS_DEBUG and MYLIBS_OPTIMIZED list out of your MYLIB_LIBRARIES var</div><div><br></div><div>and then:</div><div><br></div><div>target_link_libraries(target_name</div><div> PUBLIC</div><div> $<$<CONFIG:Debug>:${MYLIBS_DEBUG}></div><div> $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}></div><div><br></div><div>which may be easier to read.</div><div><br></div><div>Or may be I missed something in your explanation.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="SV"><div class="gmail-m_8605342384271848267WordSection1"><p class="MsoNormal"><span lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">This generator expression makes my target depend of the following libraries for the release build:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">foo.lib & optimized.lib<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">And for the debug build:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">foo_d.lib, foo.lib & optimized.lib<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Which is obviously incorrect. <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Replacing the generator expression with an IF-statement instead works. But I would like to stick to generator expressions if possible to keep my CMake code consistent.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">How should I rewrite my generator expression to get the correct expansion?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Björn<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</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: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more 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/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/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/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/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/listinfo/cmake</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div></div></div></div></div>