diff options
author | Orkun Tokdemir <ilhanorkuntokdemir@gmail.com> | 2023-09-07 12:52:46 (GMT) |
---|---|---|
committer | Orkun Tokdemir <ilhanorkuntokdemir@gmail.com> | 2023-09-11 12:51:58 (GMT) |
commit | 09b650d00097863c03bff6c46122a7f366c4ddd2 (patch) | |
tree | 5897ea2fac1e31e9b59c4cff20e65212fccc500e | |
parent | ebc9e448b38378cc21a6b77df03a77d9732c24ac (diff) | |
download | CMake-09b650d00097863c03bff6c46122a7f366c4ddd2.zip CMake-09b650d00097863c03bff6c46122a7f366c4ddd2.tar.gz CMake-09b650d00097863c03bff6c46122a7f366c4ddd2.tar.bz2 |
Autogen: Move QtAutoMocDeps tests to RunCMake/Autogen
15 files changed, 113 insertions, 52 deletions
diff --git a/Tests/RunCMake/Autogen/MyWindow.cpp b/Tests/RunCMake/Autogen/MyWindow.cpp new file mode 100644 index 0000000..d87c2e9 --- /dev/null +++ b/Tests/RunCMake/Autogen/MyWindow.cpp @@ -0,0 +1,7 @@ +#include "MyWindow.h" + +MyWindow::MyWindow(QWidget* parent) + : QWidget(parent) +{ + this->m_ui.setupUi(this); +} diff --git a/Tests/RunCMake/Autogen/MyWindow.h b/Tests/RunCMake/Autogen/MyWindow.h new file mode 100644 index 0000000..c267610 --- /dev/null +++ b/Tests/RunCMake/Autogen/MyWindow.h @@ -0,0 +1,16 @@ +#pragma once + +#include <QWidget> + +#include "ui_MyWindow.h" + +class MyWindow : public QWidget +{ + Q_OBJECT + +public: + explicit MyWindow(QWidget* parent = nullptr); + +private: + Ui::MyWindow m_ui; +}; diff --git a/Tests/RunCMake/Autogen/MyWindow.ui b/Tests/RunCMake/Autogen/MyWindow.ui new file mode 100644 index 0000000..fbf294c --- /dev/null +++ b/Tests/RunCMake/Autogen/MyWindow.ui @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MyWindow</class> + <widget class="QWidget" name="MyWindow"/> +</ui> diff --git a/Tests/RunCMake/Ninja/QtAutoMocDeps-stderr.txt b/Tests/RunCMake/Autogen/QtAutoMocDeps-stderr.txt index 6024984..6024984 100644 --- a/Tests/RunCMake/Ninja/QtAutoMocDeps-stderr.txt +++ b/Tests/RunCMake/Autogen/QtAutoMocDeps-stderr.txt diff --git a/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake b/Tests/RunCMake/Autogen/QtAutoMocDeps.cmake index c441169..fc3b2f2 100644 --- a/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake +++ b/Tests/RunCMake/Autogen/QtAutoMocDeps.cmake @@ -1,27 +1,23 @@ enable_language(CXX) -set(QtX Qt${with_qt_version}) - -find_package(${QtX} REQUIRED COMPONENTS Core) +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) 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 ${QtX}::Core) +target_link_libraries(app_with_qt PRIVATE simple_lib Qt${with_qt_version}::Core) -if(${QtX}Widgets_DIR) - find_package(${QtX} REQUIRED COMPONENTS Widgets) +if(${with_qt_version}Widgets_DIR) if(with_qt_version STREQUAL 5) qt5_wrap_ui(_headers MyWindow.ui) else() qt_wrap_ui(_headers MyWindow.ui) endif() add_executable(app_with_widget app.cpp MyWindow.cpp ${_headers}) - target_link_libraries(app_with_widget PRIVATE ${QtX}::Widgets) + target_link_libraries(app_with_widget PRIVATE Qt${with_qt_version}::Widgets) target_include_directories(app_with_widget PRIVATE "${CMAKE_BINARY_DIR}") endif() - add_subdirectory(QtSubDir1) add_subdirectory(QtSubDir2) add_subdirectory(QtSubDir3) diff --git a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt b/Tests/RunCMake/Autogen/QtSubDir1/CMakeLists.txt index 3a12dcd..f215b9e 100644 --- a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt +++ b/Tests/RunCMake/Autogen/QtSubDir1/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 OLD) add_executable(sub_exe_1 ../app.cpp) -target_link_libraries(sub_exe_1 PRIVATE ${QtX}::Core) +target_link_libraries(sub_exe_1 PRIVATE Qt${with_qt_version}::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt b/Tests/RunCMake/Autogen/QtSubDir2/CMakeLists.txt index a2f77e4..cccb1e0 100644 --- a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt +++ b/Tests/RunCMake/Autogen/QtSubDir2/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 NEW) add_executable(sub_exe_2 ../app.cpp) -target_link_libraries(sub_exe_2 PRIVATE ${QtX}::Core) +target_link_libraries(sub_exe_2 PRIVATE Qt${with_qt_version}::Core) diff --git a/Tests/RunCMake/Autogen/QtSubDir3/CMakeLists.txt b/Tests/RunCMake/Autogen/QtSubDir3/CMakeLists.txt new file mode 100644 index 0000000..d268bfe --- /dev/null +++ b/Tests/RunCMake/Autogen/QtSubDir3/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(sub_exe_3 ../app.cpp) +target_link_libraries(sub_exe_3 PRIVATE Qt${with_qt_version}::Core) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index 4fe9406..886065a 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -122,4 +122,55 @@ if (DEFINED with_qt_version) endblock() endif() endif() + + if(RunCMake_GENERATOR MATCHES "Make|Ninja") + block() + if(QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps-build) + run_cmake(QtAutoMocDeps) + set(RunCMake_TEST_NO_CLEAN 1) + # Build the project. + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC + # for app_with_qt target. + file(TOUCH "${RunCMake_SOURCE_DIR}/simple_lib.cpp") + set(RunCMake_TEST_NOT_EXPECT_stdout "Automatic MOC for target app_with_qt|\ +Automatic MOC for target sub_exe_1|\ +Automatic MOC for target sub_exe_2") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't execute AUTOMOC for 'app_with_qt', 'sub_exe_1' and 'sub_exe_2'") + # Build and assert that AUTOMOC was not run for app_with_qt, sub_exe_1 and sub_exe_2. + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + unset(RunCMake_TEST_VARIANT_DESCRIPTION) + unset(RunCMake_TEST_NOT_EXPECT_stdout) + + macro(check_file_exists file) + if (EXISTS "${file}") + set(check_result "PASSED") + set(message_type "STATUS") + else() + set(check_result "FAILED") + set(message_type "FATAL_ERROR") + endif() + + message(${message_type} "QtAutoMocDeps-build-\"${file}\" was generated - ${check_result}") + endmacro() + + check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/deps") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/deps") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/deps") + + check_file_exists("${RunCMake_TEST_BINARY_DIR}/app_with_qt_autogen/timestamp") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir1/sub_exe_1_autogen/timestamp") + check_file_exists("${RunCMake_TEST_BINARY_DIR}/QtSubDir2/sub_exe_2_autogen/timestamp") + + # Touch a header file to make sure an automoc dependency cycle is not introduced. + file(TOUCH "${RunCMake_SOURCE_DIR}/MyWindow.h") + set(RunCMake_TEST_VARIANT_DESCRIPTION "-First build after touch to detect dependency cycle") + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + # Need to run a second time to hit the dependency cycle. + set(RunCMake_TEST_VARIANT_DESCRIPTION "-Don't hit dependency cycle") + run_cmake_command(QtAutoMocDeps-build ${CMAKE_COMMAND} --build . --verbose) + endif() + endblock() + endif() endif () diff --git a/Tests/RunCMake/Autogen/app.cpp b/Tests/RunCMake/Autogen/app.cpp new file mode 100644 index 0000000..57380e4 --- /dev/null +++ b/Tests/RunCMake/Autogen/app.cpp @@ -0,0 +1,6 @@ +int main(int argc, char* argv[]) +{ + (void)argc; + (void)argv; + return 0; +} diff --git a/Tests/RunCMake/Autogen/app_qt.cpp b/Tests/RunCMake/Autogen/app_qt.cpp new file mode 100644 index 0000000..302c672 --- /dev/null +++ b/Tests/RunCMake/Autogen/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/Autogen/simple_lib.cpp b/Tests/RunCMake/Autogen/simple_lib.cpp new file mode 100644 index 0000000..cf8d689 --- /dev/null +++ b/Tests/RunCMake/Autogen/simple_lib.cpp @@ -0,0 +1,6 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + void dummy_symbol() +{ +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 5e212bd..e13a205 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -274,6 +274,7 @@ if(CMake_TEST_Qt6 AND Qt6Widgets_FOUND) cmake_path(GET base_dir PARENT_PATH base_dir) # <base> add_RunCMake_test(AutogenQt6 TEST_DIR Autogen -Dwith_qt_version=6 + -DQtCore_VERSION=${Qt6Core_VERSION} "-DQt6_DIR:PATH=${Qt6_DIR}" "-DCMAKE_PREFIX_PATH:STRING=${base_dir}" -DPSEUDO_TIDY=$<TARGET_FILE:pseudo_tidy> @@ -286,6 +287,7 @@ endif () if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND) add_RunCMake_test(AutogenQt5 TEST_DIR Autogen -Dwith_qt_version=5 + -DQtCore_VERSION=${Qt5Core_VERSION} "-DQt5_DIR:PATH=${Qt5_DIR}" ) set(want_NoQt_test FALSE) diff --git a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt deleted file mode 100644 index 70644fa..0000000 --- a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_executable(sub_exe_3 ../app.cpp) -target_link_libraries(sub_exe_3 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 6eb0b1d..6cc6234 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -380,45 +380,6 @@ function (run_ChangeBuildType) endfunction() run_ChangeBuildType() -function(run_QtAutoMocDeps) - set(QtX Qt${CMake_TEST_Qt_version}) - if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps-build) - run_cmake_with_options(QtAutoMocDeps - "-Dwith_qt_version=${CMake_TEST_Qt_version}" - "-D${QtX}_DIR=${${QtX}_DIR}" - "-D${QtX}Core_DIR=${${QtX}Core_DIR}" - "-D${QtX}Widgets_DIR=${${QtX}Widgets_DIR}" - "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" - ) - # 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. - file(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() - # Assert that the subdir executables were not rebuilt. - if(ninja_stdout MATCHES "Automatic MOC for target sub_exe_1") - message(FATAL_ERROR - "AUTOMOC should not have executed for 'sub_exe_1' target:\nstdout:\n${ninja_stdout}") - endif() - if(ninja_stdout MATCHES "Automatic MOC for target sub_exe_2") - message(FATAL_ERROR - "AUTOMOC should not have executed for 'sub_exe_2' target:\nstdout:\n${ninja_stdout}") - endif() - # Touch a header file to make sure an automoc dependency cycle is not introduced. - file(TOUCH "${RunCMake_SOURCE_DIR}/MyWindow.h") - run_ninja("${RunCMake_TEST_BINARY_DIR}") - # Need to run a second time to hit the dependency cycle. - run_ninja("${RunCMake_TEST_BINARY_DIR}") - endif() -endfunction() - function(run_QtAutoMocSkipPch) set(QtX Qt${CMake_TEST_Qt_version}) if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) @@ -433,7 +394,7 @@ function(run_QtAutoMocSkipPch) run_ninja("${RunCMake_TEST_BINARY_DIR}") endif() endfunction() + if(CMake_TEST_Qt_version) - run_QtAutoMocDeps() run_QtAutoMocSkipPch() endif() |