cmCustomCommandGenerator.cxx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. //----------------------------------------------------------------------------
  15. cmCustomCommandGenerator::cmCustomCommandGenerator(
  16. cmCustomCommand const& cc, const char* config, cmMakefile* mf):
  17. CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
  18. OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars())
  19. {
  20. }
  21. //----------------------------------------------------------------------------
  22. unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
  23. {
  24. return static_cast<unsigned int>(this->CC.GetCommandLines().size());
  25. }
  26. //----------------------------------------------------------------------------
  27. std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
  28. {
  29. std::string const& argv0 = this->CC.GetCommandLines()[c][0];
  30. cmTarget* target = this->Makefile->FindTargetToUse(argv0.c_str());
  31. if(target && target->GetType() == cmTarget::EXECUTABLE &&
  32. (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING")))
  33. {
  34. return target->GetLocation(this->Config);
  35. }
  36. return argv0;
  37. }
  38. //----------------------------------------------------------------------------
  39. void
  40. cmCustomCommandGenerator
  41. ::AppendArguments(unsigned int c, std::string& cmd) const
  42. {
  43. cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
  44. for(unsigned int j=1;j < commandLine.size(); ++j)
  45. {
  46. std::string const& arg = commandLine[j];
  47. cmd += " ";
  48. if(this->OldStyle)
  49. {
  50. cmd += this->LG->EscapeForShellOldStyle(arg.c_str());
  51. }
  52. else
  53. {
  54. cmd += this->LG->EscapeForShell(arg.c_str(), this->MakeVars);
  55. }
  56. }
  57. }