summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAmine Najahi <anajahi@mathworks.com>2021-04-22 20:26:30 +0100
committerBrad King <brad.king@kitware.com>2021-05-05 10:56:49 -0400
commitf3f57cc4edd528aaf0b8d8633d5f9990f0d804af (patch)
tree3ca9148977b9d0044fc5524e9fd3c1f93adeecad /Source
parent186c9bff5342c1e8e73fce9cf361b6de5dda3f28 (diff)
downloadcmake-f3f57cc4edd528aaf0b8d8633d5f9990f0d804af.tar.gz
NMake: Use UTF-8 with BOM if supported by nmake
Fixes: #21792
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratedFileStream.cxx5
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.h2
-rw-r--r--Source/cmMakefileTargetGenerator.cxx3
-rw-r--r--Source/cm_codecvt.cxx1
-rw-r--r--Source/cm_codecvt.hxx1
5 files changed, 10 insertions, 2 deletions
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 43f384ab08..06778b1ebc 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -42,6 +42,11 @@ cmGeneratedFileStream::cmGeneratedFileStream(std::string const& name,
#else
static_cast<void>(encoding);
#endif
+ if (encoding == codecvt::UTF8_WITH_BOM) {
+ // Write the BOM encoding header into the file
+ char magic[] = { char(0xEF), char(0xBB), char(0xBF) };
+ this->write(magic, 3);
+ }
}
cmGeneratedFileStream::~cmGeneratedFileStream()
diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h
index ed52378347..402b89fda9 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.h
+++ b/Source/cmGlobalNMakeMakefileGenerator.h
@@ -31,7 +31,7 @@ public:
/** Get encoding used by generator for makefile files */
codecvt::Encoding GetMakefileEncoding() const override
{
- return codecvt::ANSI;
+ return this->NMakeSupportsUTF8 ? codecvt::UTF8_WITH_BOM : codecvt::ANSI;
}
/** Get the documentation entry for this generator. */
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index fa469edac3..5b6c58dfb2 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -2058,7 +2058,8 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
// Create the response file.
std::string responseFileNameFull =
cmStrCat(this->TargetBuildDirectoryFull, '/', name);
- cmGeneratedFileStream responseStream(responseFileNameFull);
+ cmGeneratedFileStream responseStream(
+ responseFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding());
responseStream.SetCopyIfDifferent(true);
responseStream << options << "\n";
diff --git a/Source/cm_codecvt.cxx b/Source/cm_codecvt.cxx
index 15f83e0f78..216d3f0175 100644
--- a/Source/cm_codecvt.cxx
+++ b/Source/cm_codecvt.cxx
@@ -31,6 +31,7 @@ codecvt::codecvt(Encoding e)
// We don't know which ANSI encoding to use for other platforms than
// Windows so we don't do any conversion there
case codecvt::UTF8:
+ case codecvt::UTF8_WITH_BOM:
// Assume internal encoding is UTF-8
case codecvt::None:
// No encoding
diff --git a/Source/cm_codecvt.hxx b/Source/cm_codecvt.hxx
index 1860211a15..b73204f2aa 100644
--- a/Source/cm_codecvt.hxx
+++ b/Source/cm_codecvt.hxx
@@ -14,6 +14,7 @@ public:
{
None,
UTF8,
+ UTF8_WITH_BOM,
ANSI
};