From 3327d3bb20c2a4505648b59d72cfaada38e1ee93 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 5 Nov 2018 11:18:46 +0100 Subject: Autogen: Add cmQtAutoGenGlobalInitializer class This moves the global ``AUTOMOC/UIC/RCC`` targets initializer generation code into a separate new ``cmQtAutoGenGlobalInitializer`` class. --- Source/CMakeLists.txt | 2 + Source/cmGlobalGenerator.cxx | 64 +++------------------------ Source/cmQtAutoGenGlobalInitializer.cxx | 76 +++++++++++++++++++++++++++++++++ Source/cmQtAutoGenGlobalInitializer.h | 32 ++++++++++++++ 4 files changed, 115 insertions(+), 59 deletions(-) create mode 100644 Source/cmQtAutoGenGlobalInitializer.cxx create mode 100644 Source/cmQtAutoGenGlobalInitializer.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index ded21bc..9aebfa7 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -320,6 +320,8 @@ set(SRCS cmQtAutoGen.h cmQtAutoGenerator.cxx cmQtAutoGenerator.h + cmQtAutoGenGlobalInitializer.cxx + cmQtAutoGenGlobalInitializer.h cmQtAutoGenInitializer.cxx cmQtAutoGenInitializer.h cmQtAutoGeneratorMocUic.cxx diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index cf85473..2805395 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -34,8 +34,6 @@ #include "cmMakefile.h" #include "cmOutputConverter.h" #include "cmPolicies.h" -#include "cmQtAutoGen.h" -#include "cmQtAutoGenInitializer.h" #include "cmSourceFile.h" #include "cmState.h" #include "cmStateDirectory.h" @@ -46,6 +44,7 @@ #if defined(CMAKE_BUILD_WITH_CMAKE) # include "cmCryptoHash.h" +# include "cmQtAutoGenGlobalInitializer.h" # include "cm_jsoncpp_value.h" # include "cm_jsoncpp_writer.h" #endif @@ -1469,64 +1468,11 @@ bool cmGlobalGenerator::ComputeTargetDepends() bool cmGlobalGenerator::QtAutoGen() { #ifdef CMAKE_BUILD_WITH_CMAKE - std::vector> autogenInits; - - for (cmLocalGenerator* localGen : this->LocalGenerators) { - const std::vector& targets = - localGen->GetGeneratorTargets(); - // Find targets that require AUTOGEN processing - for (cmGeneratorTarget* target : targets) { - if (target->GetType() == cmStateEnums::GLOBAL_TARGET) { - continue; - } - if (target->GetType() != cmStateEnums::EXECUTABLE && - target->GetType() != cmStateEnums::STATIC_LIBRARY && - target->GetType() != cmStateEnums::SHARED_LIBRARY && - target->GetType() != cmStateEnums::MODULE_LIBRARY && - target->GetType() != cmStateEnums::OBJECT_LIBRARY) { - continue; - } - if (target->IsImported()) { - continue; - } - - const bool mocEnabled = target->GetPropertyAsBool("AUTOMOC"); - const bool uicEnabled = target->GetPropertyAsBool("AUTOUIC"); - const bool rccEnabled = target->GetPropertyAsBool("AUTORCC"); - if (!mocEnabled && !uicEnabled && !rccEnabled) { - continue; - } - - 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) { - continue; - } - - autogenInits.emplace_back(cm::make_unique( - target, mocEnabled, uicEnabled, rccEnabled, qtVersion)); - } - } - - if (!autogenInits.empty()) { - // Initialize custom targets - for (auto& autoGen : autogenInits) { - if (!autoGen->InitCustomTargets()) { - return false; - } - } - - // Setup custom targets - for (auto& autoGen : autogenInits) { - if (!autoGen->SetupCustomTargets()) { - return false; - } - autoGen.reset(nullptr); - } - } -#endif - + cmQtAutoGenGlobalInitializer initializer(this->LocalGenerators); + return initializer.generate(); +#else return true; +#endif } cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer( diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx new file mode 100644 index 0000000..d815a43 --- /dev/null +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -0,0 +1,76 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include "cmQtAutoGenGlobalInitializer.h" +#include "cmAlgorithms.h" +#include "cmGeneratorTarget.h" +#include "cmLocalGenerator.h" +#include "cmQtAutoGenInitializer.h" + +cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer( + std::vector const& localGenerators) +{ + for (cmLocalGenerator* localGen : localGenerators) { + // Find targets that require AUTOMOC/UIC/RCC processing + for (cmGeneratorTarget* target : localGen->GetGeneratorTargets()) { + // Process only certain target types + switch (target->GetType()) { + case cmStateEnums::EXECUTABLE: + case cmStateEnums::STATIC_LIBRARY: + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::OBJECT_LIBRARY: + // Process target + break; + default: + // Don't process target + continue; + } + if (target->IsImported()) { + // Don't process target + continue; + } + + bool const moc = target->GetPropertyAsBool("AUTOMOC"); + bool const uic = target->GetPropertyAsBool("AUTOUIC"); + bool const rcc = target->GetPropertyAsBool("AUTORCC"); + if (moc || uic || rcc) { + // We support Qt4 and Qt5 + auto qtVersion = cmQtAutoGenInitializer::GetQtVersion(target); + if ((qtVersion.Major == 4) || (qtVersion.Major == 5)) { + // Create autogen target initializer + Initializers_.emplace_back(cm::make_unique( + target, moc, uic, rcc, qtVersion)); + } + } + } + } +} + +cmQtAutoGenGlobalInitializer::~cmQtAutoGenGlobalInitializer() +{ +} + +bool cmQtAutoGenGlobalInitializer::generate() +{ + return (InitializeCustomTargets() && SetupCustomTargets()); +} + +bool cmQtAutoGenGlobalInitializer::InitializeCustomTargets() +{ + for (auto& autoGen : Initializers_) { + if (!autoGen->InitCustomTargets()) { + return false; + } + } + return true; +} + +bool cmQtAutoGenGlobalInitializer::SetupCustomTargets() +{ + for (auto& autoGen : Initializers_) { + if (!autoGen->SetupCustomTargets()) { + return false; + } + } + return true; +} diff --git a/Source/cmQtAutoGenGlobalInitializer.h b/Source/cmQtAutoGenGlobalInitializer.h new file mode 100644 index 0000000..42bf62f --- /dev/null +++ b/Source/cmQtAutoGenGlobalInitializer.h @@ -0,0 +1,32 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmQtAutoGenGlobalInitializer_h +#define cmQtAutoGenGlobalInitializer_h + +#include "cmConfigure.h" // IWYU pragma: keep + +#include +#include + +class cmLocalGenerator; +class cmQtAutoGenInitializer; + +/// @brief Initializes the QtAutoGen generators +class cmQtAutoGenGlobalInitializer +{ +public: + cmQtAutoGenGlobalInitializer( + std::vector const& localGenerators); + ~cmQtAutoGenGlobalInitializer(); + + bool generate(); + +private: + bool InitializeCustomTargets(); + bool SetupCustomTargets(); + +private: + std::vector> Initializers_; +}; + +#endif -- cgit v0.12