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.
This commit is contained in:
Joerg Bornemann
2020-12-23 14:21:24 +01:00
parent 2999c40dd9
commit fefba42e37
6 changed files with 61 additions and 2 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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;
}

View File

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

View File

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

View File

@@ -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