<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=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<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:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1221595857;
mso-list-template-ids:1022519164;}
@list l1
{mso-list-id:1674189376;
mso-list-type:hybrid;
mso-list-template-ids:2080118808 67829775 67829785 67829787 67829775 67829785 67829787 67829775 67829785 67829787;}
@list l1:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l1:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></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="FI" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I understand it is a bit awkward scenario to need to have all symbols from barstatic available in fooshared and yes I
can work around it by the OBJECT library method.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">However, I see it contradictory to<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l1 level1 lfo2"><![if !supportLists]><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Get all symbols from barstatic included into fooshared when linking it in PUBLIC mode<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l1 level1 lfo2"><![if !supportLists]><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Still need to export also barstatic even when this is not necessary due to 1.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Clarification: the executable is spit out from the same build/cmake than fooshared. It uses only barstatic and not fooshared
at all. The executable is not the problem, problem is the exporting of fooshared to external builds.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">This goes towards generic discussion on what is the preferred way of creating both .so and .a versions of a library, check
e.g. <a href="https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-version-of-the-sam">
https://stackoverflow.com/questions/2152077/is-it-possible-to-get-cmake-to-build-both-a-static-and-shared-version-of-the-sam</a>. Although the OBJECT library method works, it is clumsy due to needing to define target_include_directories, compiler flags etc
multiple times and having yet another named target to maintain. It is more beautiful to just create the static lib as your base and then link the shared version to it, although it works only when the shared lib has at least one extra source file compared to
the static version. Or, worked until the export stage.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">-Lassi<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Marc CHEVRIER <marc.chevrier@gmail.com>
<br>
<b>Sent:</b> torstai 28. helmikuuta 2019 11.37<br>
<b>To:</b> cmake-developers@cmake.org; Lassi Niemistö <lassi.niemisto@wapice.com><br>
<b>Subject:</b> Re: [cmake-developers] Mandatory export of a static library dependency<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div name="messageBodySection">
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Hi,
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">It is perfectly normal that CMake requires static library to be exported when command ’target_link_libraries(fooshared barstatic)’ is specified because this is equivalent to
command 'target_link_libraries(fooshared PUBLIC barstatic)’.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">As you have already discovered, using command 'target_link_libraries(fooshared PRIVATE barstatic)’ avoids exporting of barstatic library.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Now, I think you did a wrong diagnostic regarding your link problems with this signature. Symbols visibility is not changed by specifying ‘PRIVATE’ but link commands are changed.
With ‘PRIVATE’, the link command for your executable <b>do not contains anymore a </b>reference to barstatic library. And the ‘fooshared’ library will contains
<b>only</b> objects from ‘barstatic’ needed to solved unreferenced symbols (so may be not all objects from ‘barstatic’).<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">So to solve your problem you have two possibilities:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
<div>
<ol start="1" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
<span style="font-size:10.5pt;font-family:"Arial",sans-serif">Specify ‘barstatic’ library as dependency of your executable, i.e. 'target_link_libraries(exec PRIVATE fooshared barstatic)’.<o:p></o:p></span></li><li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1">
<span style="font-size:10.5pt;font-family:"Arial",sans-serif">Ensure that all objects of `barstatic` are included in your ‘fooshared’ library. For that purpose, you can create `barstatic` as OBJECT library and include all objects in your ‘fooshared’ library
using pattern ‘add_library(fooshared SHARED .. $<TARGET_OBJECTS:barstatic> …)’. But the most simple is, may be, to put directly all your sources in ‘fooshared’ library.<o:p></o:p></span></li></ol>
<div>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
</div>
</div>
<div name="messageReplySection">
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Le 28 févr. 2019 à 08:25 +0100, Lassi Niemistö <lassi.niemisto@wapice.com>, a écrit :<br>
<br>
<o:p></o:p></span></p>
<blockquote style="border:none;border-left:solid #1ABC9C 1.0pt;padding:0cm 0cm 0cm 8.0pt;margin-left:3.75pt;margin-top:3.75pt;margin-right:3.75pt;margin-bottom:3.75pt">
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif">Hello,<br>
<br>
The cmake "users" list did not wake any replies, so posting here as a possible bug:<br>
<br>
I use CMake 3.13RC1. My project produces, installs and exports a shared library target "fooshared". Some logical parts of "fooshared" are reused in an executable, so I have placed those sources into an internal static library target "barstatic". I have used
target_link_libraries(fooshared barstatic) to make this work.<br>
<br>
Problem: when I try to:<br>
install(TARGETS fooshared DESTINATION <dest> EXPORT myexport)<br>
install(EXPORT myexport DESTINATION <dest>)<br>
..I get a whine about dependency to "barstatic" which is not in the export group "myexport".<br>
<br>
I wouldn't like to export "barstatic" at all, it should remain under the hood. I tried to use target_link_libraries(fooshared PRIVATE barstatic) which cut the export chaining, but then symbols from "barstatic" were not available for users of "fooshared" anymore.
So I worked around this by converting "barstatic" into an object library, but it feels ugly.<br>
<br>
Why would CMake require exporting statically linked dependency targets among the targets that use them? Feels like a bug to me.<br>
<br>
Regards,<br>
-Lassi Niemistö<br>
--<br>
<br>
Powered by www.kitware.com<br>
<br>
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: http://cmake.org/cmake/help/support.html<br>
CMake Consulting: http://cmake.org/cmake/help/consulting.html<br>
CMake Training Courses: http://cmake.org/cmake/help/training.html<br>
<br>
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br>
<br>
Follow this link to subscribe/unsubscribe:<br>
https://cmake.org/mailman/listinfo/cmake-developers<o:p></o:p></span></p>
</blockquote>
</div>
</div>
</body>
</html>