summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalVisualStudioGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-04-11 14:07:40 (GMT)
committerBrad King <brad.king@kitware.com>2011-04-11 15:53:31 (GMT)
commitb98fdd52848b45f97f8a38eaa7749186f6c8fab3 (patch)
tree37dbb31f8d0b8c842541aaa737f169c030c14b87 /Source/cmLocalVisualStudioGenerator.cxx
parent06fcbc4757c7a52733a554d4050735452d49a5e7 (diff)
downloadCMake-b98fdd52848b45f97f8a38eaa7749186f6c8fab3.zip
CMake-b98fdd52848b45f97f8a38eaa7749186f6c8fab3.tar.gz
CMake-b98fdd52848b45f97f8a38eaa7749186f6c8fab3.tar.bz2
VS: Use setlocal/endlocal only in VS 10 custom commands
The setlocal/endlocal and errorlevel pattern added by commit 06fcbc47 (VS10: Fix working directory of consecutive custom commands, 2011-04-08) does not work well in VS 7.1. Restore the original behavior for VS versions that do not need the new behavior.
Diffstat (limited to 'Source/cmLocalVisualStudioGenerator.cxx')
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx50
1 files changed, 37 insertions, 13 deletions
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index b2057b8..f3936e1 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -170,29 +170,47 @@ std::string
cmLocalVisualStudioGenerator
::ConstructScript(cmCustomCommand const& cc,
const char* configName,
- const char* newline)
+ const char* newline_text)
{
+ bool useLocal = this->CustomCommandUseLocal();
const cmCustomCommandLines& commandLines = cc.GetCommandLines();
const char* workingDirectory = cc.GetWorkingDirectory();
cmCustomCommandGenerator ccg(cc, configName, this->Makefile);
RelativeRoot relativeRoot = workingDirectory? NONE : START_OUTPUT;
+ // Avoid leading or trailing newlines.
+ const char* newline = "";
+
// Line to check for error between commands.
- std::string check_error = newline;
- check_error += "if %errorlevel% neq 0 goto :cmEnd";
+ std::string check_error = newline_text;
+ if(useLocal)
+ {
+ check_error += "if %errorlevel% neq 0 goto :cmEnd";
+ }
+ else
+ {
+ check_error += "if errorlevel 1 goto ";
+ check_error += this->GetReportErrorLabel();
+ }
// Store the script in a string.
std::string script;
// Open a local context.
- script += "set errlev=";
- script += newline;
- script += "setlocal";
+ if(useLocal)
+ {
+ script += newline;
+ newline = newline_text;
+ script += "set errlev=";
+ script += newline;
+ script += "setlocal";
+ }
if(workingDirectory)
{
// Change the working directory.
script += newline;
+ newline = newline_text;
script += "cd ";
script += this->Convert(workingDirectory, FULL, SHELL);
script += check_error;
@@ -201,6 +219,7 @@ cmLocalVisualStudioGenerator
if(workingDirectory[0] && workingDirectory[1] == ':')
{
script += newline;
+ newline = newline_text;
script += workingDirectory[0];
script += workingDirectory[1];
script += check_error;
@@ -216,6 +235,7 @@ cmLocalVisualStudioGenerator
if(extraPath)
{
script += newline;
+ newline = newline_text;
script += "set PATH=";
script += extraPath;
script += ";%PATH%";
@@ -227,6 +247,7 @@ cmLocalVisualStudioGenerator
{
// Start a new line.
script += newline;
+ newline = newline_text;
// Add this command line.
std::string cmd = ccg.GetCommand(c);
@@ -241,13 +262,16 @@ cmLocalVisualStudioGenerator
}
// Close the local context.
- script += newline;
- script += ":cmEnd";
- script += newline;
- script += "endlocal & set errlev=%errorlevel%";
- script += newline;
- script += "if %errlev% neq 0 goto ";
- script += this->GetReportErrorLabel();
+ if(useLocal)
+ {
+ script += newline;
+ script += ":cmEnd";
+ script += newline;
+ script += "endlocal & set errlev=%errorlevel%";
+ script += newline;
+ script += "if %errlev% neq 0 goto ";
+ script += this->GetReportErrorLabel();
+ }
return script;
}