From 335a29cb07a8d014a9ed4d4dbf25e49da3a78b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C4=81vis=20Mos=C4=81ns?= Date: Sat, 1 Oct 2016 03:11:35 +0300 Subject: Enable Unicode output to Windows consoles Use KWSys ConsoleBuf to replace the `streambuf` on `std::cout` and `std::cerr` so that process output can be encoded correctly for display in a Windows console. --- CMakeLists.txt | 1 + Source/CPack/cpack.cxx | 8 ++++++++ Source/cmakemain.cxx | 8 ++++++++ Source/ctest.cxx | 8 ++++++++ 4 files changed, 25 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8a635f..1bc4b4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,6 +260,7 @@ macro (CMAKE_BUILD_UTILITIES) set(KWSYS_USE_MD5 1) set(KWSYS_USE_Process 1) set(KWSYS_USE_CommandLineArguments 1) + set(KWSYS_USE_ConsoleBuf 1) set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source) set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}") add_subdirectory(Source/kwsys) diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index b06bd38..06472c6 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -17,6 +17,9 @@ #include #include +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) +#include +#endif #include #include #include @@ -84,6 +87,11 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, // this is CPack. int main(int argc, char const* const* argv) { +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf::Manager consoleOut(std::cout); + cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); +#endif cmsys::Encoding::CommandLineArguments args = cmsys::Encoding::CommandLineArguments::Main(argc, argv); argc = args.argc(); diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index d1159c3..44af966 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -18,6 +18,9 @@ #include #include +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) +#include +#endif #include #include #include @@ -153,6 +156,11 @@ static void cmakemainProgressCallback(const char* m, float prog, int main(int ac, char const* const* av) { +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf::Manager consoleOut(std::cout); + cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); +#endif cmsys::Encoding::CommandLineArguments args = cmsys::Encoding::CommandLineArguments::Main(ac, av); ac = args.argc(); diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 8ab17b9..1acd240 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -10,6 +10,9 @@ #include "cmake.h" #include +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) +#include +#endif #include #include #include @@ -110,6 +113,11 @@ static const char* cmDocumentationOptions[][2] = { // this is a test driver program for cmCTest. int main(int argc, char const* const* argv) { +#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE) + // Replace streambuf so we can output Unicode to console + cmsys::ConsoleBuf::Manager consoleOut(std::cout); + cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); +#endif cmsys::Encoding::CommandLineArguments encoding_args = cmsys::Encoding::CommandLineArguments::Main(argc, argv); argc = encoding_args.argc(); -- cgit v0.12