Browse Source

QtAutogen: Short-circut some logic when moc is not available.

This is the case when AUTOMOC is false.  This prevents creating rules
to moc the files in the absense of moc.
Stephen Kelly 11 years ago
parent
commit
f7ae1d8ad6

+ 14 - 3
Source/cmQtAutoGenerators.cxx

@@ -1444,6 +1444,12 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
               << std::endl;
     return;
     }
+  this->ParseForUic(absFilename, contentsString, includedUis);
+  if (this->MocExecutable.empty())
+    {
+    return;
+    }
+
   const std::string absPath = cmsys::SystemTools::GetFilenamePath(
                    cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
   const std::string scannedFileBasename = cmsys::SystemTools::
@@ -1572,7 +1578,6 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
       matchOffset += mocIncludeRegExp.end();
       } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
     }
-  this->ParseForUic(absFilename, contentsString, includedUis);
 
   // In this case, check whether the scanned file itself contains a Q_OBJECT.
   // If this is the case, the moc_foo.cpp should probably be generated from
@@ -1627,6 +1632,12 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
               << std::endl;
     return;
     }
+  this->ParseForUic(absFilename, contentsString, includedUis);
+  if (this->MocExecutable.empty())
+    {
+    return;
+    }
+
   const std::string absPath = cmsys::SystemTools::GetFilenamePath(
                    cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
   const std::string scannedFileBasename = cmsys::SystemTools::
@@ -1705,7 +1716,6 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
       matchOffset += mocIncludeRegExp.end();
       } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
     }
-  this->ParseForUic(absFilename, contentsString, includedUis);
 
   // In this case, check whether the scanned file itself contains a Q_OBJECT.
   // If this is the case, the moc_foo.cpp should probably be generated from
@@ -1830,7 +1840,8 @@ void cmQtAutoGenerators::ParseHeaders(const std::set<std::string>& absHeaders,
     const std::string& headerName = *hIt;
     const std::string contents = ReadAll(headerName);
 
-    if (includedMocs.find(headerName) == includedMocs.end())
+    if (!this->MocExecutable.empty()
+        && includedMocs.find(headerName) == includedMocs.end())
       {
       if (this->Verbose)
         {

+ 14 - 0
Tests/QtAutogen/CMakeLists.txt

@@ -11,6 +11,11 @@ if (QT_TEST_VERSION STREQUAL 4)
   include(UseQt4)
 
   set(QT_QTCORE_TARGET Qt4::QtCore)
+
+  macro(qtx_wrap_cpp)
+    qt4_wrap_cpp(${ARGN})
+  endmacro()
+
 else()
   if (NOT QT_TEST_VERSION STREQUAL 5)
     message(SEND_ERROR "Invalid Qt version specified.")
@@ -25,6 +30,11 @@ else()
   if(Qt5_POSITION_INDEPENDENT_CODE)
     set(CMAKE_POSITION_INDEPENDENT_CODE ON)
   endif()
+
+  macro(qtx_wrap_cpp)
+    qt5_wrap_cpp(${ARGN})
+  endmacro()
+
 endif()
 
 
@@ -77,3 +87,7 @@ set_target_properties(empty PROPERTIES AUTOMOC TRUE)
 target_link_libraries(empty no_link_language)
 add_library(no_link_language STATIC empty.h)
 set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE)
+
+qtx_wrap_cpp(uicOnlyMoc uiconly.h)
+add_executable(uiconly uiconly.cpp ${uicOnlyMoc})
+target_link_libraries(uiconly ${QT_LIBRARIES})

+ 13 - 0
Tests/QtAutogen/uiconly.cpp

@@ -0,0 +1,13 @@
+
+#include "uiconly.h"
+
+UicOnly::UicOnly(QWidget *parent)
+  : QWidget(parent), ui(new Ui::UicOnly)
+{
+
+}
+
+int main()
+{
+  return 0;
+}

+ 20 - 0
Tests/QtAutogen/uiconly.h

@@ -0,0 +1,20 @@
+
+#ifndef UIC_ONLY_H
+#define UIC_ONLY_H
+
+#include <QWidget>
+#include <memory>
+
+#include "ui_uiconly.h"
+
+class UicOnly : public QWidget
+{
+  Q_OBJECT
+public:
+  explicit UicOnly(QWidget *parent = 0);
+
+private:
+  const std::auto_ptr<Ui::UicOnly> ui;
+};
+
+#endif

+ 24 - 0
Tests/QtAutogen/uiconly.ui

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UicOnly</class>
+ <widget class="QWidget" name="UicOnly">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="treeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>