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:51 (GMT) |
commit | 9493532f80f27313e82b64b053fcc7d61626c1b4 (patch) | |
tree | 24787f63bb2ae9ca5ad91870a4c33845fa41d6c9 /Source/cmcmd.cxx | |
parent | 64449c9f949948aa956ea03682530df9317f37ef (diff) | |
parent | f7a5f283188c1e51b0fb549f0a78afaf1d570383 (diff) | |
download | CMake-9493532f80f27313e82b64b053fcc7d61626c1b4.zip CMake-9493532f80f27313e82b64b053fcc7d61626c1b4.tar.gz CMake-9493532f80f27313e82b64b053fcc7d61626c1b4.tar.bz2 |
Merge topic 'cmake-E-cat-binary'
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 0bdc6fa..8db6ee8 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" @@ -34,10 +35,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 @@ -52,6 +49,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" @@ -183,6 +186,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(); @@ -502,7 +508,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) { @@ -952,6 +959,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); } } @@ -1907,14 +1916,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; |