summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorDāvis Mosāns <davispuh@gmail.com>2016-11-23 12:11:40 (GMT)
committerBrad King <brad.king@kitware.com>2016-11-30 14:06:51 (GMT)
commit2ed473b3b8e28485e6a14a49c7e0e4133eb02eee (patch)
tree1343f0e826693c923074102e588f90f0678e3cc5 /Source
parent076aef8e45a91e83f9a7d879712fd70778d67c92 (diff)
downloadCMake-2ed473b3b8e28485e6a14a49c7e0e4133eb02eee.zip
CMake-2ed473b3b8e28485e6a14a49c7e0e4133eb02eee.tar.gz
CMake-2ed473b3b8e28485e6a14a49c7e0e4133eb02eee.tar.bz2
execute_process: Add ENCODING option for Windows child process output
Different applications can use different output encodings.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmExecuteProcessCommand.cxx11
-rw-r--r--Source/cmProcessOutput.cxx15
-rw-r--r--Source/cmProcessOutput.h7
3 files changed, 32 insertions, 1 deletions
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index 1562223..eb26a50 100644
--- a/Source/cmExecuteProcessCommand.cxx
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -47,6 +47,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
std::string error_variable;
std::string result_variable;
std::string working_directory;
+ cmProcessOutput::Encoding encoding = cmProcessOutput::Auto;
for (size_t i = 0; i < args.size(); ++i) {
if (args[i] == "COMMAND") {
doing_command = true;
@@ -128,6 +129,14 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
} else if (args[i] == "ERROR_STRIP_TRAILING_WHITESPACE") {
doing_command = false;
error_strip_trailing_whitespace = true;
+ } else if (args[i] == "ENCODING") {
+ doing_command = false;
+ if (++i < args.size()) {
+ encoding = cmProcessOutput::FindEncoding(args[i]);
+ } else {
+ this->SetError(" called with no value for ENCODING.");
+ return false;
+ }
} else if (doing_command) {
cmds[command_index].push_back(args[i].c_str());
} else {
@@ -223,7 +232,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
int length;
char* data;
int p;
- cmProcessOutput processOutput;
+ cmProcessOutput processOutput(encoding);
std::string strdata;
while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
// Put the output in the right place.
diff --git a/Source/cmProcessOutput.cxx b/Source/cmProcessOutput.cxx
index 1440223..8b4d0e1 100644
--- a/Source/cmProcessOutput.cxx
+++ b/Source/cmProcessOutput.cxx
@@ -9,6 +9,21 @@ unsigned int cmProcessOutput::defaultCodepage =
KWSYS_ENCODING_DEFAULT_CODEPAGE;
#endif
+cmProcessOutput::Encoding cmProcessOutput::FindEncoding(std::string name)
+{
+ Encoding encoding = Auto;
+ if (name == "UTF8") {
+ encoding = UTF8;
+ } else if (name == "NONE") {
+ encoding = None;
+ } else if (name == "ANSI") {
+ encoding = ANSI;
+ } else if (name == "OEM") {
+ encoding = OEM;
+ }
+ return encoding;
+}
+
cmProcessOutput::cmProcessOutput(Encoding encoding, unsigned int maxSize)
{
#if defined(_WIN32)
diff --git a/Source/cmProcessOutput.h b/Source/cmProcessOutput.h
index 6a4e7d5..6046f57 100644
--- a/Source/cmProcessOutput.h
+++ b/Source/cmProcessOutput.h
@@ -27,6 +27,13 @@ public:
OEM
};
+ /**
+ * Find encoding enum value for given encoding \a name.
+ * \param name a encoding name.
+ * \return encoding enum value or Auto if \a name was not found.
+ */
+ static Encoding FindEncoding(std::string name);
+
/// The code page that is used as internal encoding to which we will encode.
static unsigned int defaultCodepage;