[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] Specify extra files for display in IDE
From:       Daniel Eiband <daniel.eiband () brainlab ! com>
Date:       2018-08-30 13:46:48
Message-ID: ed905480536346ef8d5331f667cc9a01 () despmsx01 ! brainlab ! net
[Download RAW message or body]

[Attachment #2 (text/plain)]

Hi Eric,



Thank you for your answers! Visual Studio supports the source_group command, but it \
cannot be used to add sources. It only controls where source files of targets are \
displayed.



> I do very often add non source file (like README.md) to any targets



This is what I also do for non-build related files such as readme files. It works \
except for interface libraries (read below). In the object library case I can add \
non-build related files, but for let's say 'logical' reasons I would like to show the \
build related files such as cpp files also in the shared library target which links \
to the object library.



> At least the "never displayed" header only library looks like a bug of the Visual \
> Studio generator to me.



The situation for interface libraries (header only) is different: CMake won't allow \
me to add any sources to the target, not even headers. As a result configure fails \
with an error. I'm pretty sure if I could add headers to interface libraries then \
they will show up in Visual Studio with this target. So I think it's not a generator \
bug, but a short-coming of CMake itself.



Daniel


From: Eric Noulard [mailto:eric.noulard@gmail.com]
Sent: Donnerstag, 30. August 2018 14:40
To: Daniel Eiband <daniel.eiband@brainlab.com>
Cc: CMake Mailinglist <cmake@cmake.org>
Subject: Re: [CMake] Specify extra files for display in IDE


Le jeu. 30 août 2018 à 12:32, Daniel Eiband \
<daniel.eiband@brainlab.com<mailto:daniel.eiband@brainlab.com>> a écrit : Hi,

I'm currently migrating a code base from a proprietary MSBuild based generator to \
CMake 3.11 which is shipped with Visual Studio. There are two aspects to this task:

1) Integration of custom build steps
2) Presentation in the IDE

The first aspect of integrating all of our custom build steps as custom commands \
works really well. At one point I use an object library to be able to use the object \
files as input to such a custom tool and to link a shared library. Both the object \
library and the shared library are from the programmers perspective one logical unit. \
The object library is just an implementation detail. However, as for the second \
point, the source files are displayed with the object library target in the IDE while \
the shared library has no sources. This makes sense from the build targets point of \
view, but surprises the developers. My approach is to hide all targets which are sort \
of implementation detail into a folder.  To make this work I would like to display \
the sources with the shared library which consumes the object files of the object \
library. Currently this seems to be impossible.

Another inconsistency I noticed regarding the second point is the following: I \
implemented header only libraries as interface libraries in CMake. This works fine \
from the build perspective. Interface libraries however don't allow me to list \
sources, not even headers. As a result, the headers of this header only library are \
not displayed anywhere in the IDE. This is odd, because in executable targets for \
example I can list all headers even if they don't contribute to the build process \
directly and they are displayed in the IDE. Using empty custom targets to present the \
header files works, but they are not displayed as C++ libraries in Visual Studio any \
longer. This also litters the solution with lots of extra empty targets.

I'm going to rephrase both described presentation problems into one more fundamental \
question, solutions or workarounds for either of both presentation problems are of \
course welcome: Can I specify sources used for builds and files used for display in \
IDEs separately? I think they are two different things. For my use case it would also \
be sufficient to be able to add extra files for display in IDEs to any target.

I'm afraid that your question may be generator-specific and I'm no sure Visual Studio \
generator behaves in the same way as others I'm using. I do very often add non source \
file (like README.md) to any targets (add_executable, add_library, add_custom_target) \
in order to make them editable in the IDE. Since those file are guessed as not being \
compilable they inherit the HEADER_FILE_ONLY  \
(https://cmake.org/cmake/help/v3.11/prop_sf/HEADER_FILE_ONLY.html) automatically and \
they show up in IDE just fine.

