cmcmd: Clarify comment explaining vs_link_{exe,dll} output encoding

Revise the comment from commit 7e359823c9 (MSVC: Preserve linker output
encoding, 2018-08-03, v3.13.0-rc1~223^2) to more clearly explain why we
need to write output using a `cmConsoleBuf` without `SetUTF8Pipes`.
This commit is contained in:
Brad King
2025-04-17 16:12:52 -04:00
parent 407363abd0
commit c11c86c098

View File

@@ -2221,10 +2221,16 @@ private:
// still works.
int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type)
{
// Replace streambuf so we output in the system codepage. CMake is set up
// to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker
// outputs using the system codepage so we need to change behavior when
// we run the link command.
// MSVC tools print output in the language specified by the VSLANG
// environment variable, and encoded in the console output code page.
// RunCommand captures and converts it to our internal UTF-8 encoding.
// Then we print it as output through cmConsoleBuf:
// - NMake: Our output goes to a real console. cmConsoleBuf writes
// with WriteConsoleW, so no narrow encoding code page is needed.
// - Ninja: Our output goes to a pipe that ninja buffers and prints again.
// It does not convert encoding, so we must print in the console output
// code page even though it goes to a pipe.
// Both cases can be handled using a cmConsoleBuf without SetUTF8Pipes.
cmConsoleBuf consoleBuf;
if (args.size() < 2) {