codecvt: Extrace codecvt::Encoding to remove codecvt includes
parent
64821d8a26
commit
1bb0e59318
|
@ -10,7 +10,7 @@
|
|||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmDebuggerStackFrame.h"
|
||||
#include "cmDebuggerVariables.h"
|
||||
|
@ -578,17 +578,17 @@ std::shared_ptr<cmDebuggerVariables> cmDebuggerVariablesHelper::CreateIfAny(
|
|||
return {};
|
||||
}
|
||||
|
||||
auto makeFileEncodingString = [](codecvt::Encoding encoding) {
|
||||
auto makeFileEncodingString = [](codecvt_Encoding encoding) {
|
||||
switch (encoding) {
|
||||
case codecvt::Encoding::None:
|
||||
case codecvt_Encoding::None:
|
||||
return "None";
|
||||
case codecvt::Encoding::UTF8:
|
||||
case codecvt_Encoding::UTF8:
|
||||
return "UTF8";
|
||||
case codecvt::Encoding::UTF8_WITH_BOM:
|
||||
case codecvt_Encoding::UTF8_WITH_BOM:
|
||||
return "UTF8_WITH_BOM";
|
||||
case codecvt::Encoding::ANSI:
|
||||
case codecvt_Encoding::ANSI:
|
||||
return "ANSI";
|
||||
case codecvt::Encoding::ConsoleOutput:
|
||||
case codecvt_Encoding::ConsoleOutput:
|
||||
return "ConsoleOutput";
|
||||
default:
|
||||
return "Unknown";
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding)
|
||||
{
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
if (encoding != codecvt::None) {
|
||||
if (encoding != codecvt_Encoding::None) {
|
||||
this->imbue(std::locale(this->getloc(), new codecvt(encoding)));
|
||||
}
|
||||
#else
|
||||
|
@ -35,13 +35,13 @@ cmGeneratedFileStream::cmGeneratedFileStream(std::string const& name,
|
|||
cmSystemTools::ReportLastSystemError("");
|
||||
}
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
if (encoding != codecvt::None) {
|
||||
if (encoding != codecvt_Encoding::None) {
|
||||
this->imbue(std::locale(this->getloc(), new codecvt(encoding)));
|
||||
}
|
||||
#else
|
||||
static_cast<void>(encoding);
|
||||
#endif
|
||||
if (encoding == codecvt::UTF8_WITH_BOM) {
|
||||
if (encoding == codecvt_Encoding::UTF8_WITH_BOM) {
|
||||
// Write the BOM encoding header into the file
|
||||
char magic[] = { static_cast<char>(0xEF), static_cast<char>(0xBB),
|
||||
static_cast<char>(0xBF) };
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "cmsys/FStream.hxx"
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
// This is the first base class of cmGeneratedFileStream. It will be
|
||||
// created before and destroyed after the ofstream portion and can
|
||||
|
@ -77,13 +77,13 @@ class cmGeneratedFileStream
|
|||
{
|
||||
public:
|
||||
using Stream = cmsys::ofstream;
|
||||
using Encoding = codecvt::Encoding;
|
||||
using Encoding = codecvt_Encoding;
|
||||
|
||||
/**
|
||||
* This constructor prepares a default stream. The open method must
|
||||
* be used before writing to the stream.
|
||||
*/
|
||||
cmGeneratedFileStream(Encoding encoding = codecvt::None);
|
||||
cmGeneratedFileStream(codecvt_Encoding encoding = codecvt_Encoding::None);
|
||||
|
||||
/**
|
||||
* This constructor takes the name of the file to be generated. It
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
* second argument is set to true.
|
||||
*/
|
||||
cmGeneratedFileStream(std::string const& name, bool quiet = false,
|
||||
Encoding encoding = codecvt::None);
|
||||
codecvt_Encoding encoding = codecvt_Encoding::None);
|
||||
|
||||
/**
|
||||
* The destructor checks the stream status to be sure the temporary
|
||||
|
@ -151,5 +151,5 @@ public:
|
|||
* Write a specific string using an alternate encoding.
|
||||
* Afterward, the original encoding is restored.
|
||||
*/
|
||||
void WriteAltEncoding(std::string const& data, Encoding encoding);
|
||||
void WriteAltEncoding(std::string const& data, codecvt_Encoding encoding);
|
||||
};
|
||||
|
|
|
@ -142,6 +142,10 @@ cmGlobalGenerator::~cmGlobalGenerator()
|
|||
{
|
||||
this->ClearGeneratorMembers();
|
||||
}
|
||||
codecvt_Encoding cmGlobalGenerator::GetMakefileEncoding() const
|
||||
{
|
||||
return codecvt_Encoding::None;
|
||||
}
|
||||
|
||||
#if !defined(CMAKE_BOOTSTRAP)
|
||||
Json::Value cmGlobalGenerator::GetJson() const
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmBuildOptions.h"
|
||||
#include "cmCustomCommandLines.h"
|
||||
|
@ -120,10 +120,7 @@ public:
|
|||
}
|
||||
|
||||
/** Get encoding used by generator for makefile files */
|
||||
virtual codecvt::Encoding GetMakefileEncoding() const
|
||||
{
|
||||
return codecvt::None;
|
||||
}
|
||||
virtual codecvt_Encoding GetMakefileEncoding() const;
|
||||
|
||||
#if !defined(CMAKE_BOOTSTRAP)
|
||||
/** Get a JSON object describing the generator. */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmGlobalGeneratorFactory.h"
|
||||
#include "cmGlobalUnixMakefileGenerator3.h"
|
||||
|
@ -38,9 +38,10 @@ public:
|
|||
static std::string GetActualName() { return "NMake Makefiles"; }
|
||||
|
||||
/** Get encoding used by generator for makefile files */
|
||||
codecvt::Encoding GetMakefileEncoding() const override
|
||||
codecvt_Encoding GetMakefileEncoding() const override
|
||||
{
|
||||
return this->NMakeSupportsUTF8 ? codecvt::UTF8_WITH_BOM : codecvt::ANSI;
|
||||
return this->NMakeSupportsUTF8 ? codecvt_Encoding::UTF8_WITH_BOM
|
||||
: codecvt_Encoding::ANSI;
|
||||
}
|
||||
|
||||
/** Get the documentation entry for this generator. */
|
||||
|
|
|
@ -566,7 +566,7 @@ std::unique_ptr<cmLocalGenerator> cmGlobalNinjaGenerator::CreateLocalGenerator(
|
|||
cm::make_unique<cmLocalNinjaGenerator>(this, mf));
|
||||
}
|
||||
|
||||
codecvt::Encoding cmGlobalNinjaGenerator::GetMakefileEncoding() const
|
||||
codecvt_Encoding cmGlobalNinjaGenerator::GetMakefileEncoding() const
|
||||
{
|
||||
return this->NinjaExpectedEncoding;
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
|
|||
if (this->NinjaSupportsCodePage) {
|
||||
this->CheckNinjaCodePage();
|
||||
} else {
|
||||
this->NinjaExpectedEncoding = codecvt::ANSI;
|
||||
this->NinjaExpectedEncoding = codecvt_Encoding::ANSI;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -830,9 +830,9 @@ void cmGlobalNinjaGenerator::CheckNinjaCodePage()
|
|||
lineView.substr(cmStrLen("Build file encoding: "));
|
||||
if (encoding == "UTF-8") {
|
||||
// Ninja expects UTF-8. We use that internally. No conversion needed.
|
||||
this->NinjaExpectedEncoding = codecvt::None;
|
||||
this->NinjaExpectedEncoding = codecvt_Encoding::None;
|
||||
} else {
|
||||
this->NinjaExpectedEncoding = codecvt::ANSI;
|
||||
this->NinjaExpectedEncoding = codecvt_Encoding::ANSI;
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
|
@ -842,10 +842,10 @@ void cmGlobalNinjaGenerator::CheckNinjaCodePage()
|
|||
this->GetCMakeInstance()->IssueMessage(
|
||||
MessageType::WARNING,
|
||||
"Could not determine Ninja's code page, defaulting to UTF-8");
|
||||
this->NinjaExpectedEncoding = codecvt::None;
|
||||
this->NinjaExpectedEncoding = codecvt_Encoding::None;
|
||||
}
|
||||
} else {
|
||||
this->NinjaExpectedEncoding = codecvt::ANSI;
|
||||
this->NinjaExpectedEncoding = codecvt_Encoding::ANSI;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include <cm/optional>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmBuildOptions.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
|
@ -192,7 +192,7 @@ public:
|
|||
bool IsNinja() const override { return true; }
|
||||
|
||||
/** Get encoding used by generator for ninja files */
|
||||
codecvt::Encoding GetMakefileEncoding() const override;
|
||||
codecvt_Encoding GetMakefileEncoding() const override;
|
||||
|
||||
static cmDocumentationEntry GetDocumentation();
|
||||
|
||||
|
@ -590,7 +590,7 @@ private:
|
|||
bool NinjaSupportsMetadataOnRegeneration = false;
|
||||
bool NinjaSupportsCodePage = false;
|
||||
|
||||
codecvt::Encoding NinjaExpectedEncoding = codecvt::None;
|
||||
codecvt_Encoding NinjaExpectedEncoding = codecvt_Encoding::None;
|
||||
|
||||
bool DiagnosedCxxModuleNinjaSupport = false;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmTargetDepend.h"
|
||||
|
@ -119,9 +119,9 @@ public:
|
|||
|
||||
/** Get encoding used by generator for generated source files
|
||||
*/
|
||||
codecvt::Encoding GetMakefileEncoding() const override
|
||||
codecvt_Encoding GetMakefileEncoding() const override
|
||||
{
|
||||
return codecvt::ANSI;
|
||||
return codecvt_Encoding::ANSI;
|
||||
}
|
||||
|
||||
class TargetSet : public std::set<cmGeneratorTarget const*>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include "cm_codecvt.hxx"
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
#include "cmComputeLinkInformation.h"
|
||||
#include "cmCustomCommand.h"
|
||||
|
@ -2129,12 +2129,12 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
|
|||
// 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 =
|
||||
codecvt_Encoding responseEncoding =
|
||||
this->GlobalGenerator->GetMakefileEncoding();
|
||||
// Non-MSVC tooling doesn't understand BOM encoded files.
|
||||
if (responseEncoding == codecvt::UTF8_WITH_BOM &&
|
||||
if (responseEncoding == codecvt_Encoding::UTF8_WITH_BOM &&
|
||||
(language == "CUDA" || !this->Makefile->IsOn("MSVC"))) {
|
||||
responseEncoding = codecvt::UTF8;
|
||||
responseEncoding = codecvt_Encoding::UTF8;
|
||||
}
|
||||
|
||||
// Create the response file.
|
||||
|
|
|
@ -13,19 +13,19 @@
|
|||
# include "cm_utf8.h"
|
||||
#endif
|
||||
|
||||
codecvt::codecvt(Encoding e)
|
||||
codecvt::codecvt(codecvt_Encoding e)
|
||||
#if defined(_WIN32)
|
||||
: m_codepage(0)
|
||||
#endif
|
||||
{
|
||||
switch (e) {
|
||||
case codecvt::ConsoleOutput:
|
||||
case codecvt_Encoding::ConsoleOutput:
|
||||
#if defined(_WIN32)
|
||||
m_noconv = false;
|
||||
m_codepage = GetConsoleOutputCP();
|
||||
break;
|
||||
#endif
|
||||
case codecvt::ANSI:
|
||||
case codecvt_Encoding::ANSI:
|
||||
#if defined(_WIN32)
|
||||
m_noconv = false;
|
||||
m_codepage = CP_ACP;
|
||||
|
@ -33,10 +33,10 @@ codecvt::codecvt(Encoding e)
|
|||
#endif
|
||||
// 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:
|
||||
case codecvt_Encoding::UTF8:
|
||||
case codecvt_Encoding::UTF8_WITH_BOM:
|
||||
// Assume internal encoding is UTF-8
|
||||
case codecvt::None:
|
||||
case codecvt_Encoding::None:
|
||||
// No encoding
|
||||
default:
|
||||
this->m_noconv = true;
|
||||
|
|
|
@ -7,21 +7,14 @@
|
|||
#include <cwchar>
|
||||
#include <locale>
|
||||
|
||||
#include "cm_codecvt_Encoding.hxx"
|
||||
|
||||
class codecvt : public std::codecvt<char, char, mbstate_t>
|
||||
{
|
||||
public:
|
||||
enum Encoding
|
||||
{
|
||||
None,
|
||||
UTF8,
|
||||
UTF8_WITH_BOM,
|
||||
ANSI,
|
||||
ConsoleOutput,
|
||||
};
|
||||
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
|
||||
codecvt(Encoding e);
|
||||
codecvt(codecvt_Encoding e);
|
||||
|
||||
protected:
|
||||
~codecvt() override;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#pragma once
|
||||
|
||||
enum class codecvt_Encoding
|
||||
{
|
||||
None,
|
||||
UTF8,
|
||||
UTF8_WITH_BOM,
|
||||
ANSI,
|
||||
ConsoleOutput,
|
||||
};
|
Loading…
Reference in New Issue