mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-15 20:46:37 +08:00
cmConsoleBuf: Factor out cout/cerr console buffer management
This commit is contained in:
@@ -193,6 +193,8 @@ set(SRCS
|
|||||||
cmComputeLinkInformation.h
|
cmComputeLinkInformation.h
|
||||||
cmComputeTargetDepends.h
|
cmComputeTargetDepends.h
|
||||||
cmComputeTargetDepends.cxx
|
cmComputeTargetDepends.cxx
|
||||||
|
cmConsoleBuf.h
|
||||||
|
cmConsoleBuf.cxx
|
||||||
cmCPackPropertiesGenerator.h
|
cmCPackPropertiesGenerator.h
|
||||||
cmCPackPropertiesGenerator.cxx
|
cmCPackPropertiesGenerator.cxx
|
||||||
cmCryptoHash.cxx
|
cmCryptoHash.cxx
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include "cmCPackGenerator.h"
|
#include "cmCPackGenerator.h"
|
||||||
#include "cmCPackGeneratorFactory.h"
|
#include "cmCPackGeneratorFactory.h"
|
||||||
#include "cmCPackLog.h"
|
#include "cmCPackLog.h"
|
||||||
|
#include "cmConsoleBuf.h"
|
||||||
#include "cmDocumentation.h"
|
#include "cmDocumentation.h"
|
||||||
#include "cmDocumentationEntry.h"
|
#include "cmDocumentationEntry.h"
|
||||||
#include "cmDocumentationFormatter.h"
|
#include "cmDocumentationFormatter.h"
|
||||||
@@ -27,10 +28,6 @@
|
|||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
# include "cmsys/ConsoleBuf.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const char* cmDocumentationName[][2] = {
|
const char* cmDocumentationName[][2] = {
|
||||||
{ nullptr, " cpack - Packaging driver provided by CMake." },
|
{ nullptr, " cpack - Packaging driver provided by CMake." },
|
||||||
@@ -103,13 +100,11 @@ void cpackProgressCallback(const std::string& message, float /*unused*/)
|
|||||||
int main(int argc, char const* const* argv)
|
int main(int argc, char const* const* argv)
|
||||||
{
|
{
|
||||||
cmSystemTools::EnsureStdPipes();
|
cmSystemTools::EnsureStdPipes();
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
// Replace streambuf so we can output Unicode to console
|
// Replace streambuf so we can output Unicode to console
|
||||||
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
|
cmConsoleBuf consoleBuf;
|
||||||
consoleOut.SetUTF8Pipes();
|
consoleBuf.SetUTF8Pipes();
|
||||||
cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
|
|
||||||
consoleErr.SetUTF8Pipes();
|
|
||||||
#endif
|
|
||||||
cmsys::Encoding::CommandLineArguments args =
|
cmsys::Encoding::CommandLineArguments args =
|
||||||
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
|
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
|
||||||
argc = args.argc();
|
argc = args.argc();
|
||||||
|
23
Source/cmConsoleBuf.cxx
Normal file
23
Source/cmConsoleBuf.cxx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#include "cmConsoleBuf.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
||||||
|
cmConsoleBuf::cmConsoleBuf()
|
||||||
|
: m_ConsoleOut(std::cout)
|
||||||
|
, m_ConsoleErr(std::cerr, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
cmConsoleBuf::cmConsoleBuf() = default;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cmConsoleBuf::~cmConsoleBuf() = default;
|
||||||
|
|
||||||
|
void cmConsoleBuf::SetUTF8Pipes()
|
||||||
|
{
|
||||||
|
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
||||||
|
m_ConsoleOut.SetUTF8Pipes();
|
||||||
|
m_ConsoleErr.SetUTF8Pipes();
|
||||||
|
#endif
|
||||||
|
}
|
23
Source/cmConsoleBuf.h
Normal file
23
Source/cmConsoleBuf.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
||||||
|
# include "cmsys/ConsoleBuf.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class cmConsoleBuf
|
||||||
|
{
|
||||||
|
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
||||||
|
cmsys::ConsoleBuf::Manager m_ConsoleOut;
|
||||||
|
cmsys::ConsoleBuf::Manager m_ConsoleErr;
|
||||||
|
#endif
|
||||||
|
public:
|
||||||
|
cmConsoleBuf();
|
||||||
|
~cmConsoleBuf();
|
||||||
|
cmConsoleBuf(cmConsoleBuf const&) = delete;
|
||||||
|
cmConsoleBuf& operator=(cmConsoleBuf const&) = delete;
|
||||||
|
void SetUTF8Pipes();
|
||||||
|
};
|
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <cm3p/uv.h>
|
#include <cm3p/uv.h>
|
||||||
|
|
||||||
|
#include "cmConsoleBuf.h"
|
||||||
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
@@ -32,9 +33,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cmsys/Encoding.hxx"
|
#include "cmsys/Encoding.hxx"
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
# include "cmsys/ConsoleBuf.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
@@ -687,13 +685,11 @@ int do_open(int ac, char const* const* av)
|
|||||||
int main(int ac, char const* const* av)
|
int main(int ac, char const* const* av)
|
||||||
{
|
{
|
||||||
cmSystemTools::EnsureStdPipes();
|
cmSystemTools::EnsureStdPipes();
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
// Replace streambuf so we can output Unicode to console
|
// Replace streambuf so we can output Unicode to console
|
||||||
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
|
cmConsoleBuf consoleBuf;
|
||||||
consoleOut.SetUTF8Pipes();
|
consoleBuf.SetUTF8Pipes();
|
||||||
cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
|
|
||||||
consoleErr.SetUTF8Pipes();
|
|
||||||
#endif
|
|
||||||
cmsys::Encoding::CommandLineArguments args =
|
cmsys::Encoding::CommandLineArguments args =
|
||||||
cmsys::Encoding::CommandLineArguments::Main(ac, av);
|
cmsys::Encoding::CommandLineArguments::Main(ac, av);
|
||||||
ac = args.argc();
|
ac = args.argc();
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <cm3p/uv.h>
|
#include <cm3p/uv.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "cmConsoleBuf.h"
|
||||||
#include "cmDuration.h"
|
#include "cmDuration.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
@@ -33,10 +34,6 @@
|
|||||||
# include "bindexplib.h"
|
# include "bindexplib.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32)
|
|
||||||
# include "cmsys/ConsoleBuf.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) && !defined(__CYGWIN__)
|
#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
# include "cmVisualStudioWCEPlatformParser.h"
|
# include "cmVisualStudioWCEPlatformParser.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -1863,14 +1860,11 @@ private:
|
|||||||
// still works.
|
// still works.
|
||||||
int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type)
|
int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
// Replace streambuf so we output in the system codepage. CMake is set up
|
// Replace streambuf so we output in the system codepage. CMake is set up
|
||||||
// to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker
|
// to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker
|
||||||
// outputs using the system codepage so we need to change behavior when
|
// outputs using the system codepage so we need to change behavior when
|
||||||
// we run the link command.
|
// we run the link command.
|
||||||
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
|
cmConsoleBuf consoleBuf;
|
||||||
cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@@ -9,14 +9,12 @@
|
|||||||
#include "cmsys/Encoding.hxx"
|
#include "cmsys/Encoding.hxx"
|
||||||
|
|
||||||
#include "cmCTest.h"
|
#include "cmCTest.h"
|
||||||
|
#include "cmConsoleBuf.h"
|
||||||
#include "cmDocumentation.h"
|
#include "cmDocumentation.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
#include "CTest/cmCTestLaunch.h"
|
#include "CTest/cmCTestLaunch.h"
|
||||||
#include "CTest/cmCTestScriptHandler.h"
|
#include "CTest/cmCTestScriptHandler.h"
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
# include "cmsys/ConsoleBuf.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char* cmDocumentationName[][2] = {
|
static const char* cmDocumentationName[][2] = {
|
||||||
{ nullptr, " ctest - Testing driver provided by CMake." },
|
{ nullptr, " ctest - Testing driver provided by CMake." },
|
||||||
@@ -155,13 +153,11 @@ static const char* cmDocumentationOptions[][2] = {
|
|||||||
int main(int argc, char const* const* argv)
|
int main(int argc, char const* const* argv)
|
||||||
{
|
{
|
||||||
cmSystemTools::EnsureStdPipes();
|
cmSystemTools::EnsureStdPipes();
|
||||||
#if defined(_WIN32) && !defined(CMAKE_BOOTSTRAP)
|
|
||||||
// Replace streambuf so we can output Unicode to console
|
// Replace streambuf so we can output Unicode to console
|
||||||
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
|
cmConsoleBuf consoleBuf;
|
||||||
consoleOut.SetUTF8Pipes();
|
consoleBuf.SetUTF8Pipes();
|
||||||
cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
|
|
||||||
consoleErr.SetUTF8Pipes();
|
|
||||||
#endif
|
|
||||||
cmsys::Encoding::CommandLineArguments encoding_args =
|
cmsys::Encoding::CommandLineArguments encoding_args =
|
||||||
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
|
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
|
||||||
argc = encoding_args.argc();
|
argc = encoding_args.argc();
|
||||||
|
@@ -299,6 +299,7 @@ CMAKE_CXX_SOURCES="\
|
|||||||
cmComputeLinkDepends \
|
cmComputeLinkDepends \
|
||||||
cmComputeLinkInformation \
|
cmComputeLinkInformation \
|
||||||
cmComputeTargetDepends \
|
cmComputeTargetDepends \
|
||||||
|
cmConsoleBuf \
|
||||||
cmConditionEvaluator \
|
cmConditionEvaluator \
|
||||||
cmConfigureFileCommand \
|
cmConfigureFileCommand \
|
||||||
cmContinueCommand \
|
cmContinueCommand \
|
||||||
|
Reference in New Issue
Block a user