Commit 3327d3bb authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

Autogen: Add cmQtAutoGenGlobalInitializer class

This moves the global ``AUTOMOC/UIC/RCC`` targets initializer
generation code into a separate new ``cmQtAutoGenGlobalInitializer`` class.
parent 206ce3c0
......@@ -320,6 +320,8 @@ set(SRCS
cmQtAutoGen.h
cmQtAutoGenerator.cxx
cmQtAutoGenerator.h
cmQtAutoGenGlobalInitializer.cxx
cmQtAutoGenGlobalInitializer.h
cmQtAutoGenInitializer.cxx
cmQtAutoGenInitializer.h
cmQtAutoGeneratorMocUic.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<std::unique_ptr<cmQtAutoGenInitializer>> autogenInits;
for (cmLocalGenerator* localGen : this->LocalGenerators) {
const std::vector<cmGeneratorTarget*>& 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<cmQtAutoGenInitializer>(
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(
......
/* 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<cmLocalGenerator*> 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<cmQtAutoGenInitializer>(
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;
}
/* 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 <memory>
#include <vector>
class cmLocalGenerator;
class cmQtAutoGenInitializer;
/// @brief Initializes the QtAutoGen generators
class cmQtAutoGenGlobalInitializer
{
public:
cmQtAutoGenGlobalInitializer(
std::vector<cmLocalGenerator*> const& localGenerators);
~cmQtAutoGenGlobalInitializer();
bool generate();
private:
bool InitializeCustomTargets();
bool SetupCustomTargets();
private:
std::vector<std::unique_ptr<cmQtAutoGenInitializer>> Initializers_;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment