cmCustomCommandGenerator.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2010 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCustomCommandGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmCustomCommand.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGeneratorExpression.h"
  15. //----------------------------------------------------------------------------
  16. cmCustomCommandGenerator::cmCustomCommandGenerator(
  17. cmCustomCommand const& cc, const std::string& config, cmMakefile* mf):
  18. CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
  19. OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
  20. GE(new cmGeneratorExpression(cc.GetBacktrace()))
  21. {
  22. }
  23. //----------------------------------------------------------------------------
  24. cmCustomCommandGenerator::~cmCustomCommandGenerator()
  25. {
  26. delete this->GE;
  27. }
  28. //----------------------------------------------------------------------------
  29. unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
  30. {
  31. return static_cast<unsigned int>(this->CC.GetCommandLines().size());
  32. }
  33. //----------------------------------------------------------------------------
  34. std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
  35. {
  36. std::string const& argv0 = this->CC.GetCommandLines()[c][0];
  37. cmTarget* target = this->Makefile->FindTargetToUse(argv0);
  38. if(target && target->GetType() == cmTarget::EXECUTABLE &&
  39. (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING")))
  40. {
  41. return target->GetLocation(this->Config);
  42. }
  43. return this->GE->Parse(argv0)->Evaluate(this->Makefile, this->Config);
  44. }
  45. //----------------------------------------------------------------------------
  46. void
  47. cmCustomCommandGenerator
  48. ::AppendArguments(unsigned int c, std::string& cmd) const
  49. {
  50. cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
  51. for(unsigned int j=1;j < commandLine.size(); ++j)
  52. {
  53. std::string arg = this->GE->Parse(commandLine[j])->Evaluate(this->Makefile,
  54. this->Config);
  55. cmd += " ";
  56. if(this->OldStyle)
  57. {
  58. cmd += this->LG->EscapeForShellOldStyle(arg.c_str());
  59. }
  60. else
  61. {
  62. cmd += this->LG->EscapeForShell(arg.c_str(), this->MakeVars);
  63. }
  64. }
  65. }