<table><tr><td style="">kossebau added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D9334" rel="noreferrer">View Revision</a></tr></table><br /><div><div>

<blockquote style="border-left: 3px solid #8C98B8;
          color: #6B748C;
          font-style: italic;
          margin: 4px 0 12px 0;
          padding: 8px 12px;
          background-color: #F8F9FC;">
<div style="font-style: normal;
          padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D9334#180540" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: line-through;" rel="noreferrer">D9334#180540</a>, <a href="https://phabricator.kde.org/p/ngraham/" style="
              border-color: #f1f7ff;
              color: #19558d;
              background-color: #f1f7ff;
                border: 1px solid transparent;
                border-radius: 3px;
                font-weight: bold;
                padding: 0 4px;" rel="noreferrer">@ngraham</a> wrote:</div>
<div style="margin: 0;
          padding: 0;
          border: 0;
          color: rgb(107, 116, 140);"><p>We have a report in the wild that this broke compiling KWin with CMake 3.10.x for someone on Gentoo: <a href="https://bugs.kde.org/show_bug.cgi?id=387983" class="remarkup-link" target="_blank" rel="noreferrer">https://bugs.kde.org/show_bug.cgi?id=387983</a></p></div>
</blockquote>

<p>Actually did it uncover some issue in kwinscripts code. Which had both a <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY_DECLARATION(KcmKWinScriptsFactory)</tt> (in a file which also had a <tt style="background: #ebebeb; font-size: 13px;">#include "module.moc"</tt>) and a <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY(KcmKWinScriptsFactory [...])</tt> (in a file which had no such <tt style="background: #ebebeb; font-size: 13px;">#include "main.moc"</tt>). Remember that <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY</tt> covers both definition and declaration, so we had some duplicated declaration where only one is needed.<br />
Milian fixed that today by dropping the duplicated K_PLUGIN_FACTORY_DECLARATION and adding a main.moc include (actually could also have removed the module.moc, no longer needed).</p>

<blockquote style="border-left: 3px solid #8C98B8;
          color: #6B748C;
          font-style: italic;
          margin: 4px 0 12px 0;
          padding: 8px 12px;
          background-color: #F8F9FC;">
<div style="font-style: normal;
          padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D9334#180830" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: line-through;" rel="noreferrer">D9334#180830</a>, <a href="https://phabricator.kde.org/p/mpyne/" style="
              border-color: #f1f7ff;
              color: #19558d;
              background-color: #f1f7ff;
                border: 1px solid transparent;
                border-radius: 3px;
                font-weight: bold;
                padding: 0 4px;" rel="noreferrer">@mpyne</a> wrote:</div>
<div style="margin: 0;
          padding: 0;
          border: 0;
          color: rgb(107, 116, 140);"><p>In fact this appears to force files containing <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY*</tt> into being evaluated by CMake's AUTOMOC (other warning fixes removed files from consideration by CMake AUTOMOC).</p>

<p>CMake itself appears to have had an interface change for AUTOMOC between 3.8 and 3.9+.</p>

<p>In particular, <a href="https://cmake.org/cmake/help/v3.8/manual/cmake-qt.7.html#automoc" class="remarkup-link" target="_blank" rel="noreferrer">https://cmake.org/cmake/help/v3.8/manual/cmake-qt.7.html#automoc</a></p>

<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>If the macro is found in a C++ implementation file, the moc output will be put into a file named according to <basename>.moc, following the Qt conventions. The moc file may be included by the user in the C++ implementation file with a preprocessor #include. If it is not so included, it will be added to a separate file which is compiled into the target.</p></blockquote>

<p>vs. <a href="https://cmake.org/cmake/help/v3.9/manual/cmake-qt.7.html#automoc" class="remarkup-link" target="_blank" rel="noreferrer">https://cmake.org/cmake/help/v3.9/manual/cmake-qt.7.html#automoc</a></p>

<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>If the macro is found in a C++ implementation file, the moc output will be put into a file named according to <basename>.moc, following the Qt conventions. The <basename>.moc must be included by the user in the C++ implementation file with a preprocessor #include.</p></blockquote></div>
</blockquote>

<p>Not sure if this is a behavioural change, or rather a fix in the docu: unless I missed something, the code in the moc file has to see (or rather the compiler compiling it) the declaration of the class with the Q_OBJECT macro, as it contains the definition of declarations done by the Q_OBJECT macro.<br />
And if the macro is used for a declaration in a cpp file, the moc file cannot include the cpp file (otherwise the cpp definition content would be compiled 2x), so it has to be rather the cpp file which explicitely includes the moc file (after the code with the class with the Q_OBJECT declaration).</p>

<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>I'm not sure what the right answer is, or whether <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY</tt> needs its output to be run through <tt style="background: #ebebeb; font-size: 13px;">moc</tt> but if we do need <tt style="background: #ebebeb; font-size: 13px;">moc</tt> to run then I'm not sure what's the best way to address the CMake behavior change for .cpp files.</p></blockquote>

<p>Now, <tt style="background: #ebebeb; font-size: 13px;">K_PLUGIN_FACTORY</tt> includes both the declaration (with the Q_OBJECT macro) and the definition. Which is also why it needs to be into a cpp file (unless the header is included only once). And moc needs to run the file which has K_PLUGIN_FACTORY, as it needs to create the implementation as declared from the contained Q_OBJECT macro. And put the generated code into a file. Which itself needs to be then pulled into the very cpp file with the K_PLUGIN_FACTORY,, due to the need to see the declaration, as said above.</p>

<p>So IMHO things are okayish as they are now and should not have really changed, besides just being less tolerant to doubled class declaration code as in kwinscripts. Which itself is questionable.</p>

<p>automoc in the end will stay a poor beast. It is run before the buildsystem has been created and dependencies are known, yet has to have an idea how to parse the code (despite include dirs yet unknown) to find out what classes to generate code for and how to add to the build (automoc.cpp files or the explicitly included files). The day will be great when moc no longer is needed :)</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R244 KCoreAddons</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D9334" rel="noreferrer">https://phabricator.kde.org/D9334</a></div></div><br /><div><strong>To: </strong>mlaurent, dfaure<br /><strong>Cc: </strong>kossebau, mpyne, ngraham, Frameworks<br /></div>