Reputation: 9014
I have CMake-based Qt5 project with precompiled headers (Common.h). CMAKE_AUTOMOC
is OFF. I call qt5_wrap_cpp
to generate moc_*.cpp files.
How I can configure moc, so it will add a custom include into generated moc_*.cpp files? (#include "Common.h")
Currently I use /FI compiler flag to force include of Common.h, but it is not friendly to code autocomplete tool (ReSharper).
"Common.h":
#ifdef QT_CORE_LIB
# include <QtCore>
#endif
#ifdef QT_GUI_LIB
# include <QtGui>
#endif
#ifdef QT_WIDGETS_LIB
# include <QtWidgets>
#endif
#ifdef QT_MULTIMEDIA_LIB
# include <QtMultimedia>
#endif
#ifdef QT_NETWORK_LIB
# include <QtNetwork>
#endif
#ifdef QT_XML_LIB
# include <QtXml>
#endif
#ifdef QT_QML_LIB
# include <QtQml>
#endif
#ifdef QT_QUICK_LIB
# include <QtQuick>
#endif
#ifdef QT_SQL_LIB
# include <QtSql>
#endif
Upvotes: 1
Views: 1481
Reputation: 9014
Problem is not related to CMake.
I created an issue in R++ bugtracker: RSCPP-14920
Upvotes: 0
Reputation: 98485
You should never have to do that.
Moc can generate code from either an interface file (.h
) or an implementation file (.cpp
). In the first case, the interface itself is included at the beginning of the moc output. The #include "Common.h"
belongs in your header, not in moc output. In the latter case, the moc output must be included by you at the end of the implementation file. And again, the #include "Common.h"
belongs somewhere in your implementation file.
If you start thinking of what might necessitate inclusion of a header in moc output generate from an interface file, there's only one conclusion: you only need it if the users of your interface need that inclusion anyway. It is never moc's job to add such an inclusion for you.
Upvotes: 2