From cab631c2e242ff74a1bddd973b5aafe9b6f4ebd5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 26 Jan 2022 07:23:29 -0500 Subject: NMake: Document response file encoding heuristic in a comment Since commit f3f57cc4ed (NMake: Use UTF-8 with BOM if supported by nmake, 2021-04-22, v3.21.0-rc1~217^2) the encoding of response files is selected based on the makefile encoding. In principle these may be orthogonal, but in practice it is a useful heuristic. Call out this heuristic in a comment, and leave a FIXME to do something better. --- Source/cmMakefileTargetGenerator.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index a3e5553..add9c01 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -16,6 +16,8 @@ #include #include +#include "cm_codecvt.hxx" + #include "cmComputeLinkInformation.h" #include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" @@ -2046,11 +2048,17 @@ std::string cmMakefileTargetGenerator::CreateResponseFile( const char* name, std::string const& options, std::vector& makefile_depends) { + // FIXME: Find a better way to determine the response file encoding, + // perhaps using tool-specific platform information variables. + // For now, use the makefile encoding as a heuristic. + codecvt::Encoding responseEncoding = + this->GlobalGenerator->GetMakefileEncoding(); + // Create the response file. std::string responseFileNameFull = cmStrCat(this->TargetBuildDirectoryFull, '/', name); - cmGeneratedFileStream responseStream( - responseFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding()); + cmGeneratedFileStream responseStream(responseFileNameFull, false, + responseEncoding); responseStream.SetCopyIfDifferent(true); responseStream << options << "\n"; -- cgit v0.12 From d5ee6d50ee71f78dc619001e86e69f23444acfa9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 26 Jan 2022 07:24:02 -0500 Subject: NMake: Use UTF-8 BOM in response files only with MSVC tooling Since commit f3f57cc4ed (NMake: Use UTF-8 with BOM if supported by nmake, 2021-04-22, v3.21.0-rc1~217^2), we add a BOM to response files to tell MSVC tooling that they are encoded as UTF-8. However, the "NMake Makefiles" generator may also be used with non-MSVC toolchains that do not understand the BOM. Update the response file encoding selection heuristic to add the BOM only with MSVC tooling. Fixes: #23143 --- Source/cmMakefileTargetGenerator.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index add9c01..9458277 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -2053,6 +2053,11 @@ std::string cmMakefileTargetGenerator::CreateResponseFile( // For now, use the makefile encoding as a heuristic. codecvt::Encoding responseEncoding = this->GlobalGenerator->GetMakefileEncoding(); + // Non-MSVC tooling may not understand a BOM. + if (responseEncoding == codecvt::UTF8_WITH_BOM && + !this->Makefile->IsOn("MSVC")) { + responseEncoding = codecvt::UTF8; + } // Create the response file. std::string responseFileNameFull = -- cgit v0.12