Commit 7891f69c authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'autogen_cmStrCat'

ca292311 Autogen: Modernize to use cmStrCat for string concatenation
d02a99d9 Autogen: Modernize code to use cm::string_view for the info writer
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3663
parents 6f3c429e ca292311
......@@ -353,9 +353,8 @@ bool cmQtAutoGen::RccLister::list(std::string const& qrcFile,
// Log command
if (verbose) {
std::string msg = "Running command:\n";
msg += QuotedCommand(cmd);
msg += '\n';
std::string msg =
cmStrCat("Running command:\n", QuotedCommand(cmd), '\n');
cmSystemTools::Stdout(msg);
}
......
/* 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 "cmQtAutoGen.h"
#include "cmQtAutoGenInitializer.h"
#include "cmCustomCommandLines.h"
#include "cmDuration.h"
......@@ -11,15 +9,18 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmProcessOutput.h"
#include "cmQtAutoGen.h"
#include "cmQtAutoGenInitializer.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include <utility>
#include "cm_memory.hxx"
#include <utility>
cmQtAutoGenGlobalInitializer::Keywords::Keywords()
: AUTOMOC("AUTOMOC")
, AUTOUIC("AUTOUIC")
......@@ -119,23 +120,17 @@ cmQtAutoGenGlobalInitializer::cmQtAutoGenGlobalInitializer(
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 += ". ";
msg += cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled);
msg += " disabled. Consider adding:\n";
{
std::string version = (qtVersion.second == 0)
? std::string("<QTVERSION>")
: std::to_string(qtVersion.second);
std::string comp = uicDisabled ? "Widgets" : "Core";
msg += " find_package(Qt";
msg += version;
msg += " COMPONENTS ";
msg += comp;
msg += ")\n";
}
msg += "to your CMakeLists.txt file.";
cmAlphaNum version = (qtVersion.second == 0)
? cmAlphaNum("<QTVERSION>")
: cmAlphaNum(qtVersion.second);
cmAlphaNum component = uicDisabled ? "Widgets" : "Core";
std::string const msg = cmStrCat(
"AUTOGEN: No valid Qt version found for target ",
target->GetName(), ". ",
cmQtAutoGen::Tools(mocDisabled, uicDisabled, rccDisabled),
" disabled. Consider adding:\n", " find_package(Qt", version,
" COMPONENTS ", component, ")\n", "to your CMakeLists.txt file.");
target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
}
if (mocIsValid || uicIsValid || rccIsValid) {
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGeneratedFileStream.h"
#include "cmQtAutoGen.h"
#include "cm_string_view.hxx"
#include <map>
#include <memory>
......@@ -85,24 +86,24 @@ public:
/// @return True if the file is open
explicit operator bool() const { return static_cast<bool>(Ofs_); }
void Write(const char* text) { Ofs_ << text; }
void Write(const char* key, std::string const& value);
void WriteUInt(const char* key, unsigned int value);
void Write(cm::string_view text) { Ofs_ << text; }
void Write(cm::string_view, std::string const& value);
void WriteUInt(cm::string_view, unsigned int value);
template <class C>
void WriteStrings(const char* key, C const& container);
void WriteConfig(const char* key,
void WriteStrings(cm::string_view, C const& container);
void WriteConfig(cm::string_view,
std::map<std::string, std::string> const& map);
template <class C>
void WriteConfigStrings(const char* key,
void WriteConfigStrings(cm::string_view,
std::map<std::string, C> const& map);
void WriteNestedLists(const char* key,
void WriteNestedLists(cm::string_view,
std::vector<std::vector<std::string>> const& lists);
private:
template <class IT>
static std::string ListJoin(IT it_begin, IT it_end);
static std::string ConfigKey(const char* key, std::string const& config);
static std::string ConfigKey(cm::string_view, std::string const& config);
private:
cmGeneratedFileStream Ofs_;
......
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmQtAutoGenerator.h"
#include "cmQtAutoGen.h"
#include "cmsys/FStream.hxx"
#include "cm_memory.hxx"
#include "cmsys/FStream.hxx"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmQtAutoGen.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
......@@ -60,19 +60,13 @@ void cmQtAutoGenerator::Logger::SetColorOutput(bool value)
std::string cmQtAutoGenerator::Logger::HeadLine(std::string const& title)
{
std::string head = title;
head += '\n';
head.append(head.size() - 1, '-');
head += '\n';
return head;
return cmStrCat(title, "\n", std::string(title.size(), '-'), "\n");
}
void cmQtAutoGenerator::Logger::Info(GenT genType,
std::string const& message) const
{
std::string msg = GeneratorName(genType);
msg += ": ";
msg += message;
std::string msg = cmStrCat(GeneratorName(genType), ": ", message);
if (msg.back() != '\n') {
msg.push_back('\n');
}
......@@ -110,19 +104,13 @@ void cmQtAutoGenerator::Logger::WarningFile(GenT genType,
std::string const& filename,
std::string const& message) const
{
std::string msg = " ";
msg += Quoted(filename);
msg.push_back('\n');
// Message
msg += message;
Warning(genType, msg);
Warning(genType, cmStrCat(" ", Quoted(filename), "\n", message));
}
void cmQtAutoGenerator::Logger::Error(GenT genType,
std::string const& message) const
{
std::string msg;
msg += HeadLine(GeneratorName(genType) + " error");
std::string msg = HeadLine(GeneratorName(genType) + " error");
// Message
msg += message;
if (msg.back() != '\n') {
......@@ -139,12 +127,7 @@ void cmQtAutoGenerator::Logger::ErrorFile(GenT genType,
std::string const& filename,
std::string const& message) const
{
std::string emsg = " ";
emsg += Quoted(filename);
emsg += '\n';
// Message
emsg += message;
Error(genType, emsg);
Error(genType, cmStrCat(" ", Quoted(filename), '\n', message));
}
void cmQtAutoGenerator::Logger::ErrorCommand(
......@@ -280,10 +263,8 @@ bool cmQtAutoGenerator::Run(std::string const& infoFile,
InfoFile_ = infoFile;
cmSystemTools::ConvertToUnixSlashes(InfoFile_);
if (!InfoFileTime_.Load(InfoFile_)) {
std::string msg = "AutoGen: The info file ";
msg += Quoted(InfoFile_);
msg += " is not readable\n";
cmSystemTools::Stderr(msg);
cmSystemTools::Stderr(cmStrCat("AutoGen: The info file ",
Quoted(InfoFile_), " is not readable\n"));
return false;
}
InfoDir_ = cmSystemTools::GetFilenamePath(infoFile);
......
This diff is collapsed.
......@@ -36,9 +36,7 @@ bool cmQtAutoRcc::Init(cmMakefile* makefile)
this](std::string const& key) -> std::string {
const char* valueConf = nullptr;
{
std::string keyConf = key;
keyConf += '_';
keyConf += InfoConfig();
std::string keyConf = cmStrCat(key, '_', InfoConfig());
valueConf = makefile->GetDefinition(keyConf);
}
if (valueConf == nullptr) {
......@@ -82,9 +80,8 @@ bool cmQtAutoRcc::Init(cmMakefile* makefile)
// - Rcc executable
RccExecutable_ = InfoGet("ARCC_RCC_EXECUTABLE");
if (!RccExecutableTime_.Load(RccExecutable_)) {
std::string error = "The rcc executable ";
error += Quoted(RccExecutable_);
error += " does not exist.";
std::string error = cmStrCat("The rcc executable ", Quoted(RccExecutable_),
" does not exist.");
return LogInfoError(error);
}
RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS");
......@@ -179,10 +176,8 @@ bool cmQtAutoRcc::Process()
std::string cmQtAutoRcc::MultiConfigOutput() const
{
static std::string const suffix = "_CMAKE_";
std::string res;
res += RccPathChecksum_;
res += '/';
res += AppendFilenameSuffix(RccFileName_, suffix);
std::string res = cmStrCat(RccPathChecksum_, '/',
AppendFilenameSuffix(RccFileName_, suffix));
return res;
}
......@@ -273,9 +268,7 @@ bool cmQtAutoRcc::SettingsFileWrite()
Log().Info(GenT::RCC, "Writing settings file " + Quoted(SettingsFile_));
}
// Write settings file
std::string content = "rcc:";
content += SettingsString_;
content += '\n';
std::string content = cmStrCat("rcc:", SettingsString_, '\n');
std::string error;
if (!FileWrite(SettingsFile_, content, &error)) {
Log().ErrorFile(GenT::RCC, SettingsFile_,
......@@ -403,10 +396,9 @@ bool cmQtAutoRcc::TestInfoFile()
// Test if the rcc output file is older than the info file
if (RccFileTime_.Older(InfoFileTime())) {
if (Log().Verbose()) {
std::string reason = "Touching ";
reason += Quoted(RccFileOutput_);
reason += " because it is older than ";
reason += Quoted(InfoFile());
std::string reason =
cmStrCat("Touching ", Quoted(RccFileOutput_),
" because it is older than ", Quoted(InfoFile()));
Log().Info(GenT::RCC, reason);
}
// Touch build file
......@@ -457,10 +449,9 @@ bool cmQtAutoRcc::GenerateRcc()
if (!result || (retVal != 0)) {
// rcc process failed
{
std::string err = "The rcc process failed to compile\n ";
err += Quoted(QrcFile_);
err += "\ninto\n ";
err += Quoted(RccFileOutput_);
std::string err =
cmStrCat("The rcc process failed to compile\n ", Quoted(QrcFile_),
"\ninto\n ", Quoted(RccFileOutput_));
Log().ErrorCommand(GenT::RCC, err, cmd, rccStdOut + rccStdErr);
}
cmSystemTools::RemoveFile(RccFileOutput_);
......@@ -482,12 +473,10 @@ bool cmQtAutoRcc::GenerateWrapper()
// Generate a wrapper source file on demand
if (IsMultiConfig()) {
// Wrapper file content
std::string content;
content += "// This is an autogenerated configuration wrapper file.\n";
content += "// Changes will be overwritten.\n";
content += "#include <";
content += MultiConfigOutput();
content += ">\n";
std::string content =
cmStrCat("// This is an autogenerated configuration wrapper file.\n",
"// Changes will be overwritten.\n", "#include <",
MultiConfigOutput(), ">\n");
// Compare with existing file content
bool fileDiffers = true;
......
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