My particular IDE being either qtcreator, vscode+cmaketools or eclipse and this works \
well for those.

Moreover, in qtcreator (for example) header only libraries appear on their own with \
editable header file AND as subdir of every other targets their are used by. This \
subdir contains the headers. This is not the case with object libraries though :-(

Concerning the visual grouping you must already being using source_group \
(https://cmake.org/cmake/help/latest/command/source_group.html) source_group does not \
seems to have any effect in my favorite IDEs...

In the end I don't know if there is currently any ways to do what you want.

At least the "never displayed" header only library looks like a bug of the Visual \
Studio generator to me.


--
Eric


[Attachment #3 (text/html)]

<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:"MS Mincho";
	panose-1:2 2 6 9 4 2 5 8 3 4;}
@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;}
@font-face
	{font-family:"\@MS Mincho";
	panose-1:2 2 6 9 4 2 5 8 3 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:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
	{mso-style-priority:99;
	mso-style-link:"Plain Text Char";
	margin:0cm;
	margin-bottom:.0001pt;
	font-size:9.0pt;
	font-family:"Arial",sans-serif;
	color:black;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:"Arial",sans-serif;
	color:black;
	font-weight:normal;
	font-style:normal;}
span.EmailStyle18
	{mso-style-type:personal;
	font-family:"Arial",sans-serif;
	color:black;
	font-weight:normal;
	font-style:normal;}
span.PlainTextChar
	{mso-style-name:"Plain Text Char";
	mso-style-priority:99;
	mso-style-link:"Plain Text";
	font-family:"Arial",sans-serif;
	color:black;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoPlainText">Hi Eric,<o:p></o:p></p>
<p class="MsoPlainText"><o:p>&nbsp;</o:p></p>
<p class="MsoPlainText">Thank you for your answers! Visual Studio supports the \
source_group command, but it cannot be used to add sources. It only controls where \
source files of targets are displayed.<o:p></o:p></p> <p \
class="MsoPlainText"><o:p>&nbsp;</o:p></p> <p class="MsoPlainText">&gt; I do very \
often add non source file (like README.md) to any targets<o:p></o:p></p> <p \
class="MsoPlainText"><o:p>&nbsp;</o:p></p> <p class="MsoPlainText">This is what I \
also do for non-build related files such as readme files. It works except for \
interface libraries (read below). In the object library case I can add non-build \
related files, but for let's say 'logical' reasons I would  like to show the build \
related files such as cpp files also in the shared library target which links to the \
object library.<o:p></o:p></p> <p class="MsoPlainText"><o:p>&nbsp;</o:p></p>
<p class="MsoPlainText">&gt; At least the &quot;never displayed&quot; header only \
library looks like a bug of the Visual Studio generator to me.<o:p></o:p></p> <p \
class="MsoPlainText"><o:p>&nbsp;</o:p></p> <p class="MsoPlainText">The situation for \
interface libraries (header only) is different: CMake won't allow me to add any \
sources to the target, not even headers. As a result configure fails with an error. \
I'm pretty sure if I could add headers to interface  libraries then they will show up \
in Visual Studio with this target. So I think it's not a generator bug, but a \
short-coming of CMake itself.<o:p></o:p></p> <p \
class="MsoPlainText"><o:p>&nbsp;</o:p></p> <p \
class="MsoPlainText">Daniel<o:p></o:p></p> <p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black"><o:p>&nbsp;</o:p></span></p>
 <p class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Eric Noulard \
[mailto:eric.noulard@gmail.com] <br>
<b>Sent:</b> Donnerstag, 30. August 2018 14:40<br>
<b>To:</b> Daniel Eiband &lt;daniel.eiband@brainlab.com&gt;<br>
<b>Cc:</b> CMake Mailinglist &lt;cmake@cmake.org&gt;<br>
<b>Subject:</b> Re: [CMake] Specify extra files for display in \
IDE<o:p></o:p></span></p> <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
<div>
<div>
<p class="MsoNormal">Le&nbsp;jeu. 30 août 2018 à &nbsp;12:32, Daniel Eiband &lt;<a \
href="mailto:daniel.eiband@brainlab.com">daniel.eiband@brainlab.com</a>&gt; a \
écrit&nbsp;:<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-right:0cm"> <div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">Hi,</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">I'm \
currently migrating a code base from a proprietary MSBuild based generator to CMake \
3.11 which is shipped  with Visual Studio. There are two aspects to this \
task:</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">1) \
Integration of custom build steps</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">2) \
Presentation in the IDE</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">The \
first aspect of integrating all of our custom build steps as custom commands works \
really well. At one  point I use an object library to be able to use the object files \
as input to such a custom tool and to link a shared library. Both the object library \
and the shared library are from the programmers perspective one logical unit. The \
object library is just an  implementation detail. However, as for the second point, \
the source files are displayed with the object library target in the IDE while the \
shared library has no sources. This makes sense from the build targets point of view, \
but surprises the developers.</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">My \
approach is to hide all targets which are sort of implementation detail into a \
folder.&nbsp; To make this  work I would like to display the sources with the shared \
library which consumes the object files of the object library. Currently this seems \
to be impossible.</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">Another \
inconsistency I noticed regarding the second point is the following: I implemented \
header only libraries  as interface libraries in CMake. This works fine from the \
build perspective. Interface libraries however don't allow me to list sources, not \
even headers. As a result, the headers of this header only library are not displayed \
anywhere in the IDE. This is odd,  because in executable targets for example I can \
list all headers even if they don't contribute to the build process directly and they \
are displayed in the IDE. Using empty custom targets to present the header files \
works, but they are not displayed as C&#43;&#43;  libraries in Visual Studio any \
longer. This also litters the solution with lots of extra empty \
targets.</span><o:p></o:p></p> <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">&nbsp;</span><o:p></o:p></p>
 <p class="MsoNormal" \
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span \
style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black">I'm \
going to rephrase both described presentation problems into one more fundamental \
question, solutions  or workarounds for either of both presentation problems are of \
course welcome: Can I specify sources used for builds and files used for display in \
IDEs separately? I think they are two different things. For my use case it would also \
be sufficient to be able  to add extra files for display in IDEs to any \
target.</span><o:p></o:p></p> </div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">I'm afraid that your question may be generator-specific and I'm \
no sure Visual Studio generator behaves in the same way as others I'm \
using.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">I do very often add non source file (like README.md) to any \
targets (add_executable, add_library, add_custom_target) in order to make them \
editable in the IDE.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">Since those file are guessed as not being compilable they \
inherit the HEADER_FILE_ONLY&nbsp; (<a \
href="https://cmake.org/cmake/help/v3.11/prop_sf/HEADER_FILE_ONLY.html">https://cmake.org/cmake/help/v3.11/prop_sf/HEADER_FILE_ONLY.html</a>) \
automatically<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">and they show up in IDE just fine.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">My particular IDE being either qtcreator, vscode&#43;cmaketools \
or eclipse and this works well for those.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Moreover, in qtcreator (for example) header only libraries \
appear on their own with editable header file AND as subdir of every other targets \
their are used by. This subdir contains the headers.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">This is not the case with object libraries though \
:-(<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">Concerning the visual grouping you must already being using \
source_group (<a href="https://cmake.org/cmake/help/latest/command/source_group.html">https://cmake.org/cmake/help/latest/command/source_group.html</a>) \
source_group does not seems<o:p></o:p></p> </div>
<div>
<p class="MsoNormal">to have any effect in my favorite IDEs...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">In the end I don't know if there is currently any ways to do \
what you want.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">At least the &quot;never displayed&quot; header only library \
looks like a bug of the Visual Studio generator to me.<o:p></o:p></p> </div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Eric<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>



-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: \
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at \
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--===============2007005833==--



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic