Autogen: option to have automoc not add a mocs_compilation.cpp file
Target group
There are projects which enjoy CMake's automoc for automatically finding all files that need to have moc files generated for them, yet still desire to explicitly include/source all such moc files in their code (see below for motivation).
During development on and builds of such projects, if missing out an otherwise needed explicit moc include, they are expecting the build to fail hard, like missing out any other needed file include/sourcing. Examples are CI build servers or similar QA builds with strict non-tolerant policy checking.
The projects also fancy the build log to not be cluttered with lines about the thus unused mocs_compilation.cpp file, as well as having the generated build system otherwise clear from any references and resulting complexity as well as build targets.
Proposed solution
For such projects it would be welcome to have an option for no mocs_compilation.cpp file at all being used in the build.
- There would be a new target property named
AUTOMOC_USE_MOCS_COMPILATION
(or similar, whatever matches CMake naming pattern and makes a sane name, no own good idea here yet). - The default would be
ON
to be behaviour-backward-compatible (perhaps could change later as part of some CMake policy). - As usual, default set by a respective global CMake var
CMAKE_AUTOMOC_USE_MOCS_COMPILATION
.
This idea had been before proposed on the Qt Development mailing list, with some on-list & off-list thumbs-up: https://lists.qt-project.org/pipermail/development/2023-July/044157.html
Motivation
While it is convenient as developer not to have to care about adding any needed moc includes for moc files generated for headers (other than for source files, where there is no way around), this convenience is found to come at some cost:
- increased full build time in general
- increased incremental build time in general
- missing out some compiler sanity checks
- missing out some compiler optimizations
See https://frinring.wordpress.com/2023/06/28/include-also-moc-files-of-headers for some closer look at that, including some numbers on seen build time changes.
For those reasons also the Qt developers themselves now and then run respective scripts (kept in their sources here: https://code.qt.io/cgit/qt/qtbase.git/tree/util/includemocs) over the Qt sources, to ensure more explicit moc includes are done. See the resulting "QtFoo: includemocs" commits as found in this search: https://code.qt.io/cgit/qt/qtbase.git/log/?qt=grep&q=includemocs