1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-18 17:31:57 +08:00

Ninja: Write msvc_deps_prefix as UTF-8 when console codepage is UTF-8

This commit is contained in:
Ben McMorran
2020-07-31 17:37:26 -07:00
parent 67599c7ada
commit 37a279f8d1

View File

@@ -84,8 +84,26 @@ void cmLocalNinjaGenerator::Generate()
if (!showIncludesPrefix.empty()) {
cmGlobalNinjaGenerator::WriteComment(this->GetRulesFileStream(),
"localized /showIncludes string");
this->GetRulesFileStream()
<< "msvc_deps_prefix = " << showIncludesPrefix << "\n\n";
this->GetRulesFileStream() << "msvc_deps_prefix = ";
#ifdef WIN32
// Ninja uses the ANSI Windows APIs, so strings in the rules file
// typically need to be ANSI encoded. However, in this case the compiler
// is being invoked using the UTF-8 codepage so the /showIncludes prefix
// will be UTF-8 encoded on stdout. Ninja can't successfully compare this
// UTF-8 encoded prefix to the ANSI encoded msvc_deps_prefix if it
// contains any non-ASCII characters and dependency checking will fail.
// As a workaround, leave the msvc_deps_prefix UTF-8 encoded even though
// the rest of the file is ANSI encoded.
if (GetConsoleOutputCP() == CP_UTF8 && GetACP() != CP_UTF8) {
this->GetRulesFileStream().WriteRaw(showIncludesPrefix);
} else {
this->GetRulesFileStream() << showIncludesPrefix;
}
#else
// It's safe to use the standard encoding on other platforms.
this->GetRulesFileStream() << showIncludesPrefix;
#endif
this->GetRulesFileStream() << "\n\n";
}
}