diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2017-12-09 12:06:58 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2017-12-13 12:50:18 (GMT) |
commit | 54b4ff2aee015768a990cb3fccb79f8e87b38a19 (patch) | |
tree | 49982f8d34ef12cc27858b2130785ca4639fd9d2 /Tests/QtAutogen | |
parent | 4988746e76703269d76c3fb633bafc0767fafbe4 (diff) | |
download | CMake-54b4ff2aee015768a990cb3fccb79f8e87b38a19.zip CMake-54b4ff2aee015768a990cb3fccb79f8e87b38a19.tar.gz CMake-54b4ff2aee015768a990cb3fccb79f8e87b38a19.tar.bz2 |
Autogen: Tests: Separate RerunMocBasic test
Diffstat (limited to 'Tests/QtAutogen')
-rw-r--r-- | Tests/QtAutogen/CommonTests.cmake | 2 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/CMakeLists.txt | 65 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt | 24 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/input.txt | 1 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in | 23 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/res1.qrc | 5 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/test1a.h.in | 8 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/MocBasic/test1b.h.in | 7 | ||||
-rw-r--r-- | Tests/QtAutogen/RerunMocBasic/dummy.cpp | 5 |
9 files changed, 140 insertions, 0 deletions
diff --git a/Tests/QtAutogen/CommonTests.cmake b/Tests/QtAutogen/CommonTests.cmake index 6921495..94413a3 100644 --- a/Tests/QtAutogen/CommonTests.cmake +++ b/Tests/QtAutogen/CommonTests.cmake @@ -31,3 +31,5 @@ endif() ADD_AUTOGEN_TEST(SameName sameName) ADD_AUTOGEN_TEST(StaticLibraryCycle slc) ADD_AUTOGEN_TEST(Complex QtAutogen) +# Rerun tests +ADD_AUTOGEN_TEST(RerunMocBasic) diff --git a/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt new file mode 100644 index 0000000..0bb0339 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/CMakeLists.txt @@ -0,0 +1,65 @@ +cmake_minimum_required(VERSION 3.10) +project(RerunMocBasic) +include("../AutogenTest.cmake") + +# Dummy executable to generate a clean target +add_executable(dummy dummy.cpp) + +set(timeformat "%Y%j%H%M%S") +set(mocBasicSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocBasic") +set(mocBasicBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocBasic") + +# Initial build +configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY) +try_compile(MOC_RERUN + "${mocBasicBinDir}" + "${mocBasicSrcDir}" + MocBasic + CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}" + "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}" + OUTPUT_VARIABLE output +) +if (NOT MOC_RERUN) + message(SEND_ERROR "Initial build of mocBasic failed. Output: ${output}") +endif() +# Get name of the output binary +file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8) +list(GET mocBasicList 0 mocBasicBin) + +message("Changing the header content for a MOC rerun") +# - Acquire binary timestamps before the build +file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}") +# - Ensure that the timestamp will change +# - Change header file content and rebuild +# - Rebuild +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY) +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result ) +if (result) + message(SEND_ERROR "Second build of mocBasic failed.") +endif() +# - Acquire binary timestamps after the build +file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}") +# - Test if timestamps changed +if (NOT timeAfter GREATER timeBefore) + message(SEND_ERROR "File (${mocBasicBin}) should have changed!") +endif() + + +message("Changing nothing for a MOC rerun") +# - Acquire binary timestamps before the build +file(TIMESTAMP "${mocBasicBin}" timeBefore "${timeformat}") +# - Ensure that the timestamp would change +# - Change nothing +# - Rebuild +execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result ) +if (result) + message(SEND_ERROR "Third build of mocBasic failed.") +endif() +# - Acquire binary timestamps after the build +file(TIMESTAMP "${mocBasicBin}" timeAfter "${timeformat}") +# - Test if timestamps changed +if (timeAfter GREATER timeBefore) + message(SEND_ERROR "File (${mocBasicBin}) should not have changed!") +endif() diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt b/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt new file mode 100644 index 0000000..cec60a4 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.10) +project(MocBasic) +include("../../AutogenTest.cmake") + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +# Generated source file +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + COMMAND ${CMAKE_COMMAND} -E sleep 2 + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/main.cpp +) + +add_executable(mocBasic + ${CMAKE_CURRENT_BINARY_DIR}/test1.h + ${CMAKE_CURRENT_BINARY_DIR}/main.cpp + res1.qrc +) +target_include_directories(mocBasic PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(mocBasic ${QT_QTCORE_TARGET}) +# Write target name to text file +add_custom_command(TARGET mocBasic POST_BUILD COMMAND + ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:mocBasic>" > mocBasic.txt +) diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/input.txt b/Tests/QtAutogen/RerunMocBasic/MocBasic/input.txt new file mode 100644 index 0000000..da62762 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/input.txt @@ -0,0 +1 @@ +Res1 input. diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in b/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in new file mode 100644 index 0000000..9d7ea37 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/main.cpp.in @@ -0,0 +1,23 @@ +#include "test1.h" + +extern int qInitResources_res1(); + +class Test2 : public QObject +{ + Q_OBJECT +public slots: + void onTst1() {} +}; + +int main() +{ + // Fails to link if the rcc generated symbol is not present. + qInitResources_res1(); + + Test1 test1; + Test2 test2; + + return 0; +} + +#include "main.moc" diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/res1.qrc b/Tests/QtAutogen/RerunMocBasic/MocBasic/res1.qrc new file mode 100644 index 0000000..fb804b5 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/res1.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>input.txt</file> + </qresource> +</RCC> diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/test1a.h.in b/Tests/QtAutogen/RerunMocBasic/MocBasic/test1a.h.in new file mode 100644 index 0000000..a335046 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/test1a.h.in @@ -0,0 +1,8 @@ +#include <QObject> +class Test1 : public QObject +{ + Q_OBJECT +public slots: + void onTst1() {} + void onTst2() {} +}; diff --git a/Tests/QtAutogen/RerunMocBasic/MocBasic/test1b.h.in b/Tests/QtAutogen/RerunMocBasic/MocBasic/test1b.h.in new file mode 100644 index 0000000..6128eeb --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/MocBasic/test1b.h.in @@ -0,0 +1,7 @@ +#include <QObject> +class Test1 : public QObject +{ + Q_OBJECT +public slots: + void onTst1() {} +}; diff --git a/Tests/QtAutogen/RerunMocBasic/dummy.cpp b/Tests/QtAutogen/RerunMocBasic/dummy.cpp new file mode 100644 index 0000000..4837a76 --- /dev/null +++ b/Tests/QtAutogen/RerunMocBasic/dummy.cpp @@ -0,0 +1,5 @@ + +int main(int argv, char** args) +{ + return 0; +} |