[Cmake-commits] CMake branch, next, updated. v2.8.6-1614-g94a04b3

Alexander Neundorf neundorf at kde.org
Sat Oct 22 13:46:41 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  94a04b36bb45a36d441dcb384721ba2ff5349c7d (commit)
       via  ea8ac9f5dc2eab7b263a18eee5db75aedd31e26a (commit)
       via  56aa6ffae75dd2567d2041147774bb1a9a3a1bdf (commit)
      from  e18f86692b9a70fc8b405ae4eb8cb46302bac960 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94a04b36bb45a36d441dcb384721ba2ff5349c7d
commit 94a04b36bb45a36d441dcb384721ba2ff5349c7d
Merge: e18f866 ea8ac9f
Author:     Alexander Neundorf <neundorf at kde.org>
AuthorDate: Sat Oct 22 13:46:22 2011 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sat Oct 22 13:46:22 2011 -0400

    Merge topic 'AutomocFindQ_OBJECTAlwaysInHeader' into next
    
    ea8ac9f Add copyright notices
    56aa6ff automoc:run moc on the header if the source file contains include "foo.moc"


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ea8ac9f5dc2eab7b263a18eee5db75aedd31e26a
commit ea8ac9f5dc2eab7b263a18eee5db75aedd31e26a
Author:     Alex Neundorf <neundorf at kde.org>
AuthorDate: Sat Oct 22 19:43:34 2011 +0200
Commit:     Alex Neundorf <neundorf at kde.org>
CommitDate: Sat Oct 22 19:43:34 2011 +0200

    Add copyright notices
    
    Alex

diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index 7e7f04f..edf1d57 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -1,3 +1,16 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2011 Kitware, Inc.
+  Copyright 2011 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
 #include "cmGlobalGenerator.h"
 #include "cmLocalGenerator.h"
 #include "cmMakefile.h"
diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h
index 8fb790a..c3550a4 100644
--- a/Source/cmQtAutomoc.h
+++ b/Source/cmQtAutomoc.h
@@ -1,3 +1,16 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2011 Kitware, Inc.
+  Copyright 2011 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
 #ifndef cmQtAutomoc_h
 #define cmQtAutomoc_h
 
diff --git a/Tests/QtAutomoc/foo.cpp b/Tests/QtAutomoc/foo.cpp
index a7a4783..699ba09 100644
--- a/Tests/QtAutomoc/foo.cpp
+++ b/Tests/QtAutomoc/foo.cpp
@@ -1,3 +1,16 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2011 Kitware, Inc.
+  Copyright 2011 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
 #include "foo.h"
 
 #include <stdio.h>
diff --git a/Tests/QtAutomoc/foo.h b/Tests/QtAutomoc/foo.h
index 7323ff3..32d4c8d 100644
--- a/Tests/QtAutomoc/foo.h
+++ b/Tests/QtAutomoc/foo.h
@@ -1,3 +1,16 @@
+/*============================================================================
+  CMake - Cross Platform Makefile Generator
+  Copyright 2004-2011 Kitware, Inc.
+  Copyright 2011 Alexander Neundorf (neundorf at kde.org)
+
+  Distributed under the OSI-approved BSD License (the "License");
+  see accompanying file Copyright.txt for details.
+
+  This software is distributed WITHOUT ANY WARRANTY; without even the
+  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the License for more information.
+============================================================================*/
+
 #ifndef FOO_H
 #define FOO_H
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=56aa6ffae75dd2567d2041147774bb1a9a3a1bdf
commit 56aa6ffae75dd2567d2041147774bb1a9a3a1bdf
Author:     Alex Neundorf <neundorf at kde.org>
AuthorDate: Sat Oct 22 19:38:39 2011 +0200
Commit:     Alex Neundorf <neundorf at kde.org>
CommitDate: Sat Oct 22 19:38:39 2011 +0200

    automoc:run moc on the header if the source file contains include "foo.moc"
    
    This fixes #12533.
    Before automoc did not check the header if the source file contained a
    statement, now it does.
    Additionally, moc is now only run on explicitely listed headers which
    contain a Q_OBJECT macro.
    
    Alex

diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index abda47e..7e7f04f 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -377,9 +377,8 @@ bool cmQtAutomoc::RunAutomocQt4()
 
   // key = moc source filepath, value = moc output filepath
   std::map<std::string, std::string> includedMocs;
-  // key = moc source filepath, value = moc output filename
-  std::map<std::string, std::string> notIncludedMocs;
-
+  // collect all headers which may need to be mocced
+  std::set<std::string> headerFiles;
 
   std::vector<std::string> sourceFiles;
   cmSystemTools::ExpandListArgument(this->Sources, sourceFiles);
@@ -393,34 +392,22 @@ bool cmQtAutomoc::RunAutomocQt4()
       {
       std::cout << "AUTOMOC: Checking " << absFilename << std::endl;
       }
-    this->ParseCppFile(absFilename, includedMocs, notIncludedMocs);
+    this->ParseCppFile(absFilename, includedMocs, headerFiles);
     }
 
-  std::vector<std::string> headerFiles;
-  cmSystemTools::ExpandListArgument(this->Headers, headerFiles);
-  for (std::vector<std::string>::const_iterator it = headerFiles.begin();
-       it != headerFiles.end();
+  std::vector<std::string> headerFilesVec;
+  cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec);
+  for (std::vector<std::string>::const_iterator it = headerFilesVec.begin();
+       it != headerFilesVec.end();
        ++it)
     {
-    const std::string &absFilename = *it;
-    if (this->Verbose)
-      {
-      std::cout << "AUTOMOC: Checking " << absFilename << std::endl;
-      }
-    if (includedMocs.find(absFilename) == includedMocs.end()
-              && notIncludedMocs.find(absFilename) == notIncludedMocs.end())
-      {
-      // if this header is not getting processed yet and is explicitly
-      // mentioned for the automoc the moc is run unconditionally on the
-      // header and the resulting file is included in the _automoc.cpp file
-      // (unless there's a .cpp file later on that includes the moc from
-      // this header)
-      const std::string currentMoc = "moc_" + cmsys::SystemTools::
-                         GetFilenameWithoutLastExtension(absFilename) + ".cpp";
-      notIncludedMocs[absFilename] = currentMoc;
-      }
+    headerFiles.insert(*it);
     }
 
