cmCustomCommandGenerator.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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())), DependsDone(false)
  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);
  59. }
  60. else
  61. {
  62. cmd += this->LG->EscapeForShell(arg, this->MakeVars);
  63. }
  64. }
  65. }
  66. //----------------------------------------------------------------------------
  67. const char* cmCustomCommandGenerator::GetComment() const
  68. {
  69. return this->CC.GetComment();
  70. }
  71. //----------------------------------------------------------------------------
  72. std::string cmCustomCommandGenerator::GetWorkingDirectory() const
  73. {
  74. return this->CC.GetWorkingDirectory();
  75. }
  76. //----------------------------------------------------------------------------
  77. std::vector<std::string> const& cmCustomCommandGenerator::GetOutputs() const
  78. {
  79. return this->CC.GetOutputs();
  80. }
  81. //----------------------------------------------------------------------------
  82. std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const
  83. {
  84. if (!this->DependsDone)
  85. {
  86. this->DependsDone = true;
  87. std::vector<std::string> depends = this->CC.GetDepends();
  88. for(std::vector<std::string>::const_iterator
  89. i = depends.begin();
  90. i != depends.end(); ++i)
  91. {
  92. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  93. = this->GE->Parse(*i);
  94. std::vector<std::string> result;
  95. cmSystemTools::ExpandListArgument(
  96. cge->Evaluate(this->Makefile, this->Config), result);
  97. for (std::vector<std::string>::iterator it = result.begin();
  98. it != result.end(); ++it)
  99. {
  100. if (cmSystemTools::FileIsFullPath(it->c_str()))
  101. {
  102. *it = cmSystemTools::CollapseFullPath(*it);
  103. }
  104. }
  105. this->Depends.insert(this->Depends.end(), result.begin(), result.end());
  106. }
  107. }
  108. return this->Depends;
  109. }