diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 8c189e9288..2041b8816e 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -1484,5 +1484,6 @@ void QAbstractAnimation::updateDirection(QAbstractAnimation::Direction direction QT_END_NAMESPACE #include "moc_qabstractanimation.cpp" +#include "moc_qabstractanimation_p.cpp" #endif //QT_NO_ANIMATION diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 41fae69bb2..06d706b915 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -1106,3 +1106,7 @@ qint64 QFile::size() const } QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qfile.cpp" +#endif diff --git a/src/corelib/io/qfiledevice.cpp b/src/corelib/io/qfiledevice.cpp index ce9c8275ce..715dc7293a 100644 --- a/src/corelib/io/qfiledevice.cpp +++ b/src/corelib/io/qfiledevice.cpp @@ -739,3 +739,7 @@ bool QFileDevice::unmap(uchar *address) } QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qfiledevice.cpp" +#endif diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 612b3fa57c..ed597c415b 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -497,6 +497,7 @@ QStringList QFileSystemWatcher::files() const QT_END_NAMESPACE #include "moc_qfilesystemwatcher.cpp" +#include "moc_qfilesystemwatcher_p.cpp" #endif // QT_NO_FILESYSTEMWATCHER diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 5564bc7dca..3cfc6a254f 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -417,4 +417,6 @@ QString QInotifyFileSystemWatcherEngine::getPathFromID(int id) const QT_END_NAMESPACE +#include "moc_qfilesystemwatcher_inotify_p.cpp" + #endif // QT_NO_FILESYSTEMWATCHER diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index cbcb68e7d2..5bef8127f7 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -151,4 +151,7 @@ void QPollingFileSystemWatcherEngine::timeout() } QT_END_NAMESPACE + +#include "moc_qfilesystemwatcher_polling_p.cpp" + #endif // !QT_NO_FILESYSTEMWATCHER diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 41a4d7a1ba..80122eac5e 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -2059,3 +2059,7 @@ QDebug operator<<(QDebug debug, QIODevice::OpenMode modes) #endif QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qiodevice.cpp" +#endif diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index 61299b8aa8..beca6ccbf7 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -578,3 +578,4 @@ QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteD QT_END_NAMESPACE +#include "moc_qnoncontiguousbytedevice_p.cpp" diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp index d8166014db..0283c5f31f 100644 --- a/src/corelib/io/qsavefile.cpp +++ b/src/corelib/io/qsavefile.cpp @@ -412,4 +412,8 @@ bool QSaveFile::directWriteFallback() const QT_END_NAMESPACE +#ifndef QT_NO_QOBJECT +#include "moc_qsavefile.cpp" +#endif + #endif // QT_NO_TEMPORARYFILE diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 16dab38a60..d5460238ec 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -3513,4 +3513,8 @@ QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc r QT_END_NAMESPACE +#ifndef QT_BOOTSTRAPPED +#include "moc_qsettings.cpp" +#endif + #endif // QT_NO_SETTINGS diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 4cf3a3e9bd..f2368c3b23 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -645,4 +645,8 @@ bool QStandardPaths::isTestModeEnabled() QT_END_NAMESPACE +#ifndef QT_NO_QOBJECT +#include "moc_qstandardpaths.cpp" +#endif + #endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 7aae128796..8a99873fee 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -796,4 +796,6 @@ QT_END_NAMESPACE #endif // QT_NO_TEMPORARYFILE - +#ifndef QT_NO_QOBJECT +#include "moc_qtemporaryfile.cpp" +#endif diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 9b565bff9d..5144ac0ec9 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -3188,3 +3188,6 @@ QLocale QTextStream::locale() const QT_END_NAMESPACE +#ifndef QT_NO_QOBJECT +#include "moc_qtextstream_p.cpp" +#endif diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 0c87dd5659..c0737ffb36 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -3804,3 +3804,5 @@ void QAbstractItemModelPrivate::Persistent::insertMultiAtEnd(const QModelIndex& } QT_END_NAMESPACE + +#include "moc_qabstractitemmodel.cpp" diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index 0f7472aa5a..2b47d43469 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -328,4 +328,6 @@ Qt::DropActions QStringListModel::supportedDropActions() const QT_END_NAMESPACE +#include "moc_qstringlistmodel.cpp" + #endif // QT_NO_STRINGLISTMODEL diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index e94faa4587..d234949d14 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -521,3 +521,5 @@ bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, vo */ QT_END_NAMESPACE + +#include "moc_qabstracteventdispatcher.cpp" diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 0104ba0101..39e7c71a9c 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2914,3 +2914,7 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc */ QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qcoreapplication.cpp" +#endif diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 4efc38ac89..e90cd842ab 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -652,3 +652,5 @@ QDeferredDeleteEvent::~QDeferredDeleteEvent() */ QT_END_NAMESPACE + +#include "moc_qcoreevent.cpp" diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp index 8ca2ac1c39..8cefa7a118 100644 --- a/src/corelib/kernel/qeventdispatcher_glib.cpp +++ b/src/corelib/kernel/qeventdispatcher_glib.cpp @@ -611,3 +611,5 @@ QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate &dd, QObj } QT_END_NAMESPACE + +#include "moc_qeventdispatcher_glib_p.cpp" diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 802962d77d..a28f2e3f0a 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -553,3 +553,5 @@ void QEventDispatcherUNIX::flush() { } QT_END_NAMESPACE + +#include "moc_qeventdispatcher_unix_p.cpp" diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index e4b819d9d2..8974ff7709 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -441,3 +441,5 @@ QEventLoopLocker::~QEventLoopLocker() } QT_END_NAMESPACE + +#include "moc_qeventloop.cpp" diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index a550ca6ca1..73307e925a 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -678,3 +678,5 @@ void QMimeData::removeFormat(const QString &mimeType) } QT_END_NAMESPACE + +#include "moc_qmimedata.cpp" diff --git a/src/corelib/kernel/qobjectcleanuphandler.cpp b/src/corelib/kernel/qobjectcleanuphandler.cpp index f3d23c4b44..b6c62af4b3 100644 --- a/src/corelib/kernel/qobjectcleanuphandler.cpp +++ b/src/corelib/kernel/qobjectcleanuphandler.cpp @@ -145,3 +145,5 @@ void QObjectCleanupHandler::objectDestroyed(QObject *object) } QT_END_NAMESPACE + +#include "moc_qobjectcleanuphandler.cpp" diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index 29b3e87076..7f185ee9dc 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -598,3 +598,5 @@ QString QSharedMemory::errorString() const #endif // QT_NO_SHAREDMEMORY QT_END_NAMESPACE + +#include "moc_qsharedmemory.cpp" diff --git a/src/corelib/kernel/qsocketnotifier.cpp b/src/corelib/kernel/qsocketnotifier.cpp index 933eac19ab..2268cb83bb 100644 --- a/src/corelib/kernel/qsocketnotifier.cpp +++ b/src/corelib/kernel/qsocketnotifier.cpp @@ -270,3 +270,5 @@ bool QSocketNotifier::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qsocketnotifier.cpp" diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 0c314526cb..55f75ab17e 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -670,3 +670,4 @@ int QTimer::remainingTime() const QT_END_NAMESPACE #include "qtimer.moc" +#include "moc_qtimer.cpp" diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 04a5e7ed7a..2232e24a25 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -1143,4 +1143,6 @@ bool QTranslator::isEmpty() const QT_END_NAMESPACE +#include "moc_qtranslator.cpp" + #endif // QT_NO_TRANSLATION diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index 21f1007d5b..40000e7b24 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -346,4 +346,6 @@ int QFactoryLoader::indexOf(const QString &needle) const QT_END_NAMESPACE +#include "moc_qfactoryloader_p.cpp" + #endif // QT_NO_QOBJECT diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index 6421e7c5d8..3d04d0802d 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -1129,3 +1129,5 @@ bool qt_debug_component() } QT_END_NAMESPACE + +#include "moc_qlibrary.cpp" diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index dbd3bee556..aab00cc7eb 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -479,3 +479,4 @@ QJsonObject QStaticPlugin::metaData() const QT_END_NAMESPACE +#include "moc_qpluginloader.cpp" diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp index 13bf41faa9..1a9ad4601d 100644 --- a/src/corelib/statemachine/qabstractstate.cpp +++ b/src/corelib/statemachine/qabstractstate.cpp @@ -234,3 +234,5 @@ bool QAbstractState::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qabstractstate.cpp" diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp index 8c30d5f11c..53c713d6a8 100644 --- a/src/corelib/statemachine/qabstracttransition.cpp +++ b/src/corelib/statemachine/qabstracttransition.cpp @@ -431,3 +431,5 @@ bool QAbstractTransition::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qabstracttransition.cpp" diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp index cd0cfe2f85..a90f147773 100644 --- a/src/corelib/statemachine/qeventtransition.cpp +++ b/src/corelib/statemachine/qeventtransition.cpp @@ -252,3 +252,5 @@ bool QEventTransition::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qeventtransition.cpp" diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp index bef9fc4239..d8bfd30974 100644 --- a/src/corelib/statemachine/qfinalstate.cpp +++ b/src/corelib/statemachine/qfinalstate.cpp @@ -137,3 +137,5 @@ bool QFinalState::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qfinalstate.cpp" diff --git a/src/corelib/statemachine/qhistorystate.cpp b/src/corelib/statemachine/qhistorystate.cpp index b1c5a92d00..a179d7c75b 100644 --- a/src/corelib/statemachine/qhistorystate.cpp +++ b/src/corelib/statemachine/qhistorystate.cpp @@ -310,3 +310,6 @@ bool QHistoryState::event(QEvent *e) */ QT_END_NAMESPACE + +#include "moc_qhistorystate.cpp" +#include "moc_qhistorystate_p.cpp" diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp index 3b219bda53..c05b4617b2 100644 --- a/src/corelib/statemachine/qsignaltransition.cpp +++ b/src/corelib/statemachine/qsignaltransition.cpp @@ -284,3 +284,5 @@ void QSignalTransitionPrivate::callOnTransition(QEvent *e) QT_END_NAMESPACE + +#include "moc_qsignaltransition.cpp" diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp index 48456424cf..76dcbf784b 100644 --- a/src/corelib/statemachine/qstate.cpp +++ b/src/corelib/statemachine/qstate.cpp @@ -599,3 +599,5 @@ bool QState::event(QEvent *e) */ QT_END_NAMESPACE + +#include "moc_qstate.cpp" diff --git a/src/corelib/thread/qfuturewatcher.cpp b/src/corelib/thread/qfuturewatcher.cpp index aa6f00c317..d2ec18850f 100644 --- a/src/corelib/thread/qfuturewatcher.cpp +++ b/src/corelib/thread/qfuturewatcher.cpp @@ -592,4 +592,6 @@ void QFutureWatcherBasePrivate::sendCallOutEvent(QFutureCallOutEvent *event) QT_END_NAMESPACE +#include "moc_qfuturewatcher.cpp" + #endif // QT_NO_QFUTURE diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 0828400733..996a1df9a0 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -901,3 +901,5 @@ QDaemonThread::~QDaemonThread() } QT_END_NAMESPACE + +#include "moc_qthread.cpp" diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index e45aaec103..f3ce1f258f 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -679,4 +679,6 @@ void QThreadPool::cancel(QRunnable *runnable) QT_END_NAMESPACE +#include "moc_qthreadpool.cpp" + #endif diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp index 963a91b9a9..5410adc737 100644 --- a/src/corelib/tools/qcryptographichash.cpp +++ b/src/corelib/tools/qcryptographichash.cpp @@ -494,3 +494,7 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method) } QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qcryptographichash.cpp" +#endif diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 4b5f5e7830..03bb1a1411 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -1501,3 +1501,5 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing) #endif // QT_NO_DATASTREAM QT_END_NAMESPACE + +#include "moc_qeasingcurve.cpp" diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 697e0062dd..5eb45f3b2c 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3665,3 +3665,7 @@ QDebug operator<<(QDebug dbg, const QLocale &l) } #endif QT_END_NAMESPACE + +#ifndef QT_NO_QOBJECT +#include "moc_qlocale.cpp" +#endif diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index adbc2900e3..e70e7f8e16 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -784,3 +784,5 @@ void QTimeLine::timerEvent(QTimerEvent *event) } QT_END_NAMESPACE + +#include "moc_qtimeline.cpp" diff --git a/util/includemocs/includemocs.pl b/util/includemocs/includemocs.pl new file mode 100755 index 0000000000..ce04d961d8 --- /dev/null +++ b/util/includemocs/includemocs.pl @@ -0,0 +1,138 @@ +#!/usr/bin/perl +############################################################################# +## +## Copyright (C) 2017 Intel Corporation. +## Contact: https://www.qt.io/licensing/ +## +## This file is the build configuration utility of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# +use strict; + +MAKEFILE: while ($_ = shift @ARGV) { + chdir($ENV{PWD}); + open MAKEFILE, "<", $_ + or die("Could not open Makefile"); + print "includemocs.pl: Processing $_\n"; + + my $srcdir; + my $sourcesline; + + # Find "SOURCES =" line + while () { + $srcdir = $1 if m,^# Project:\s+(.*)/[^/]+.pro,; + if (/^# Template:\s+(\w+)/) { + next MAKEFILE if $1 eq "subdirs"; + } + if (/^SOURCES\s*=\s*(.*)/) { + $sourcesline = $1; + last; + } + } + if ($sourcesline =~ s/\s+\\//) { + # continuation + while () { + chomp; + /^\s*([^ ]+)/; + $sourcesline .= " $1"; + last unless m/\\$/; + } + } + close MAKEFILE; + + # Now parse the sources + my @mocs; + my @sources; + for (split(/ /, $sourcesline)) { + if (/\.moc\/(moc_.*\.cpp)/) { + push @mocs, $1; + } elsif (/^\.(rcc|uic)/) { + # ignore + } else { + push @sources, $_; + } + } + + chdir($srcdir) or die("Where's $srcdir? $!"); + for my $moc (@mocs) { + my $include = "#include \"$moc\"\n"; + + # Find a corresponding .cpp file to host the new #include + my $basename = ($moc =~ s/^moc_//r); + $basename =~ s/\.[^.]+//; + my @candidates = grep { m,\Q/$basename.\E, } @sources; + + if (scalar @candidates == 0) { + # Try without a _p suffix + $basename =~ s/_p$//; + @candidates = grep { m,\Q/$basename.\E, } @sources; + } + if (scalar @candidates == 0) { + print STDERR "includemocs.pl: Cannot find .cpp file for $moc\n"; + next; + } + + my $cpp = $candidates[0]; + undef @candidates; + + #print "$moc -> $cpp\n"; + open CPP, "<", $cpp + or die("Cannot open source $cpp: $!"); + + my @lines; + while () { + push @lines, $_; + next unless defined($include); + + # Print the new include next to a pre-existing moc include + if (/#include \"moc_/ || /#include ".*\.moc"/) { + push @lines, $include; + undef $include; + } + } + close CPP; + + if (defined($include)) { + # Try to insert the new #include between QT_END_NAMESPACE and any #endif lines + my $n = 0; + my $extrablank = ""; + while (defined($include)) { + --$n; + $_ = $lines[$n]; + if (/^#endif/) { + $extrablank = "\n"; + next; + } + + $_ .= "\n" unless /^$/; + splice @lines, $n, 1, ($_, $include, $extrablank); + undef $include; + } + } + + # Write the file again + open CPP, ">", $cpp + or die("Cannot open source $cpp for writing: $!"); + map { print CPP $_; } @lines; + close CPP; + } +}