From 5ae69f591965886c5e6a1cde780a87ddc4c4722d Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 10 Jan 2019 15:44:10 +0100 Subject: Autogen: Issue a warning when AUTOMOC/UIC/RCC gets disabled. We used to silently disable AUTOMOC/UIC/RCC when no valid Qt version was found. This patch introduces the generation of a warning message in that case. Closes #18732. --- Source/cmGlobalGenerator.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 71e844e..5f7ff0b 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1500,6 +1500,31 @@ bool cmGlobalGenerator::QtAutoGen() auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); // don't do anything if there is no Qt4 or Qt5Core (which contains moc) if (qtVersion.Major != 4 && qtVersion.Major != 5) { + std::string msg = "AUTOGEN: No valid Qt version found for target "; + msg += target->GetName(); + msg += ". "; + { + std::vector lst; + if (mocEnabled) { + lst.emplace_back("AUTOMOC"); + } + if (uicEnabled) { + lst.emplace_back("AUTOUIC"); + } + if (rccEnabled) { + lst.emplace_back("AUTORCC"); + } + msg += cmJoin(lst, ", "); + } + msg += " disabled. "; + msg += "Consider adding:\n"; + if (uicEnabled) { + msg += " find_package(Qt5 COMPONENTS Widgets)\n"; + } else { + msg += " find_package(Qt5 COMPONENTS Core)\n"; + } + msg += "to your CMakeLists.txt file."; + target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); continue; } -- cgit v0.12 From f44a0414aec38f6e70eb2c11c75c9f35bb526259 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 10 Jan 2019 17:39:51 +0100 Subject: Autogen: Issue a warning when AUTOMOC/UIC/RCC gets disabled. We used to silently disable AUTOMOC/UIC/RCC when no valid Qt version was found. This patch introduces the generation of a warning message in that case. --- Source/cmQtAutoGenGlobalInitializer.cxx | 40 ++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 678ff14..f4cf3e0 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -13,6 +13,7 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmake.h" #include #include @@ -86,10 +87,43 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); bool const validQt = (qtVersion.Major == 4) || (qtVersion.Major == 5) || (qtVersion.Major == 6); - bool const mocIsValid = moc && (validQt || !mocExec.empty()); - bool const uicIsValid = uic && (validQt || !uicExec.empty()); - bool const rccIsValid = rcc && (validQt || !rccExec.empty()); + bool const mocAvailable = (validQt || !mocExec.empty()); + bool const uicAvailable = (validQt || !uicExec.empty()); + bool const rccAvailable = (validQt || !rccExec.empty()); + bool const mocIsValid = (moc && mocAvailable); + bool const uicIsValid = (uic && uicAvailable); + bool const rccIsValid = (rcc && uicAvailable); + // Disabled AUTOMOC/UIC/RCC warning + bool const mocDisabled = (moc && !mocAvailable); + bool const uicDisabled = (uic && !uicAvailable); + bool const rccDisabled = (rcc && !rccAvailable); + if (mocDisabled || uicDisabled || rccDisabled) { + std::string msg = "AUTOGEN: No valid Qt version found for target "; + msg += target->GetName(); + msg += ". "; + { + std::vector lst; + if (mocDisabled) { + lst.emplace_back("AUTOMOC"); + } + if (uicDisabled) { + lst.emplace_back("AUTOUIC"); + } + if (rccDisabled) { + lst.emplace_back("AUTORCC"); + } + msg += cmJoin(lst, ", "); + } + msg += " disabled. Consider adding:\n"; + if (uicDisabled) { + msg += " find_package(Qt5 COMPONENTS Widgets)\n"; + } else { + msg += " find_package(Qt5 COMPONENTS Core)\n"; + } + msg += "to your CMakeLists.txt file."; + target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg); + } if (mocIsValid || uicIsValid || rccIsValid) { // Create autogen target initializer Initializers_.emplace_back(cm::make_unique( -- cgit v0.12 From dd39da551883bca5f8ec1be376a77f6d56666552 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 Jan 2019 08:27:14 -0500 Subject: Tests: Add case for warning when AUTOMOC/UIC/RCC gets disabled --- Tests/RunCMake/Autogen/CMakeLists.txt | 3 +++ Tests/RunCMake/Autogen/NoQt-stderr.txt | 8 ++++++++ Tests/RunCMake/Autogen/NoQt.cmake | 6 ++++++ Tests/RunCMake/Autogen/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/Autogen/empty.cpp | 0 Tests/RunCMake/CMakeLists.txt | 1 + 6 files changed, 21 insertions(+) create mode 100644 Tests/RunCMake/Autogen/CMakeLists.txt create mode 100644 Tests/RunCMake/Autogen/NoQt-stderr.txt create mode 100644 Tests/RunCMake/Autogen/NoQt.cmake create mode 100644 Tests/RunCMake/Autogen/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/Autogen/empty.cpp diff --git a/Tests/RunCMake/Autogen/CMakeLists.txt b/Tests/RunCMake/Autogen/CMakeLists.txt new file mode 100644 index 0000000..9a66cde --- /dev/null +++ b/Tests/RunCMake/Autogen/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.13) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/Autogen/NoQt-stderr.txt b/Tests/RunCMake/Autogen/NoQt-stderr.txt new file mode 100644 index 0000000..6b4a933 --- /dev/null +++ b/Tests/RunCMake/Autogen/NoQt-stderr.txt @@ -0,0 +1,8 @@ +^CMake Warning \(dev\) in CMakeLists.txt: + AUTOGEN: No valid Qt version found for target main. AUTOMOC, AUTOUIC, + AUTORCC disabled. Consider adding: + + find_package\(Qt5 COMPONENTS Widgets\) + + to your CMakeLists.txt file. +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/Autogen/NoQt.cmake b/Tests/RunCMake/Autogen/NoQt.cmake new file mode 100644 index 0000000..b2d375a --- /dev/null +++ b/Tests/RunCMake/Autogen/NoQt.cmake @@ -0,0 +1,6 @@ +enable_language(CXX) + +add_executable(main empty.cpp) +set_property(TARGET main PROPERTY AUTOMOC 1) +set_property(TARGET main PROPERTY AUTORCC 1) +set_property(TARGET main PROPERTY AUTOUIC 1) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake new file mode 100644 index 0000000..e52f28d --- /dev/null +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake(NoQt) diff --git a/Tests/RunCMake/Autogen/empty.cpp b/Tests/RunCMake/Autogen/empty.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 99f4ae7..89102dd 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -142,6 +142,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) endif() add_RunCMake_test(AndroidTestUtilities) +add_RunCMake_test(Autogen) add_RunCMake_test(BuildDepends) if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(Byproducts) -- cgit v0.12