Just curious, what would be the inconvenience of using an if statement around  <font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">target_link_libraries </span></font>to link against one or another target?<br>
<br><div class="gmail_quote">On Tue, Mar 24, 2009 at 12:30 PM, Alexandre Feblot <span dir="ltr">&lt;<a href="mailto:Alexandre.Feblot@thomsonreuters.com">Alexandre.Feblot@thomsonreuters.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div link="blue" vlink="#606420" lang="FR">

<div>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Hi,</span></font><span lang="EN-GB"></span></p>

<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">I&#39;m facing an issue while trying to port my current
build system to cmake, and it seems there is no way to solve it currently.
At least, nobody in the mailing list found one. The only suggestion was to
totally recode the dependency mechanism with macros instead of relying on the
Cmake standard mechanism (as done in Boost), which doesn&#39;t really look like an
optimal use of cmake.</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Let me explain the problem again, and propose the
cmake api to solve it:</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">----- PROBLEM:</span></font><span lang="EN-GB"></span></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">It&#39;s a typical application of the C++ link time
variation idiom:</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">In our project, we build a bunch of <b><b><font face="Arial"><span style="font-family: Arial;">static</span></font></b></b>
libs (about 360) and several executables on them.</span></font><span lang="EN-GB"></span></p>

<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">* one library, in the middle of the lib dependency
chain, has in fact 2 different implementations. That is to say, there are 2
different libs with the exact same interface, but they don&#39;t use the same
back-end, have different source code, and don&#39;t have the same dependencies.</span></font><span lang="EN-GB"></span></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">* only one of them has to be used in every
executable, the implementation to use is determined by the executable.</span></font><span lang="EN-GB"></span></p>

<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Dependency graph example: &quot;-&gt;&quot; means
&quot;depends on&quot;</span></font><font face="Arial"><span style="font-family: Arial;" lang="EN-GB"></span></font></p>

<p><font size="3" face="Arial"><span style="font-size: 12pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><b><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">exe1-A</span></font></b></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB"> -&gt; lib1 -&gt; lib3 -&gt; <b><b><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;">lib4-A</span></font></b></b>
-&gt; lib5 -&gt; lib7</span></font><font face="Arial"><span style="font-family: Arial;" lang="EN-GB"></span></font></p>

<p><b><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">exe1-B</span></font></b></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB"> -&gt; lib1 -&gt; lib3 -&gt; <b><b><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;">lib4-B</span></font></b></b>
-&gt; lib6 -&gt; lib8</span></font><font face="Arial"><span style="font-family: Arial;" lang="EN-GB"></span></font></p>

<p><b><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">exe2-A</span></font></b></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB"> -&gt; lib2 -&gt; lib3 -&gt; <b><b><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;">lib4-A</span></font></b></b>
-&gt; lib5 -&gt; lib7</span></font><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;" lang="EN-GB"></span></font></p>

<p><b><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">exe2-B</span></font></b></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB"> -&gt; lib2 -&gt; lib3 -&gt; <b><b><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;">lib4-B</span></font></b></b>
-&gt; lib6 -&gt; lib8</span></font><font face="Courier New"><span style="font-family: &quot;Courier New&quot;;" lang="EN-GB"></span></font></p>

<p><font size="3" face="Arial"><span style="font-size: 12pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="3" face="Arial"><span style="font-size: 12pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">I&#39;d like to keep using the standard cmake mechanism
of dependency description in which every lib only defines on which other
libs it depends, and let cmake compute the final link line.</span></font><span lang="EN-GB"></span></p>

<p><font size="3" face="Times New Roman"><span style="font-size: 12pt;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">----- SOLUTION : Feature request:</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Adding a SELECTOR keyword (working a bit like
debug|optimized) to target_link_libraries to specify that the given dependency
is only required when this selector has a given value.</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">The selector will be defined when building the
executable.</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<pre><font size="2" face="Courier New"><span style="font-size: 10pt;" lang="EN-GB">target_link_libraries(&lt;target&gt; [item1 [item2 [...]]]<br>
                        <b><span style="font-weight: bold;">[[SELECTOR &lt;selectorName&gt; &lt;selectorValue&gt;]</span></b>[debug|optimized|general] &lt;item&gt;] ...)</span></font></pre>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">* lib3 CMakeLists.txt:</span></font></p>

<p style="text-indent: 35.4pt;"><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">add_library(lib3  some
source)</span></font></p>

<p style="text-indent: 35.4pt;"><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">target_link_libraries(lib3,</span></font></p>

<p style="margin-left: 35.4pt; text-indent: 35.4pt;"><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; font-weight: bold;" lang="EN-GB">SELECTOR</span></font></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">
 A_OR_B  A  lib4-A</span></font></p>

<p style="margin-left: 35.4pt; text-indent: 35.4pt;"><b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; font-weight: bold;" lang="EN-GB">SELECTOR</span></font></b><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">
 A_OR_B  B  lib4-B</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      )</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">* exe1-A CmakeLists.txt</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      add_executable(exe1-A  some
sources)</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      <b><span style="font-weight: bold;">set (A_OR_B  A)</span></b></span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      target_link_libraries(exe1-A
 lib1)  # will link with lib4-A</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">* exe1-B CmakeLists.txt</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      add_executable(exe1-A  some
sources)</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      <b><span style="font-weight: bold;">set (A_OR_B  B)</span></b></span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB">      target_link_libraries(exe1-A
 lib1)  # will link with lib4-B</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Would you see this feature in a future official
release?</span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Would you include a patch if we code it with your
help, as we don&#39;t know much about cmake sources.</span></font></p>

<p><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;" lang="EN-GB"> </span></font></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Thanks,</span></font><span lang="EN-GB"></span></p>

<p><font size="2" face="Arial"><span style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> </span></font></p>

</div>

<br clear="all"> This email was sent to you by Thomson Reuters, the global news and information company.<br>
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.
</div>



<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br><br clear="all"><br>-- <br>Adolfo Rodríguez Tsouroukdissian<br><br>Robotics engineer<br>
PAL ROBOTICS S.L<br><a href="http://www.pal-robotics.com">http://www.pal-robotics.com</a><br>Tel. +34.93.414.53.47<br>Fax.+34.93.209.11.09<br>