diff options
author | Brad King <brad.king@kitware.com> | 2020-10-15 12:10:40 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-10-15 12:10:50 (GMT) |
commit | b1d9a25f35a22f41b2c1b87725f091936711a28c (patch) | |
tree | c2196fa3b431f21af857fe830928fe2f28979220 /Source/cmcmd.cxx | |
parent | 30643e21d48004c6d5675d14881ad82ace1194b7 (diff) | |
parent | f7a5f283188c1e51b0fb549f0a78afaf1d570383 (diff) | |
download | CMake-b1d9a25f35a22f41b2c1b87725f091936711a28c.zip CMake-b1d9a25f35a22f41b2c1b87725f091936711a28c.tar.gz CMake-b1d9a25f35a22f41b2c1b87725f091936711a28c.tar.bz2 |
Merge topic 'cmake-E-cat-binary' into release-3.19
f7a5f28318 cmake: Fix '-E cat' command for binary files on Windows
90b39a5209 cmConsoleBuf: Factor out cout/cerr console buffer management
f1fdd15863 clang-format: Fix include block order in ctest.cxx and cpack.cxx
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5364
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r-- | Source/cmcmd.cxx | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 15d2fd1..e2ff8b7 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -7,6 +7,7 @@ #include <cm3p/uv.h> #include <fcntl.h> +#include "cmConsoleBuf.h" #include "cmDuration.h" #include "cmGlobalGenerator.h" #include "cmLocalGenerator.h" @@ -33,10 +34,6 @@ # include "bindexplib.h" #endif -#if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) -# include "cmsys/ConsoleBuf.hxx" -#endif - #if !defined(CMAKE_BOOTSTRAP) && defined(_WIN32) && !defined(__CYGWIN__) # include "cmVisualStudioWCEPlatformParser.h" #endif @@ -51,6 +48,12 @@ #include <sstream> #include <utility> +#ifdef _WIN32 +# include <fcntl.h> // for _O_BINARY +# include <io.h> // for _setmode +# include <stdio.h> // for std{out,err} and fileno +#endif + #include <cm/string_view> #include "cmsys/Directory.hxx" @@ -182,6 +185,9 @@ static bool cmTarFilesFrom(std::string const& file, static void cmCatFile(const std::string& fileToAppend) { +#ifdef _WIN32 + _setmode(fileno(stdout), _O_BINARY); +#endif cmsys::ifstream source(fileToAppend.c_str(), (std::ios::binary | std::ios::in)); std::cout << source.rdbuf(); @@ -501,7 +507,8 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string> const& args) return ret; } -int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) +int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, + std::unique_ptr<cmConsoleBuf> consoleBuf) { // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx if (args.size() > 1) { @@ -951,6 +958,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args) cmSystemTools::Error(arg + ": no such file or directory (ignoring)"); return_value = 1; } else { + // Destroy console buffers to drop cout/cerr encoding transform. + consoleBuf.reset(); cmCatFile(arg); } } @@ -1889,14 +1898,11 @@ private: // still works. 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 // to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker // outputs using the system codepage so we need to change behavior when // we run the link command. - cmsys::ConsoleBuf::Manager consoleOut(std::cout); - cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true); -#endif + cmConsoleBuf consoleBuf; if (args.size() < 2) { return -1; |