diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-08-03 10:23:07 (GMT) |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-08-03 17:38:16 (GMT) |
commit | 7445c9a58a2444c8918e81a9264b1584001ca013 (patch) | |
tree | 08d3c4cdd8d4e255b1023c095be8fae17bc4eba0 /Tests/RunCMake/Ninja | |
parent | a79056bb023ae99c2e0f09f49b5d525e7b3eff8a (diff) | |
download | CMake-7445c9a58a2444c8918e81a9264b1584001ca013.zip CMake-7445c9a58a2444c8918e81a9264b1584001ca013.tar.gz CMake-7445c9a58a2444c8918e81a9264b1584001ca013.tar.bz2 |
AutoGen: Add test to check for correct AutoMoc dependencies
When using Qt 5.15.0 or above together with Ninja, check that touching
a source file of a dependency does not needlessly re-run AUTOMOC for
the dependee target.
Diffstat (limited to 'Tests/RunCMake/Ninja')
-rw-r--r-- | Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/RunCMakeTest.cmake | 21 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/app.cpp | 6 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/app_qt.cpp | 11 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/simple_lib.cpp | 6 |
5 files changed, 53 insertions, 0 deletions
diff --git a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake new file mode 100644 index 0000000..d69a119 --- /dev/null +++ b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake @@ -0,0 +1,9 @@ +enable_language(CXX) + +find_package(Qt5Core REQUIRED) + +set(CMAKE_AUTOMOC ON) + +add_library(simple_lib SHARED simple_lib.cpp) +add_executable(app_with_qt app.cpp app_qt.cpp) +target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 0eada08..c1f6346 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -132,6 +132,7 @@ ${ninja_stderr} message(FATAL_ERROR "top ninja build failed exited with status ${ninja_result}") endif() + set(ninja_stdout "${ninja_stdout}" PARENT_SCOPE) endfunction(run_ninja) function (run_LooseObjectDepends) @@ -316,3 +317,23 @@ function (run_ChangeBuildType) run_ninja("${RunCMake_TEST_BINARY_DIR}" -w dupbuild=err) endfunction() run_ChangeBuildType() + +function(run_Qt5AutoMocDeps) + if(CMake_TEST_Qt5 AND CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5AutoMocDeps-build) + run_cmake(Qt5AutoMocDeps) + unset(RunCMake_TEST_OPTIONS) + # Build the project. + run_ninja("${RunCMake_TEST_BINARY_DIR}") + # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC + # for app_with_qt target. + touch("${RunCMake_SOURCE_DIR}/simple_lib.cpp") + # Build and assert that AUTOMOC was not run for app_with_qt. + run_ninja("${RunCMake_TEST_BINARY_DIR}") + if(ninja_stdout MATCHES "Automatic MOC for target app_with_qt") + message(FATAL_ERROR + "AUTOMOC should not have executed for 'app_with_qt' target:\nstdout:\n${ninja_stdout}") + endif() + endif() +endfunction() +run_Qt5AutoMocDeps() diff --git a/Tests/RunCMake/Ninja/app.cpp b/Tests/RunCMake/Ninja/app.cpp new file mode 100644 index 0000000..57380e4 --- /dev/null +++ b/Tests/RunCMake/Ninja/app.cpp @@ -0,0 +1,6 @@ +int main(int argc, char* argv[]) +{ + (void)argc; + (void)argv; + return 0; +} diff --git a/Tests/RunCMake/Ninja/app_qt.cpp b/Tests/RunCMake/Ninja/app_qt.cpp new file mode 100644 index 0000000..302c672 --- /dev/null +++ b/Tests/RunCMake/Ninja/app_qt.cpp @@ -0,0 +1,11 @@ +#include <QObject> + +class Mango : public QObject +{ + Q_OBJECT +public: +Q_SIGNALS: + void eatFruit(); +}; + +#include "app_qt.moc" diff --git a/Tests/RunCMake/Ninja/simple_lib.cpp b/Tests/RunCMake/Ninja/simple_lib.cpp new file mode 100644 index 0000000..cf8d689 --- /dev/null +++ b/Tests/RunCMake/Ninja/simple_lib.cpp @@ -0,0 +1,6 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + void dummy_symbol() +{ +} |