diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index ef4985a453..ff49eeff91 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -401,7 +401,6 @@ add_library( cmRulePlaceholderExpander.cxx cmRulePlaceholderExpander.h cmLocalUnixMakefileGenerator3.cxx - cmLocale.h cmMakefile.cxx cmMakefile.h cmMakefileTargetGenerator.cxx diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index ab7e624d95..0adcefd067 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -24,7 +24,6 @@ #include "cm_parse_date.h" -#include "cmLocale.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -449,9 +448,6 @@ bool cmArchiveWrite::AddFile(char const* file, size_t skip, char const* prefix) } char const* out = file + skip; - cmLocaleRAII localeRAII; - static_cast(localeRAII); - // Meta-data. std::string dest = cmStrCat(prefix ? prefix : "", out); if (this->Verbose) { diff --git a/Source/cmLocale.h b/Source/cmLocale.h deleted file mode 100644 index b0d10652a2..0000000000 --- a/Source/cmLocale.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file LICENSE.rst or https://cmake.org/licensing for details. */ -#pragma once - -#include "cmConfigure.h" // IWYU pragma: keep - -#include -#include - -class cmLocaleRAII -{ -public: - cmLocaleRAII() - : OldLocale(setlocale(LC_CTYPE, nullptr)) - { - setlocale(LC_CTYPE, ""); - } - - ~cmLocaleRAII() { setlocale(LC_CTYPE, this->OldLocale.c_str()); } - - cmLocaleRAII(cmLocaleRAII const&) = delete; - cmLocaleRAII& operator=(cmLocaleRAII const&) = delete; - -private: - std::string OldLocale; -}; diff --git a/Source/cmStdIoInit.cxx b/Source/cmStdIoInit.cxx index 49f31873bd..0d7a3d027e 100644 --- a/Source/cmStdIoInit.cxx +++ b/Source/cmStdIoInit.cxx @@ -3,6 +3,7 @@ #include "cmStdIoInit.h" #include +#include #include #include #include @@ -106,14 +107,19 @@ public: static Globals& Get(); }; -#ifdef _WIN32 Globals::Globals() { +#ifdef _WIN32 + // On Windows, setlocale offers a "." syntax to select the + // user's locale with a specific character set. We always use UTF-8. + std::setlocale(LC_CTYPE, ".UTF-8"); + SetConsoleCtrlHandler(CtrlHandler, TRUE); -} #else -Globals::Globals() = default; + // On non-Windows platforms, we select the user's locale. + std::setlocale(LC_CTYPE, ""); #endif +} Globals& Globals::Get() { diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 780c83a186..2329449c8b 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -58,7 +58,6 @@ # include # include "cmArchiveWrite.h" -# include "cmLocale.h" # ifndef __LA_INT64_T # define __LA_INT64_T la_int64_t # endif @@ -2624,8 +2623,6 @@ bool extract_tar(std::string const& arFileName, cmSystemTools::cmTarExtractTimestamps extractTimestamps, bool extract) { - cmLocaleRAII localeRAII; - static_cast(localeRAII); struct archive* a = archive_read_new(); struct archive* ext = archive_write_disk_new(); if (extract) {