summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-05-06 14:12:50 +0000
committerKitware Robot <kwrobot@kitware.com>2021-05-06 10:13:11 -0400
commite0b4a22ca6874a15912eea86cde16f47cb5f9d93 (patch)
tree4dc101c0e51a28eaae670e147ad5c80a4320e229 /Source
parent6785df1b0623d112d3d4acd1ed1cad20032adf64 (diff)
parentf3f57cc4edd528aaf0b8d8633d5f9990f0d804af (diff)
downloadcmake-e0b4a22ca6874a15912eea86cde16f47cb5f9d93.tar.gz
Merge topic 'nmake-utf8'
f3f57cc4ed NMake: Use UTF-8 with BOM if supported by nmake 186c9bff53 NMake: Check nmake version for support of UTF-8 8a4f536be6 NMake: Detect nmake version Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6041
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratedFileStream.cxx5
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.cxx41
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.h7
-rw-r--r--Source/cmMakefileTargetGenerator.cxx3
-rw-r--r--Source/cm_codecvt.cxx1
-rw-r--r--Source/cm_codecvt.hxx1
6 files changed, 56 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.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx
index 36f583f014..313f39b5e8 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.cxx
+++ b/Source/cmGlobalNMakeMakefileGenerator.cxx
@@ -2,7 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalNMakeMakefileGenerator.h"
+#include "cmsys/RegularExpression.hxx"
+
#include "cmDocumentationEntry.h"
+#include "cmDuration.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmState.h"
@@ -34,6 +37,44 @@ void cmGlobalNMakeMakefileGenerator::EnableLanguage(
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
}
+bool cmGlobalNMakeMakefileGenerator::FindMakeProgram(cmMakefile* mf)
+{
+ if (!this->cmGlobalGenerator::FindMakeProgram(mf)) {
+ return false;
+ }
+ if (cmProp nmakeCommand = mf->GetDefinition("CMAKE_MAKE_PROGRAM")) {
+ std::vector<std::string> command;
+ command.emplace_back(*nmakeCommand);
+ command.emplace_back("-?");
+ std::string out;
+ std::string err;
+ if (!cmSystemTools::RunSingleCommand(command, &out, &err, nullptr, nullptr,
+ cmSystemTools::OUTPUT_NONE,
+ cmDuration(30))) {
+ mf->IssueMessage(MessageType::FATAL_ERROR,
+ cmStrCat("Running\n '", cmJoin(command, "' '"),
+ "'\n"
+ "failed with:\n ",
+ err));
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ cmsys::RegularExpression regex(
+ "Program Maintenance Utility Version ([1-9][0-9.]+)");
+ if (regex.find(err)) {
+ this->NMakeVersion = regex.match(1);
+ this->CheckNMakeFeatures();
+ }
+ }
+ return true;
+}
+
+void cmGlobalNMakeMakefileGenerator::CheckNMakeFeatures()
+{
+ this->NMakeSupportsUTF8 = !cmSystemTools::VersionCompare(
+ cmSystemTools::OP_LESS, this->NMakeVersion.c_str(), "9");
+}
+
void cmGlobalNMakeMakefileGenerator::GetDocumentation(
cmDocumentationEntry& entry)
{
diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h
index abe64ff963..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. */
@@ -55,6 +55,11 @@ protected:
void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
private:
+ bool NMakeSupportsUTF8 = false;
+ std::string NMakeVersion;
+ bool FindMakeProgram(cmMakefile* mf) override;
+ void CheckNMakeFeatures();
+
void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
const char* envVar) const override;
};
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
};