diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index b67214854..ac2eef80e 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -100,16 +100,6 @@ const std::vector& cmCustomCommand::GetOutputs() const return this->Outputs; } -//---------------------------------------------------------------------------- -const char* cmCustomCommand::GetWorkingDirectory() const -{ - if(this->WorkingDirectory.size() == 0) - { - return 0; - } - return this->WorkingDirectory.c_str(); -} - //---------------------------------------------------------------------------- const std::vector& cmCustomCommand::GetDepends() const { diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 67c305e55..b5d7e6215 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -42,12 +42,13 @@ public: /** Get the output file produced by the command. */ const std::vector& GetOutputs() const; - /** Get the working directory. */ - const char* GetWorkingDirectory() const; - /** Get the vector that holds the list of dependencies. */ const std::vector& GetDepends() const; + /** Get the working directory. */ + std::string const& GetWorkingDirectory() const + { return this->WorkingDirectory; } + /** Get the list of command lines. */ const cmCustomCommandLines& GetCommandLines() const; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 30a2a1ec3..16c74b97b 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1646,10 +1646,11 @@ void cmGlobalXCodeGenerator cmSystemTools::ReplaceString(cmd2, "/./", "/"); cmd2 = this->ConvertToRelativeForMake(cmd2.c_str()); std::string cmd; - if(cc.GetWorkingDirectory()) + std::string wd = cc.GetWorkingDirectory(); + if(!wd.empty()) { cmd += "cd "; - cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory()); + cmd += this->ConvertToRelativeForMake(wd.c_str()); cmd += " && "; } cmd += cmd2; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index acaacdda3..d68a07bc0 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -364,8 +364,8 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(const cmCustomCommand *cc, { cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile); if (ccg.GetNumberOfCommands() > 0) { - const char* wd = cc->GetWorkingDirectory(); - if (!wd) + std::string wd = cc->GetWorkingDirectory(); + if (wd.empty()) wd = this->GetMakefile()->GetStartOutputDirectory(); cmOStringStream cdCmd; @@ -491,7 +491,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher( if(!outputs.empty()) { RelativeRoot relative_root = - cc.GetWorkingDirectory() ? NONE : START_OUTPUT; + cc.GetWorkingDirectory().empty() ? START_OUTPUT : NONE; output = this->Convert(outputs[0], relative_root, SHELL); } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 3681e0e53..d3f63f51d 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1023,9 +1023,9 @@ cmLocalUnixMakefileGenerator3 } // if the command specified a working directory use it. - const char* dir = this->Makefile->GetStartOutputDirectory(); - const char* workingDir = cc.GetWorkingDirectory(); - if(workingDir) + std::string dir = this->Makefile->GetStartOutputDirectory(); + std::string workingDir = cc.GetWorkingDirectory(); + if(!workingDir.empty()) { dir = workingDir; } @@ -1066,7 +1066,7 @@ cmLocalUnixMakefileGenerator3 // Convert the command to a relative path only if the current // working directory will be the start-output directory. bool had_slash = cmd.find("/") != cmd.npos; - if(!workingDir) + if(workingDir.empty()) { cmd = this->Convert(cmd,START_OUTPUT); } @@ -1079,7 +1079,8 @@ cmLocalUnixMakefileGenerator3 cmd = "./" + cmd; } std::string launcher = - this->MakeLauncher(cc, target, workingDir? NONE : START_OUTPUT); + this->MakeLauncher(cc, target, + workingDir.empty()? START_OUTPUT : NONE); cmd = launcher + this->ConvertShellCommand(cmd, NONE); ccg.AppendArguments(c, cmd); @@ -1125,7 +1126,7 @@ cmLocalUnixMakefileGenerator3 } // Setup the proper working directory for the commands. - this->CreateCDCommand(commands1, dir, relative); + this->CreateCDCommand(commands1, dir.c_str(), relative); // push back the custom commands commands.insert(commands.end(), commands1.begin(), commands1.end()); diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index f1fd99461..d7130248b 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -583,7 +583,7 @@ cmLocalVisualStudio6Generator this->Makefile->AddCustomCommandToOutput( output, depends, no_main_dependency, origCommand.GetCommandLines(), comment.c_str(), - origCommand.GetWorkingDirectory())) + origCommand.GetWorkingDirectory().c_str())) { target.AddSourceFile(outsf); } diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 6e93d22c2..3075c1567 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -84,9 +84,9 @@ cmLocalVisualStudioGenerator const std::string& newline_text) { bool useLocal = this->CustomCommandUseLocal(); - const char* workingDirectory = cc.GetWorkingDirectory(); + std::string workingDirectory = cc.GetWorkingDirectory(); cmCustomCommandGenerator ccg(cc, configName, this->Makefile); - RelativeRoot relativeRoot = workingDirectory? NONE : START_OUTPUT; + RelativeRoot relativeRoot = workingDirectory.empty()? START_OUTPUT : NONE; // Avoid leading or trailing newlines. std::string newline = ""; @@ -114,7 +114,7 @@ cmLocalVisualStudioGenerator script += "setlocal"; } - if(workingDirectory) + if(!workingDirectory.empty()) { // Change the working directory. script += newline; @@ -124,7 +124,7 @@ cmLocalVisualStudioGenerator script += check_error; // Change the working drive. - if(workingDirectory[0] && workingDirectory[1] == ':') + if(workingDirectory.size() > 1 && workingDirectory[1] == ':') { script += newline; newline = newline_text;