diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-12-23 13:21:24 (GMT) |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-01-06 19:16:36 (GMT) |
commit | fefba42e3740bb6a32cda13dfdebf51d414faac7 (patch) | |
tree | 44449dd991ae2cde5ea343c42551b96840769328 /Tests/QtAutogen/RerunMocBasic | |
parent | 2999c40dd911a59b438bd5f400521ab5007d83d8 (diff) | |
download | CMake-fefba42e3740bb6a32cda13dfdebf51d414faac7.zip CMake-fefba42e3740bb6a32cda13dfdebf51d414faac7.tar.gz CMake-fefba42e3740bb6a32cda13dfdebf51d414faac7.tar.bz2 |
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.
Diffstat (limited to 'Tests/QtAutogen/RerunMocBasic')
6 files changed, 61 insertions, 2 deletions
diff --git a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt index 72c99d5..c53e857 100644 --- a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt +++ b/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() diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt index 6a9f550..42f2f57 100644 --- a/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt +++ b/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 diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in b/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in index 9d7ea37..5accfd6 100644 --- a/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in +++ b/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; } diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/myobject3a.h.in b/Tests/QtAutogen/RerunMocBasic/MocBasic/myobject3a.h.in new file mode 100644 index 0000000..d62c314 --- /dev/null +++ b/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 diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp b/Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp new file mode 100644 index 0000000..0ca785e --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.cpp @@ -0,0 +1,12 @@ +#include "plainobject.h" + +#include "myobject3.h" + +PlainObject::PlainObject() +{ +} + +void PlainObject::doSomething() +{ + MyObject3 obj3; +} diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.h b/Tests/QtAutogen/RerunMocBasic/MocBasic/plainobject.h new file mode 100644 index 0000000..8037858 --- /dev/null +++ b/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 |