+  // key = moc source filepath, value = moc output filename
+  std::map<std::string, std::string> notIncludedMocs;
+  this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs);
+
   // run moc on all the moc's that are #included in source files
   for(std::map<std::string, std::string>::const_iterator
                                                      it = includedMocs.begin();
@@ -487,7 +474,7 @@ bool cmQtAutomoc::RunAutomocQt4()
 
 void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
                            std::map<std::string, std::string>& includedMocs,
-                           std::map<std::string, std::string>& notIncludedMocs)
+                           std::set<std::string>& absHeaders)
 {
   cmsys::RegularExpression mocIncludeRegExp(
               "[\n][ \t]*#[ \t]*include[ \t]+"
@@ -520,52 +507,7 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
                    cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
 
   std::string::size_type matchOffset = 0;
-  if (!mocIncludeRegExp.find(contentsString.c_str()))
-    {
-    // no moc #include, look whether we need to create a moc from
-    // the .h nevertheless
-    const std::string basename =
-              cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
-    for(std::list<std::string>::const_iterator ext = headerExtensions.begin();
-        ext != headerExtensions.end();
-        ++ext)
-      {
-      const std::string headername = absPath + basename + (*ext);
-      if (cmsys::SystemTools::FileExists(headername.c_str())
-              && includedMocs.find(headername) == includedMocs.end()
-              && notIncludedMocs.find(headername) == notIncludedMocs.end())
-        {
-        const std::string currentMoc = "moc_" + basename + ".cpp";
-        const std::string contents = this->ReadAll(headername);
-        if (qObjectRegExp.find(contents))
-          {
-          //std::cout << "header contains Q_OBJECT macro";
-          notIncludedMocs[headername] = currentMoc;
-          }
-        break;
-        }
-      }
-    for(std::list<std::string>::const_iterator ext = headerExtensions.begin();
-        ext != headerExtensions.end();
-        ++ext)
-      {
-      const std::string privateHeaderName = absPath+basename+"_p"+(*ext);
-      if (cmsys::SystemTools::FileExists(privateHeaderName.c_str())
-          && includedMocs.find(privateHeaderName) == includedMocs.end()
-          && notIncludedMocs.find(privateHeaderName) == notIncludedMocs.end())
-        {
-        const std::string currentMoc = "moc_" + basename + "_p.cpp";
-        const std::string contents = this->ReadAll(privateHeaderName);
-        if (qObjectRegExp.find(contents))
-          {
-          //std::cout << "header contains Q_OBJECT macro";
-          notIncludedMocs[privateHeaderName] = currentMoc;
-          }
-        break;
-        }
-      }
-    }
-  else
+  if (mocIncludeRegExp.find(contentsString.c_str()))
     {
     // for every moc include in the file
     do
@@ -604,7 +546,6 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
             {
             headerFound = true;
             includedMocs[sourceFilePath] = currentMoc;
-            notIncludedMocs.erase(sourceFilePath);
             break;
             }
           }
@@ -628,7 +569,6 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
                 {
                 headerFound = true;
                 includedMocs[sourceFilePath] = currentMoc;
-                notIncludedMocs.erase(sourceFilePath);
                 break;
                 }
               }
@@ -658,11 +598,71 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
       else
         {
         includedMocs[absFilename] = currentMoc;
-        notIncludedMocs.erase(absFilename);
         }
       matchOffset += mocIncludeRegExp.end();
       } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
     }
+
+  // search for header files and private header files we may need to moc:
+  const std::string basename =
+              cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
+  for(std::list<std::string>::const_iterator ext = headerExtensions.begin();
+      ext != headerExtensions.end();
+      ++ext)
+    {
+    const std::string headerName = absPath + basename + (*ext);
+    if (cmsys::SystemTools::FileExists(headerName.c_str()))
+      {
+      absHeaders.insert(headerName);
+      break;
+      }
+    }
+  for(std::list<std::string>::const_iterator ext = headerExtensions.begin();
+      ext != headerExtensions.end();
+      ++ext)
+    {
+    const std::string privateHeaderName = absPath+basename+"_p"+(*ext);
+    if (cmsys::SystemTools::FileExists(privateHeaderName.c_str()))
+      {
+      absHeaders.insert(privateHeaderName);
+      break;
+      }
+    }
+
+}
+
+
+void cmQtAutomoc::ParseHeaders(const std::set<std::string>& absHeaders,
+                        const std::map<std::string, std::string>& includedMocs,
+                        std::map<std::string, std::string>& notIncludedMocs)
+{
+  cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
+  for(std::set<std::string>::const_iterator hIt=absHeaders.begin();
+      hIt!=absHeaders.end();
+      ++hIt)
+    {
+    const std::string& headerName = *hIt;
+
+    if (includedMocs.find(headerName) == includedMocs.end())
+      {
+      if (this->Verbose)
+        {
+        std::cout << "AUTOMOC: Checking " << headerName << std::endl;
+        }
+
+      const std::string basename = cmsys::SystemTools::
+                                   GetFilenameWithoutLastExtension(headerName);
+
+      const std::string currentMoc = "moc_" + basename + ".cpp";
+      const std::string contents = this->ReadAll(headerName);
+      if (qObjectRegExp.find(contents))
+        {
+        //std::cout << "header contains Q_OBJECT macro";
+        notIncludedMocs[headerName] = currentMoc;
+        }
+      }
+    }
+
 }
 
 
diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h
index 4fd9041..8fb790a 100644
--- a/Source/cmQtAutomoc.h
+++ b/Source/cmQtAutomoc.h
@@ -27,6 +27,9 @@ private:
                    const std::string& mocFileName);
   void ParseCppFile(const std::string& absFilename,
                     std::map<std::string, std::string>& includedMocs,
+                    std::set<std::string>& absHeaders);
+  void ParseHeaders(const std::set<std::string>& absHeaders,
+                    const std::map<std::string, std::string>& includedMocs,
                     std::map<std::string, std::string>& notIncludedMocs);
 
   void Init();
diff --git a/Tests/QtAutomoc/CMakeLists.txt b/Tests/QtAutomoc/CMakeLists.txt
index 4a5ff10..01f6bea 100644
--- a/Tests/QtAutomoc/CMakeLists.txt
+++ b/Tests/QtAutomoc/CMakeLists.txt
@@ -13,7 +13,7 @@ add_definitions(-DFOO)
 # create an executable and a library target, both requiring automoc:
 add_library(codeeditorLib STATIC codeeditor.cpp)
 
-add_executable(foo main.cpp calwidget.cpp )
+add_executable(foo main.cpp calwidget.cpp foo.cpp)
 
 set_target_properties(foo codeeditorLib PROPERTIES AUTOMOC TRUE)
 
diff --git a/Tests/QtAutomoc/foo.cpp b/Tests/QtAutomoc/foo.cpp
new file mode 100644
index 0000000..a7a4783
--- /dev/null
+++ b/Tests/QtAutomoc/foo.cpp
@@ -0,0 +1,26 @@
+#include "foo.h"
+
+#include <stdio.h>
+
+class FooFoo : public QObject
+{
+  Q_OBJECT
+  public:
+    FooFoo():QObject() {}
+  public slots:
+    int getValue() const { return 12; }
+};
+
+Foo::Foo()
+:QObject()
+{
+}
+
+
+void Foo::doFoo()
+{
+  FooFoo ff;
+  printf("Hello automoc: %d\n", ff.getValue());
+}
+
+#include "foo.moc"
diff --git a/Tests/QtAutomoc/foo.h b/Tests/QtAutomoc/foo.h
new file mode 100644
index 0000000..7323ff3
--- /dev/null
+++ b/Tests/QtAutomoc/foo.h
@@ -0,0 +1,15 @@
+#ifndef FOO_H
+#define FOO_H
+
+#include <QObject>
+
+class Foo : public QObject
+{
+  Q_OBJECT
+  public:
+    Foo();
+  public slots:
+    void doFoo();
+};
+
+#endif
diff --git a/Tests/QtAutomoc/main.cpp b/Tests/QtAutomoc/main.cpp
index 7bf4a5d..b7cfb41 100644
--- a/Tests/QtAutomoc/main.cpp
+++ b/Tests/QtAutomoc/main.cpp
@@ -42,6 +42,7 @@
 
 #include "codeeditor.h"
 #include "calwidget.h"
+#include "foo.h"
 
 int main(int argv, char **args)
 {
@@ -54,5 +55,8 @@ int main(int argv, char **args)
   Window w;
   w.show();
 
+  Foo foo;
+  foo.doFoo();
+
   return app.exec();
 }

-----------------------------------------------------------------------

Summary of changes:
 Source/cmQtAutomoc.cxx                             |  163 +++++++++++---------
 Source/cmQtAutomoc.h                               |   16 ++
 Tests/QtAutomoc/CMakeLists.txt                     |    2 +-
 .../QtAutomoc/foo.cpp                              |   29 +++-
 .../cmDocumentVariables.h => Tests/QtAutomoc/foo.h |   21 ++-
 Tests/QtAutomoc/main.cpp                           |    4 +
 6 files changed, 144 insertions(+), 91 deletions(-)
 copy Source/CursesDialog/cmCursesDummyWidget.cxx => Tests/QtAutomoc/foo.cpp (56%)
 copy Source/cmDocumentVariables.h => Tests/QtAutomoc/foo.h (69%)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list