Autogen: Use cm::string_view for AUTO{MOC,UIC,RCC} generator names

- Store `AUTO{MOC,UIC,RCC}` generator name as `cm::string_view`
- Use `std::initializer_list` instead of `std::array`
This commit is contained in:
Sebastian Holtermann 2019-08-26 15:31:55 +02:00
parent 8586077baa
commit c797148e85
5 changed files with 44 additions and 47 deletions

View File

@ -76,44 +76,34 @@ void MergeOptions(std::vector<std::string>& baseOpts,
unsigned int const cmQtAutoGen::ParallelMax = 64;
std::string const cmQtAutoGen::ListSep = "<<<S>>>";
std::string const& cmQtAutoGen::GeneratorName(GenT genType)
cm::string_view cmQtAutoGen::GeneratorName(GenT genType)
{
static const std::string AutoGen("AutoGen");
static const std::string AutoMoc("AutoMoc");
static const std::string AutoUic("AutoUic");
static const std::string AutoRcc("AutoRcc");
switch (genType) {
case GenT::GEN:
return AutoGen;
return "AutoGen";
case GenT::MOC:
return AutoMoc;
return "AutoMoc";
case GenT::UIC:
return AutoUic;
return "AutoUic";
case GenT::RCC:
return AutoRcc;
return "AutoRcc";
}
return AutoGen;
return "AutoGen";
}
std::string const& cmQtAutoGen::GeneratorNameUpper(GenT genType)
cm::string_view cmQtAutoGen::GeneratorNameUpper(GenT genType)
{
static const std::string AUTOGEN("AUTOGEN");
static const std::string AUTOMOC("AUTOMOC");
static const std::string AUTOUIC("AUTOUIC");
static const std::string AUTORCC("AUTORCC");
switch (genType) {
case GenT::GEN:
return AUTOGEN;
return "AUTOGEN";
case GenT::MOC:
return AUTOMOC;
return "AUTOMOC";
case GenT::UIC:
return AUTOUIC;
return "AUTOUIC";
case GenT::RCC:
return AUTORCC;
return "AUTORCC";
}
return AUTOGEN;
return "AUTOGEN";
}
std::string cmQtAutoGen::Tools(bool moc, bool uic, bool rcc)

View File

@ -68,9 +68,9 @@ public:
public:
/// @brief Returns the generator name
static std::string const& GeneratorName(GenT genType);
static cm::string_view GeneratorName(GenT genType);
/// @brief Returns the generator name in upper case
static std::string const& GeneratorNameUpper(GenT genType);
static cm::string_view GeneratorNameUpper(GenT genType);
/// @brief Returns a string with the requested tool names
static std::string Tools(bool moc, bool uic, bool rcc);

View File

@ -29,8 +29,8 @@
#include "cmsys/SystemInformation.hxx"
#include <algorithm>
#include <array>
#include <deque>
#include <initializer_list>
#include <map>
#include <set>
#include <string>
@ -696,7 +696,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
std::vector<MUFileHandle> extraHeaders;
extraHeaders.reserve(this->AutogenTarget.Sources.size() * 2);
// Header search suffixes and extensions
std::array<std::string, 2> const suffixes{ { "", "_p" } };
static std::initializer_list<cm::string_view> const suffixes{ "", "_p" };
auto const& exts = cm->GetHeaderExtensions();
// Scan through sources
for (auto const& pair : this->AutogenTarget.Sources) {
@ -708,7 +708,7 @@ bool cmQtAutoGenInitializer::InitScanFiles()
cmStrCat(cmQtAutoGen::SubDirPrefix(srcPath),
cmSystemTools::GetFilenameWithoutLastExtension(srcPath));
for (auto const& suffix : suffixes) {
std::string const suffixedPath = basePath + suffix;
std::string const suffixedPath = cmStrCat(basePath, suffix);
for (auto const& ext : exts) {
std::string fullPath = cmStrCat(suffixedPath, '.', ext);
@ -1454,7 +1454,7 @@ bool cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename,
}
bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
std::string const& genNameUpper)
cm::string_view genNameUpper)
{
cmMakefile* makefile = this->Target->Target->GetMakefile();
cmSourceGroup* sourceGroup = nullptr;
@ -1464,13 +1464,14 @@ bool cmQtAutoGenInitializer::AddToSourceGroup(std::string const& fileName,
std::string groupName;
{
// Prefer generator specific source group name
std::array<std::string, 2> props{ { genNameUpper + "_SOURCE_GROUP",
"AUTOGEN_SOURCE_GROUP" } };
for (std::string& prop : props) {
std::initializer_list<std::string> const props{
cmStrCat(genNameUpper, "_SOURCE_GROUP"), "AUTOGEN_SOURCE_GROUP"
};
for (std::string const& prop : props) {
const char* propName = makefile->GetState()->GetGlobalProperty(prop);
if ((propName != nullptr) && (*propName != '\0')) {
groupName = propName;
property = std::move(prop);
property = prop;
break;
}
}
@ -1512,11 +1513,16 @@ static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
cmGeneratorTarget const* target)
{
// Qt version variable prefixes
static std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core",
"QT" } };
static std::initializer_list<
std::pair<cm::string_view, cm::string_view>> const keys{
{ "Qt6Core_VERSION_MAJOR", "Qt6Core_VERSION_MINOR" },
{ "Qt5Core_VERSION_MAJOR", "Qt5Core_VERSION_MINOR" },
{ "QT_VERSION_MAJOR", "QT_VERSION_MINOR" },
};
std::vector<cmQtAutoGen::IntegerVersion> result;
result.reserve(prefixes.size() * 2);
result.reserve(keys.size() * 2);
// Adds a version to the result (nullptr safe)
auto addVersion = [&result](const char* major, const char* minor) {
cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major),
@ -1525,18 +1531,19 @@ static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions(
result.emplace_back(ver);
}
};
cmMakefile* makefile = target->Target->GetMakefile();
// Read versions from variables
for (const std::string& prefix : prefixes) {
addVersion(makefile->GetDefinition(prefix + "_VERSION_MAJOR"),
makefile->GetDefinition(prefix + "_VERSION_MINOR"));
for (auto const& keyPair : keys) {
addVersion(makefile->GetDefinition(std::string(keyPair.first)),
makefile->GetDefinition(std::string(keyPair.second)));
}
// Read versions from directory properties
for (const std::string& prefix : prefixes) {
addVersion(makefile->GetProperty(prefix + "_VERSION_MAJOR"),
makefile->GetProperty(prefix + "_VERSION_MINOR"));
for (auto const& keyPair : keys) {
addVersion(makefile->GetProperty(std::string(keyPair.first)),
makefile->GetProperty(std::string(keyPair.second)));
}
return result;
@ -1580,7 +1587,7 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
// Custom executable
{
std::string const prop = genVars.GenNameUpper + "_EXECUTABLE";
std::string const prop = cmStrCat(genVars.GenNameUpper, "_EXECUTABLE");
std::string const val = this->Target->Target->GetSafeProperty(prop);
if (!val.empty()) {
// Evaluate generator expression

View File

@ -63,7 +63,7 @@ public:
bool Enabled = false;
// Generator type/name
GenT Gen;
std::string const& GenNameUpper;
cm::string_view GenNameUpper;
// Executable
std::string ExecutableTargetName;
cmGeneratorTarget* ExecutableTarget = nullptr;
@ -145,7 +145,7 @@ private:
bool AddGeneratedSource(std::string const& filename, GenVarsT const& genVars,
bool prepend = false);
bool AddToSourceGroup(std::string const& fileName,
std::string const& genNameUpper);
cm::string_view genNameUpper);
void AddCleanFile(std::string const& fileName);
bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,

View File

@ -86,7 +86,7 @@ void cmQtAutoGenerator::Logger::Warning(GenT genType,
msg += " warning: ";
} else {
// Multi line message
msg += HeadLine(GeneratorName(genType) + " warning");
msg += HeadLine(cmStrCat(GeneratorName(genType), " warning"));
}
// Message
msg += message;
@ -110,7 +110,7 @@ void cmQtAutoGenerator::Logger::WarningFile(GenT genType,
void cmQtAutoGenerator::Logger::Error(GenT genType,
std::string const& message) const
{
std::string msg = HeadLine(GeneratorName(genType) + " error");
std::string msg = HeadLine(cmStrCat(GeneratorName(genType), " error"));
// Message
msg += message;
if (msg.back() != '\n') {
@ -136,7 +136,7 @@ void cmQtAutoGenerator::Logger::ErrorCommand(
{
std::string msg;
msg.push_back('\n');
msg += HeadLine(GeneratorName(genType) + " subprocess error");
msg += HeadLine(cmStrCat(GeneratorName(genType), " subprocess error"));
msg += message;
if (msg.back() != '\n') {
msg.push_back('\n');