summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-09-21 15:14:06 -0400
committerBrad King <brad.king@kitware.com>2006-09-21 15:14:06 -0400
commit2459ceb076d7788f7512ef4a2f68e81c43bc271d (patch)
treeb198c9b7a49aed110b2a706f82426e84690dc582 /Source
parent0952a96485cad05f68724f0a703758dceb60add9 (diff)
downloadcmake-2459ceb076d7788f7512ef4a2f68e81c43bc271d.tar.gz
BUG: Centralized generation of command line arguments in escaped form. This addresses bug#3786 for several platforms.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx4
-rw-r--r--Source/cmLocalGenerator.cxx78
-rw-r--r--Source/cmLocalGenerator.h8
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx11
-rw-r--r--Source/cmLocalVisualStudio6Generator.cxx4
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx4
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx51
-rw-r--r--Source/cmLocalVisualStudioGenerator.h6
8 files changed, 96 insertions, 70 deletions
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index 9d7aa5475c..760eb7be85 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -130,12 +130,12 @@ void cmGlobalVisualStudio8Generator::Generate()
std::string argH = "-H";
argH += lg->Convert(mf->GetHomeDirectory(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::SHELL, true);
+ cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argH);
std::string argB = "-B";
argB += lg->Convert(mf->GetHomeOutputDirectory(),
cmLocalGenerator::START_OUTPUT,
- cmLocalGenerator::SHELL, true);
+ cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argB);
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index e58b5425ef..01d08ec787 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -28,6 +28,8 @@
#include "cmTest.h"
#include "cmake.h"
+#include <cmsys/System.h>
+
#include <ctype.h> // for isalpha
cmLocalGenerator::cmLocalGenerator()
@@ -1898,56 +1900,6 @@ void cmLocalGenerator::AppendFlags(std::string& flags,
//----------------------------------------------------------------------------
std::string
-cmLocalGenerator::ConstructScript(const cmCustomCommandLines& commandLines,
- const char* workingDirectory,
- const char* newline)
-
-{
- // Store the script in a string.
- std::string script;
- if(workingDirectory)
- {
- script += "cd ";
- script += this->Convert(workingDirectory, START_OUTPUT, SHELL);
- script += newline;
- }
- // for visual studio IDE add extra stuff to the PATH
- // if CMAKE_MSVCIDE_RUN_PATH is set.
- if(this->Makefile->GetDefinition("MSVC_IDE"))
- {
- const char* extraPath =
- this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
- if(extraPath)
- {
- script += "set PATH=";
- script += extraPath;
- script += ";%PATH%";
- script += newline;
- }
- }
- // Write each command on a single line.
- for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
- cl != commandLines.end(); ++cl)
- {
- // Start with the command name.
- const cmCustomCommandLine& commandLine = *cl;
- script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
-
- // Add the arguments.
- for(unsigned int j=1;j < commandLine.size(); ++j)
- {
- script += " ";
- script += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
- }
-
- // End the line.
- script += newline;
- }
- return script;
-}
-
-//----------------------------------------------------------------------------
-std::string
cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
const char* default_comment)
{
@@ -2289,3 +2241,29 @@ cmLocalGenerator
return (this->GlobalGenerator
->GetLanguageFromExtension(source.GetSourceExtension().c_str()));
}
+
+//----------------------------------------------------------------------------
+std::string cmLocalGenerator::EscapeForShell(const char* str)
+{
+ std::string result;
+ if(this->WindowsShell)
+ {
+ int size = cmsysSystem_Windows_ShellArgumentSize(str);
+ std::vector<char> arg(size);
+ cmsysSystem_Windows_ShellArgument(str, &arg[0]);
+ result = &arg[0];
+ }
+ else
+ {
+ for(const char* c = str; *c; ++c)
+ {
+ if(*c == '\\' || *c == '\'' || *c == '"' || *c == ';' ||
+ *c == '(' || *c == ')')
+ {
+ result += "\\";
+ }
+ result += *c;
+ }
+ }
+ return result;
+}
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 6a4937527a..1e324a10e6 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -202,10 +202,10 @@ public:
};
protected:
- /** Construct a script from the given list of command lines. */
- std::string ConstructScript(const cmCustomCommandLines& commandLines,
- const char* workingDirectory,
- const char* newline = "\n");
+
+ /** Escape the given string to be used as a command line argument in
+ the native build system shell. */
+ std::string EscapeForShell(const char* str);
/** Construct a comment for a custom command. */
std::string ConstructComment(const cmCustomCommand& cc,
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index aee3392716..a721abaf15 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -931,16 +931,7 @@ cmLocalUnixMakefileGenerator3
for(unsigned int j=1; j < commandLine.size(); ++j)
{
cmd += " ";
- bool forceOn = cmSystemTools::GetForceUnixPaths();
- if(forceOn && this->WindowsShell)
- {
- cmSystemTools::SetForceUnixPaths(false);
- }
- cmd += cmSystemTools::EscapeSpaces(commandLine[j].c_str());
- if(forceOn && this->WindowsShell)
- {
- cmSystemTools::SetForceUnixPaths(true);
- }
+ cmd += this->EscapeForShell(commandLine[j].c_str());
}
commands1.push_back(cmd);
}
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx
index 54bdafe532..7a07d45fe3 100644
--- a/Source/cmLocalVisualStudio6Generator.cxx
+++ b/Source/cmLocalVisualStudio6Generator.cxx
@@ -223,12 +223,12 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
std::string args;
args = "-H";
args += this->Convert(this->Makefile->GetHomeDirectory(),
- START_OUTPUT, SHELL, true);
+ START_OUTPUT, UNCHANGED, true);
commandLine.push_back(args);
args = "-B";
args +=
this->Convert(this->Makefile->GetHomeOutputDirectory(),
- START_OUTPUT, SHELL, true);
+ START_OUTPUT, UNCHANGED, true);
commandLine.push_back(args);
std::string configFile =
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index b2b983e614..08d5158ec0 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -219,12 +219,12 @@ void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmTarget& tgt)
std::string args;
args = "-H";
args += this->Convert(this->Makefile->GetHomeDirectory(),
- START_OUTPUT, SHELL, true);
+ START_OUTPUT, UNCHANGED, true);
commandLine.push_back(args);
args = "-B";
args +=
this->Convert(this->Makefile->GetHomeOutputDirectory(),
- START_OUTPUT, SHELL, true);
+ START_OUTPUT, UNCHANGED, true);
commandLine.push_back(args);
std::string configFile =
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index f2da64ee75..f874987f87 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -23,6 +23,7 @@
//----------------------------------------------------------------------------
cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator()
{
+ this->WindowsShell = true;
}
//----------------------------------------------------------------------------
@@ -103,3 +104,53 @@ void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements
}
}
}
+
+//----------------------------------------------------------------------------
+std::string
+cmLocalVisualStudioGenerator
+::ConstructScript(const cmCustomCommandLines& commandLines,
+ const char* workingDirectory,
+ const char* newline)
+{
+ // Store the script in a string.
+ std::string script;
+ if(workingDirectory)
+ {
+ script += "cd ";
+ script += this->Convert(workingDirectory, START_OUTPUT, SHELL);
+ script += newline;
+ }
+ // for visual studio IDE add extra stuff to the PATH
+ // if CMAKE_MSVCIDE_RUN_PATH is set.
+ if(this->Makefile->GetDefinition("MSVC_IDE"))
+ {
+ const char* extraPath =
+ this->Makefile->GetDefinition("CMAKE_MSVCIDE_RUN_PATH");
+ if(extraPath)
+ {
+ script += "set PATH=";
+ script += extraPath;
+ script += ";%PATH%";
+ script += newline;
+ }
+ }
+ // Write each command on a single line.
+ for(cmCustomCommandLines::const_iterator cl = commandLines.begin();
+ cl != commandLines.end(); ++cl)
+ {
+ // Start with the command name.
+ const cmCustomCommandLine& commandLine = *cl;
+ script += this->Convert(commandLine[0].c_str(),START_OUTPUT,SHELL);
+
+ // Add the arguments.
+ for(unsigned int j=1;j < commandLine.size(); ++j)
+ {
+ script += " ";
+ script += this->EscapeForShell(commandLine[j].c_str());
+ }
+
+ // End the line.
+ script += newline;
+ }
+ return script;
+}
diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h
index ac6baf9dc6..38ca491b6d 100644
--- a/Source/cmLocalVisualStudioGenerator.h
+++ b/Source/cmLocalVisualStudioGenerator.h
@@ -35,6 +35,12 @@ public:
virtual ~cmLocalVisualStudioGenerator();
protected:
+
+ /** Construct a script from the given list of command lines. */
+ std::string ConstructScript(const cmCustomCommandLines& commandLines,
+ const char* workingDirectory,
+ const char* newline = "\n");
+
// Safe object file name generation.
void ComputeObjectNameRequirements(std::vector<cmSourceGroup> const&);
bool SourceFileCompiles(const cmSourceFile* sf);