Autogen: Keep stderr out of the generated moc_predefs.h

The stdout of CMAKE_CXX_COMPILER_PREDEFINES_COMMAND is written to
moc_predefs.h verbatim, so whatever the command prints on stderr must
not be mixed in. MSVC-like compilers echo the name of the source file
they preprocess. Run the job with separate streams and report both
streams when the command fails.

Issue: #28093
This commit is contained in:
Joerg Bornemann
2026-09-18 11:34:49 +02:00
parent 1c1258ad95
commit 4a4a654814
+10 -6
View File
@@ -359,7 +359,8 @@ public:
/** @brief Run an external process. Use only during Process() call! */
bool RunProcess(GenT genType, cmWorkerPool::ProcessResultT& result,
std::vector<std::string> const& command,
std::string* infoMessage = nullptr);
std::string* infoMessage = nullptr,
bool mergedOutput = true);
};
/** Fence job utility class. */
@@ -863,7 +864,8 @@ void cmQtAutoMocUicT::JobT::MaybeWriteResponseFile(
bool cmQtAutoMocUicT::JobT::RunProcess(GenT genType,
cmWorkerPool::ProcessResultT& result,
std::vector<std::string> const& command,
std::string* infoMessage)
std::string* infoMessage,
bool mergedOutput)
{
// Log command
if (this->Log().Verbose()) {
@@ -878,7 +880,7 @@ bool cmQtAutoMocUicT::JobT::RunProcess(GenT genType,
}
// Run command
return this->cmWorkerPool::JobT::RunProcess(
result, command, this->BaseConst().AutogenBuildDir);
result, command, this->BaseConst().AutogenBuildDir, mergedOutput);
}
void cmQtAutoMocUicT::JobMocPredefsT::Process()
@@ -904,13 +906,15 @@ void cmQtAutoMocUicT::JobMocPredefsT::Process()
// Check if response file is necessary
MaybeWriteResponseFile(this->MocConst().PredefsFileAbs, cmd);
// Execute command
if (!this->RunProcess(GenT::MOC, result, cmd, reason.get())) {
// Execute command. Keep stderr out of the captured stdout, which is
// written to the predefs file verbatim: MSVC-like compilers echo the
// name of the source file they preprocess.
if (!this->RunProcess(GenT::MOC, result, cmd, reason.get(), false)) {
this->LogCommandError(GenT::MOC,
cmStrCat("The content generation command for ",
this->MessagePath(predefsFileAbs),
" failed.\n", result.ErrorMessage),
cmd, result.StdOut);
cmd, result.StdOut + result.StdErr);
return;
}
}