cmake/Source/cmQtAutoGenInitializer.h

272 lines
7.3 KiB
C
Raw Normal View History

2018-04-23 21:13:27 +02:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-04-23 21:13:27 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2021-09-14 00:13:48 +02:00
#include <cstddef>
2020-02-01 23:06:01 +01:00
#include <memory>
2018-04-23 21:13:27 +02:00
#include <set>
#include <string>
2019-11-11 23:01:05 +01:00
#include <unordered_map>
2020-02-01 23:06:01 +01:00
#include <unordered_set>
2019-11-11 23:01:05 +01:00
#include <utility>
2018-04-23 21:13:27 +02:00
#include <vector>
2020-02-01 23:06:01 +01:00
#include <cm/string_view>
#include "cmFilePathChecksum.h"
#include "cmQtAutoGen.h"
2018-04-23 21:13:27 +02:00
class cmGeneratorTarget;
2020-02-01 23:06:01 +01:00
class cmGlobalGenerator;
class cmLocalGenerator;
class cmMakefile;
2019-11-11 23:01:05 +01:00
class cmQtAutoGenGlobalInitializer;
class cmSourceFile;
2020-02-01 23:06:01 +01:00
class cmTarget;
2018-04-23 21:13:27 +02:00
2020-02-01 23:06:01 +01:00
/** \class cmQtAutoGenerator
* \brief Initializes the QtAutoGen generators
*/
2018-04-23 21:13:27 +02:00
class cmQtAutoGenInitializer : public cmQtAutoGen
{
public:
2020-02-01 23:06:01 +01:00
/** String value with per configuration variants. */
class ConfigString
{
public:
std::string Default;
std::unordered_map<std::string, std::string> Config;
};
/** String values with per configuration variants. */
template <typename C>
class ConfigStrings
{
public:
C Default;
std::unordered_map<std::string, C> Config;
};
/** rcc job. */
2018-04-23 21:13:27 +02:00
class Qrc
{
public:
2018-08-09 18:06:22 +02:00
std::string LockFile;
2018-04-23 21:13:27 +02:00
std::string QrcFile;
std::string QrcName;
2020-02-01 23:06:01 +01:00
std::string QrcPathChecksum;
2018-04-23 21:13:27 +02:00
std::string InfoFile;
2020-02-01 23:06:01 +01:00
ConfigString SettingsFile;
std::string OutputFile;
2019-11-11 23:01:05 +01:00
bool Generated = false;
bool Unique = false;
2018-04-23 21:13:27 +02:00
std::vector<std::string> Options;
std::vector<std::string> Resources;
};
2020-02-01 23:06:01 +01:00
/** moc and/or uic file. */
2019-11-11 23:01:05 +01:00
struct MUFile
{
2020-02-01 23:06:01 +01:00
std::string FullPath;
2019-11-11 23:01:05 +01:00
cmSourceFile* SF = nullptr;
2021-09-14 00:13:48 +02:00
std::vector<size_t> Configs;
2019-11-11 23:01:05 +01:00
bool Generated = false;
bool SkipMoc = false;
bool SkipUic = false;
bool MocIt = false;
bool UicIt = false;
};
2020-02-01 23:06:01 +01:00
using MUFileHandle = std::unique_ptr<MUFile>;
2019-11-11 23:01:05 +01:00
2020-02-01 23:06:01 +01:00
/** Abstract moc/uic/rcc generator variables base class. */
2019-11-11 23:01:05 +01:00
struct GenVarsT
{
bool Enabled = false;
// Generator type/name
GenT Gen;
2020-02-01 23:06:01 +01:00
cm::string_view GenNameUpper;
2019-11-11 23:01:05 +01:00
// Executable
std::string ExecutableTargetName;
cmGeneratorTarget* ExecutableTarget = nullptr;
std::string Executable;
CompilerFeaturesHandle ExecutableFeatures;
GenVarsT(GenT gen)
: Gen(gen)
2021-11-20 13:41:27 +01:00
, GenNameUpper(cmQtAutoGen::GeneratorNameUpper(gen))
{
}
2019-11-11 23:01:05 +01:00
};
2021-09-14 00:13:48 +02:00
/** @param mocExecutable The file path to the moc executable. Will be used as
fallback to query the version
@return The detected Qt version and the required Qt major version. */
2019-11-11 23:01:05 +01:00
static std::pair<IntegerVersion, unsigned int> GetQtVersion(
2021-09-14 00:13:48 +02:00
cmGeneratorTarget const* genTarget, std::string mocExecutable);
2018-10-28 12:09:07 +01:00
2019-11-11 23:01:05 +01:00
cmQtAutoGenInitializer(cmQtAutoGenGlobalInitializer* globalInitializer,
2020-02-01 23:06:01 +01:00
cmGeneratorTarget* genTarget,
2019-11-11 23:01:05 +01:00
IntegerVersion const& qtVersion, bool mocEnabled,
2018-04-23 21:13:27 +02:00
bool uicEnabled, bool rccEnabled,
2019-11-11 23:01:05 +01:00
bool globalAutogenTarget, bool globalAutoRccTarget);
2018-04-23 21:13:27 +02:00
2018-10-28 12:09:07 +01:00
bool InitCustomTargets();
bool SetupCustomTargets();
2018-04-23 21:13:27 +02:00
private:
2020-02-01 23:06:01 +01:00
/** If moc or uic is enabled, the autogen target will be generated. */
2019-11-11 23:01:05 +01:00
bool MocOrUicEnabled() const
{
return (this->Moc.Enabled || this->Uic.Enabled);
}
2018-10-28 12:09:07 +01:00
bool InitMoc();
bool InitUic();
bool InitRcc();
bool InitScanFiles();
bool InitAutogenTarget();
bool InitRccTargets();
bool SetupWriteAutogenInfo();
bool SetupWriteRccInfo();
2018-04-23 21:13:27 +02:00
2020-02-01 23:06:01 +01:00
cmSourceFile* RegisterGeneratedSource(std::string const& filename);
cmSourceFile* AddGeneratedSource(std::string const& filename,
GenVarsT const& genVars,
bool prepend = false);
2021-09-14 00:13:48 +02:00
void AddGeneratedSource(ConfigString const& filename,
GenVarsT const& genVars, bool prepend = false);
2020-02-01 23:06:01 +01:00
void AddToSourceGroup(std::string const& fileName,
cm::string_view genNameUpper);
2019-11-11 23:01:05 +01:00
void AddCleanFile(std::string const& fileName);
2018-04-23 21:13:27 +02:00
2020-02-01 23:06:01 +01:00
void ConfigFileNames(ConfigString& configString, cm::string_view prefix,
cm::string_view suffix);
2021-09-14 00:13:48 +02:00
void ConfigFileNamesAndGenex(ConfigString& configString, std::string& genex,
cm::string_view prefix, cm::string_view suffix);
2020-02-01 23:06:01 +01:00
void ConfigFileClean(ConfigString& configString);
std::string GetMocBuildPath(MUFile const& muf);
2019-11-11 23:01:05 +01:00
bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
bool ignoreMissingTarget) const;
2018-04-23 21:13:27 +02:00
2022-11-16 20:14:03 +01:00
void handleSkipPch(cmSourceFile* sf);
2020-02-01 23:06:01 +01:00
cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
cmGeneratorTarget* GenTarget = nullptr;
cmGlobalGenerator* GlobalGen = nullptr;
cmLocalGenerator* LocalGen = nullptr;
cmMakefile* Makefile = nullptr;
cmFilePathChecksum const PathCheckSum;
// -- Configuration
2018-10-28 12:09:07 +01:00
IntegerVersion QtVersion;
2020-02-01 23:06:01 +01:00
unsigned int Verbosity = 0;
2018-10-28 12:09:07 +01:00
bool MultiConfig = false;
2020-02-01 23:06:01 +01:00
bool CMP0071Accept = false;
bool CMP0071Warn = false;
2020-08-30 11:54:41 +02:00
bool CMP0100Accept = false;
bool CMP0100Warn = false;
2018-04-23 21:13:27 +02:00
std::string ConfigDefault;
std::vector<std::string> ConfigsList;
2018-10-28 12:09:07 +01:00
std::string TargetsFolder;
2020-02-01 23:06:01 +01:00
/** Common directories. */
2018-10-28 12:09:07 +01:00
struct
{
std::string Info;
std::string Build;
2022-08-04 22:12:04 +02:00
std::string RelativeBuild;
2018-10-28 12:09:07 +01:00
std::string Work;
2020-02-01 23:06:01 +01:00
ConfigString Include;
std::string IncludeGenExp;
2018-10-28 12:09:07 +01:00
} Dir;
2020-02-01 23:06:01 +01:00
/** Autogen target variables. */
2018-10-28 12:09:07 +01:00
struct
{
std::string Name;
2019-11-11 23:01:05 +01:00
bool GlobalTarget = false;
2018-10-28 12:09:07 +01:00
// Settings
2020-02-01 23:06:01 +01:00
unsigned int Parallel = 1;
2018-10-28 12:09:07 +01:00
// Configuration files
std::string InfoFile;
2020-02-01 23:06:01 +01:00
ConfigString SettingsFile;
ConfigString ParseCacheFile;
2018-10-28 12:09:07 +01:00
// Dependencies
2019-11-11 23:01:05 +01:00
bool DependOrigin = false;
2018-10-28 12:09:07 +01:00
std::set<std::string> DependFiles;
std::set<cmTarget*> DependTargets;
2020-08-30 11:54:41 +02:00
std::string DepFile;
std::string DepFileRuleName;
2018-10-28 12:09:07 +01:00
// Sources to process
2019-11-11 23:01:05 +01:00
std::unordered_map<cmSourceFile*, MUFileHandle> Headers;
std::unordered_map<cmSourceFile*, MUFileHandle> Sources;
std::vector<MUFile*> FilesGenerated;
2020-08-30 11:54:41 +02:00
std::vector<cmSourceFile*> CMP0100HeadersWarn;
2018-10-28 12:09:07 +01:00
} AutogenTarget;
2020-02-01 23:06:01 +01:00
/** moc variables. */
2019-11-11 23:01:05 +01:00
struct MocT : public GenVarsT
2018-10-28 12:09:07 +01:00
{
2019-11-11 23:01:05 +01:00
MocT()
2021-11-20 13:41:27 +01:00
: GenVarsT(GenT::MOC)
{
}
2020-02-01 23:06:01 +01:00
bool RelaxedMode = false;
bool PathPrefix = false;
2021-09-14 00:13:48 +02:00
ConfigString CompilationFile;
std::string CompilationFileGenex;
2020-02-01 23:06:01 +01:00
// Compiler implicit pre defines
std::vector<std::string> PredefsCmd;
ConfigString PredefsFile;
// Defines
ConfigStrings<std::set<std::string>> Defines;
// Includes
ConfigStrings<std::vector<std::string>> Includes;
// Options
std::vector<std::string> Options;
// Filters
std::vector<std::string> MacroNames;
std::vector<std::pair<std::string, std::string>> DependFilters;
// Utility
std::unordered_set<std::string> EmittedBuildPaths;
2018-10-28 12:09:07 +01:00
} Moc;
2020-02-01 23:06:01 +01:00
/** uic variables. */
2019-11-11 23:01:05 +01:00
struct UicT : public GenVarsT
2018-10-28 12:09:07 +01:00
{
2020-02-01 23:06:01 +01:00
using UiFileT = std::pair<std::string, std::vector<std::string>>;
2019-11-11 23:01:05 +01:00
UicT()
2021-11-20 13:41:27 +01:00
: GenVarsT(GenT::UIC)
{
}
2020-02-01 23:06:01 +01:00
std::set<std::string> SkipUi;
2021-09-14 00:13:48 +02:00
std::vector<std::string> UiFilesNoOptions;
std::vector<UiFileT> UiFilesWithOptions;
2020-02-01 23:06:01 +01:00
ConfigStrings<std::vector<std::string>> Options;
std::vector<std::string> SearchPaths;
2021-09-14 00:13:48 +02:00
std::vector<std::pair<ConfigString /*ui header*/, std::string /*genex*/>>
UiHeaders;
2018-10-28 12:09:07 +01:00
} Uic;
2020-02-01 23:06:01 +01:00
/** rcc variables. */
2019-11-11 23:01:05 +01:00
struct RccT : public GenVarsT
2018-10-28 12:09:07 +01:00
{
2019-11-11 23:01:05 +01:00
RccT()
2021-11-20 13:41:27 +01:00
: GenVarsT(GenT::RCC)
{
}
2020-02-01 23:06:01 +01:00
bool GlobalTarget = false;
std::vector<Qrc> Qrcs;
2018-10-28 12:09:07 +01:00
} Rcc;
2018-04-23 21:13:27 +02:00
};