<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi all,</p>
<p>let me introduce my finding we probably want for all KDE's
CMake-based projects eventually.</p>
<p>The idea is, wherever we add a source files to a project, we
should also add a headers alongside: <br>
</p>
<p><span id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text">
<pre><code class="hljs language-scss"><span class="hljs-built_in">add_library</span>(my_lib [STATIC|SHARED|MODULE] [source.cpp source.h ...])
<span class="hljs-built_in">add_executable</span>(my_exe [source.cpp source.h])
<span class="hljs-built_in">target_sources</span>(my_target <INTERFACE|PUBLIC|PRIVATE> [source.cpp source.h])</code>
</pre>
That has zero impact for building the project, as the headers do
not get compiled </span><span id="hs_cos_wrapper_post_body"
class="hs_cos_wrapper hs_cos_wrapper_meta_field
hs_cos_wrapper_type_rich_text" style=""
data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text"><span id="hs_cos_wrapper_post_body"
class="hs_cos_wrapper hs_cos_wrapper_meta_field
hs_cos_wrapper_type_rich_text" style=""
data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text">directly</span>,</span><span
id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text"><br>
but declaring headers in a such way helps IDEs (Qt Creator,
etc.) be aware of them and work with them properly.<br>
</span></p>
<p><span id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text">For now, <a moz-do-not-send="true"
href="https://invent.kde.org/plasma/kwin/-/merge_requests/3400">KWin MR</a>
exists which adds the most essential headers, but even to fully
cover KWin alone that would probably require some sort of
automation as it contains ~138 CMakeLists.txt files.<br>
</span></p>
<p><span id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text">Until that automation method is not
found, I hope it's OK to add the headers manually or <a
moz-do-not-send="true"
href="https://invent.kde.org/plasma/kwin/-/merge_requests/3400#note_593030">semi-automated</a>.</span></p>
<p><span id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text"><br>
</span></p>
<div class="md">
<p data-sourcepos="1:1-1:86" dir="auto">Hereby is the MR message
with all the details:<br>
</p>
<p data-sourcepos="16:1-16:30" dir="auto"><cite>
<blockquote type="cite">
<p data-sourcepos="1:1-1:86" dir="auto">Nowadays, it's
generally recommended to add headers alongside with
sources in CMake:</p>
<blockquote type="cite">
<blockquote data-sourcepos="2:1-2:543" dir="auto">
<p data-sourcepos="2:3-2:543">note that .h header files
were specified as sources too, not just the .cpp
implementation files. <strong>Headers listed as
sources don’t get compiled directly on their own,
but the effect of adding them is for the benefit of
IDE generators</strong> like Visual Studio, Xcode,
Qt Creator, etc. This causes those headers to be
listed in the project’s file list within the IDE, even
if no source file refers to it via #include. This can
make those headers easier to find during development
and potentially aid things like refactoring
functionality, etc.</p>
</blockquote>
<p data-sourcepos="4:1-4:81" dir="auto"><a
href="https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/"
rel="nofollow noreferrer noopener" target="_blank"
class="moz-txt-link-freetext"></a></p>
</blockquote>
<a
href="https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/"
rel="nofollow noreferrer noopener" target="_blank"
class="moz-txt-link-freetext">https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/</a>
<p data-sourcepos="7:1-7:42" dir="auto">Recent Qt Creator
depends on it heavily:</p>
<blockquote data-sourcepos="8:1-11:72" dir="auto">
<blockquote type="cite"><cite>
<blockquote data-sourcepos="8:1-11:72" dir="auto">
<p data-sourcepos="8:3-8:83">This means that the
header files will get the same treatment as the
source files.</p>
<ul data-sourcepos="9:3-11:72">
<li data-sourcepos="9:3-9:56">clang-tidy and clazy
will be able to analyze them</li>
<li data-sourcepos="10:3-10:57">The TODO plugin
can find the TODOs in header files</li>
<li data-sourcepos="11:3-11:72">The Test plugin
can find the Google Tests defined in header
files</li>
</ul>
</blockquote>
</cite></blockquote>
</blockquote>
<p data-sourcepos="13:1-14:122" dir="auto"><a
href="https://www.qt.io/blog/qt-creator-6-cmake-update"
rel="nofollow noreferrer noopener" target="_blank"
class="moz-txt-link-freetext">https://www.qt.io/blog/qt-creator-6-cmake-update</a><br>
In my personal observations it should also help with
source/header jumps as it sometimes doesn't work reliably
otherwise.</p>
<p data-sourcepos="16:1-16:30" dir="auto">Other IDEs should
benefit too.</p>
</blockquote>
</cite></p>
</div>
<p><span id="hs_cos_wrapper_post_body" class="hs_cos_wrapper
hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text"
style="" data-hs-cos-general-type="meta_field"
data-hs-cos-type="rich_text"></span></p>
</body>
</html>