[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-buildsystem
Subject:    Re: CMake dependency scanning for .moc files
From:       Matthias Kretz <kretz () kde ! org>
Date:       2008-04-17 9:46:59
Message-ID: 200804171147.03842.kretz () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Thursday 17 April 2008, Matthias Kretz wrote:
> run kde4automoc unconditionally for all targets

With a patch to kde4automoc.cpp it's not too bad. Please try the attached 
patch. And if you think this is the way to go then let me know how to 
unconditionally run automoc without that touch hack.

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz@gmx.net, kretz@kde.org,
Matthias.Kretz@urz.uni-heidelberg.de

["unconditional-automoc.patch" (text/x-diff)]

Index: automoc/kde4automoc.cpp
===================================================================
--- automoc/kde4automoc.cpp	(revision 797272)
+++ automoc/kde4automoc.cpp	(working copy)
@@ -38,7 +38,7 @@
         bool run();
 
     private:
-        void generateMoc(const QString &sourceFile, const QString &mocFileName);
+        bool generateMoc(const QString &sourceFile, const QString &mocFileName);
         void waitForProcesses();
         void usage(const QString &);
         void echoColor(const QString &msg)
@@ -66,6 +66,7 @@
         };
         QQueue<Process> processes;
         bool failed;
+        bool automocCppChanged;
 };
 
 void AutoMoc::usage(const QString &path)
@@ -84,7 +85,8 @@
 }
 
 AutoMoc::AutoMoc()
-    : verbose(!qgetenv("VERBOSE").isEmpty()), cerr(stderr), cout(stdout), \
failed(false) +    : verbose(!qgetenv("VERBOSE").isEmpty()), cerr(stderr), \
cout(stdout), failed(false), +    automocCppChanged(false)
 {
     const QByteArray colorEnv = qgetenv("COLOR");
     cmakeEchoColorArgs << "-E" << "cmake_echo_color" << QString("--switch=") + \
colorEnv << "--blue" @@ -256,7 +258,9 @@
         end = notIncludedMocs.constEnd();
         it = notIncludedMocs.constBegin();
         for (; it != end; ++it) {
-            generateMoc(it.key(), it.value());
+            if (generateMoc(it.key(), it.value())) {
+                automocCppChanged = true;
+            }
             outStream << "#include \"" << it.value() << "\"\n";
         }
     }
@@ -272,7 +276,19 @@
     }
     outStream.flush();
 
-    // source file that includes all remaining moc files
+    if (!automocCppChanged) {
+        // compare contents of the _automoc.cpp file
+        outfile.open(QIODevice::ReadOnly | QIODevice::Text);
+        const QByteArray oldContents = outfile.readAll();
+        outfile.close();
+        if (oldContents == automocSource) {
+            // nothing changed: don't touch the _automoc.cpp file
+            return true;
+        }
+    }
+    // either the contents of the _automoc.cpp file or one of the mocs included by \
it have changed +
+    // source file that includes all remaining moc files (_automoc.cpp file)
     outfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
     outfile.write(automocSource);
     outfile.close();
@@ -301,7 +317,7 @@
     }
 }
 
-void AutoMoc::generateMoc(const QString &sourceFile, const QString &mocFileName)
+bool AutoMoc::generateMoc(const QString &sourceFile, const QString &mocFileName)
 {
     //qDebug() << Q_FUNC_INFO << sourceFile << mocFileName;
     const QString mocFilePath = builddir + mocFileName;
@@ -332,13 +348,15 @@
         args << "-o" << mocFilePath << sourceFile;
         //qDebug() << "executing: " << mocExe << args;
         mocProc->start(mocExe, args, QIODevice::NotOpen);
-        if (mocProc->waitForStarted())
+        if (mocProc->waitForStarted()) {
             processes.enqueue(Process(mocProc, mocFilePath));
-        else {
+            return true;
+        } else {
             cerr << "kde4automoc: process for " << mocFilePath << "failed to start: \
"   << mocProc->errorString() << endl;
             failed = true;
             delete mocProc;
         }
     }
+    return false;
 }
Index: modules/KDE4Macros.cmake
===================================================================
--- modules/KDE4Macros.cmake	(revision 797272)
+++ modules/KDE4Macros.cmake	(working copy)
@@ -226,7 +226,10 @@
          ${CMAKE_CURRENT_SOURCE_DIR}
          ${CMAKE_CURRENT_BINARY_DIR}
          ${QT_MOC_EXECUTABLE}
+         COMMAND touch ${_automoc_source}.files
          DEPENDS ${${_SRCS}} ${_moc_headers} ${_automoc_source}.files \
${_KDE4_AUTOMOC_EXECUTABLE_DEP} +         COMMENT "running automoc for \
${_target_NAME}" +         VERBATIM
          )
       # the OBJECT_DEPENDS is only necessary when a new moc file has to be generated \
                that is included in a source file
       # problem: the whole target is recompiled when the automoc.cpp file is touched


["signature.asc" (application/pgp-signature)]

_______________________________________________
Kde-buildsystem mailing list
Kde-buildsystem@kde.org
https://mail.kde.org/mailman/listinfo/kde-buildsystem


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic