mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 21:00:17 -06:00
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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
Tests/QtAutogen/RerunMocBasic/MocBasic/myobject3a.h.in
Normal file
13
Tests/QtAutogen/RerunMocBasic/MocBasic/myobject3a.h.in
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef MYOBJECT3_H
|
||||
#define MYOBJECT3_H
|
||||
|
||||
#include <qobject.h>
|
||||
|
||||
class MyObject3 : public QObject
|
||||
{
|
||||
@CLASS_CONTENT@
|
||||
public:
|
||||
MyObject3() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
12
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp
Normal file
12
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "plainobject.h"
|
||||
|
||||
#include "myobject3.h"
|
||||
|
||||
PlainObject::PlainObject()
|
||||
{
|
||||
}
|
||||
|
||||
void PlainObject::doSomething()
|
||||
{
|
||||
MyObject3 obj3;
|
||||
}
|
||||
12
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.h
Normal file
12
Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.h
Normal 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
|
||||
Reference in New Issue
Block a user