cmCustomCommandGenerator.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 char* config, cmMakefile* mf):
  18. CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
  19. OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
  20. GE(new cmGeneratorExpression(mf, config, 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.c_str());
  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->Process(argv0);
  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->Process(commandLine[j]);
  54. cmd += " ";
  55. if(this->OldStyle)
  56. {
  57. cmd += this->LG->EscapeForShellOldStyle(arg.c_str());
  58. }
  59. else
  60. {
  61. cmd += this->LG->EscapeForShell(arg.c_str(), this->MakeVars);
  62. }
  63. }
  64. }