Ver Fonte

Add a failing test case for #21620

Extend Qt(4|5)Autogen.RerunMocBasic to check the following situation:

Class MyObject3 is a QObject-derived class without Q_OBJECT macro.
It's declared in myobject3.h that is not included by any file that is
input of AutoMoc (this is why we had to add PlainObject).

If myobject3.h were included by main.cpp, then AutoMoc would already
track this dependency, because main.cpp has a Q_OBJECT macro.

After the initial build(s), the Q_OBJECT macro is added to myobject3.h,
and an incremental build is run. With Qt >= 5.15 and Ninja, the build
fails, because AutoMoc is not run due to the missing dependency to
myobject3.h.
Joerg Bornemann há 4 anos atrás
pai
commit
fefba42e37

+ 16 - 1
Tests/QtAutogen/RerunMocBasic/CMakeLists.txt

@@ -49,6 +49,7 @@ endmacro()
 
 # Configure the test project
 configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
+configure_file("${mocBasicSrcDir}/myobject3a.h.in" "${mocBasicBinDir}/myobject3.h" @ONLY)
 if(CMAKE_GENERATOR_INSTANCE)
     set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}")
 else()
@@ -138,9 +139,23 @@ require_change()
 # - Rebuild
 acquire_timestamp(Before)
 sleep()
-message(STATUS "Add Q_OBJECT to header file for a MOC re-run")
+message(STATUS "Add Q_OBJECT to test1.h for a MOC re-run")
 configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
 sleep()
 rebuild(5)
 acquire_timestamp(After)
 require_change()
+
+
+# - Ensure that the timestamp will change
+# - Add Q_OBJECT to MyObject3
+# - Rebuild
+acquire_timestamp(Before)
+sleep()
+message(STATUS "Add Q_OBJECT to myobject3.h file for a MOC re-run")
+set(CLASS_CONTENT "Q_OBJECT")
+configure_file("${mocBasicSrcDir}/myobject3a.h.in" "${mocBasicBinDir}/myobject3.h" @ONLY)
+sleep()
+rebuild(6)
+acquire_timestamp(After)
+require_change()

+ 6 - 1
Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt

@@ -13,10 +13,15 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
 
 add_executable(mocBasic
   ${CMAKE_CURRENT_BINARY_DIR}/test1.h
+  ${CMAKE_CURRENT_BINARY_DIR}/myobject3.h
   ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+  plainobject.cpp
   res1.qrc
 )
-target_include_directories(mocBasic PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(mocBasic PRIVATE
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
 target_link_libraries(mocBasic ${QT_QTCORE_TARGET})
 # Write target name to text file
 add_custom_command(TARGET mocBasic POST_BUILD COMMAND

+ 2 - 0
Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in

@@ -1,4 +1,5 @@
 #include "test1.h"
+#include "plainobject.h"
 
 extern int qInitResources_res1();
 
@@ -16,6 +17,7 @@ int main()
 
   Test1 test1;
   Test2 test2;
+  PlainObject plainObject;
 
   return 0;
 }

+ 13 - 0
Tests/QtAutogen/RerunMocBasic/MocBasic/myobject3a.h.in

@@ -0,0 +1,13 @@
+#ifndef MYOBJECT3_H
+#define MYOBJECT3_H
+
+#include <qobject.h>
+
+class MyObject3 : public QObject
+{
+    @CLASS_CONTENT@
+public:
+    MyObject3() {}
+};
+
+#endif

+ 12 - 0
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp

@@ -0,0 +1,12 @@
+#include "plainobject.h"
+
+#include "myobject3.h"
+
+PlainObject::PlainObject()
+{
+}
+
+void PlainObject::doSomething()
+{
+  MyObject3 obj3;
+}

+ 12 - 0
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.h

@@ -0,0 +1,12 @@
+#ifndef PLAINOBJECT_H
+#define PLAINOBJECT_H
+
+// Class that is plain C++, no Qt involved.
+class PlainObject
+{
+public:
+  PlainObject();
+  void doSomething();
+};
+
+#endif