cmAddCustomCommandCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmAddCustomCommandCommand.h"
  14. // cmAddCustomCommandCommand
  15. bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. /* Let's complain at the end of this function about the lack of a particular
  18. arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
  19. required.
  20. */
  21. if (args.size() < 6)
  22. {
  23. this->SetError("called with wrong number of arguments.");
  24. return false;
  25. }
  26. std::string source, command, target;
  27. std::vector<std::string> command_args, depends, outputs;
  28. std::string outDir = m_Makefile->GetCurrentOutputDirectory();
  29. enum tdoing {
  30. doing_source,
  31. doing_command,
  32. doing_target,
  33. doing_args,
  34. doing_depends,
  35. doing_outputs,
  36. doing_nothing
  37. };
  38. tdoing doing = doing_nothing;
  39. for (unsigned int j = 0; j < args.size(); ++j)
  40. {
  41. std::string copy = args[j];
  42. m_Makefile->ExpandVariablesInString(copy);
  43. if(copy == "SOURCE")
  44. {
  45. doing = doing_source;
  46. }
  47. else if(copy == "COMMAND")
  48. {
  49. doing = doing_command;
  50. }
  51. else if(copy == "TARGET")
  52. {
  53. doing = doing_target;
  54. }
  55. else if(copy == "ARGS")
  56. {
  57. doing = doing_args;
  58. }
  59. else if (copy == "DEPENDS")
  60. {
  61. doing = doing_depends;
  62. }
  63. else if (copy == "OUTPUTS")
  64. {
  65. doing = doing_outputs;
  66. }
  67. else
  68. {
  69. switch (doing)
  70. {
  71. case doing_source:
  72. source = copy;
  73. break;
  74. case doing_command:
  75. command = copy;
  76. break;
  77. case doing_target:
  78. target = copy;
  79. break;
  80. case doing_args:
  81. command_args.push_back(copy);
  82. break;
  83. case doing_depends:
  84. depends.push_back(copy);
  85. break;
  86. case doing_outputs:
  87. outputs.push_back(copy);
  88. break;
  89. default:
  90. this->SetError("Wrong syntax. Unknow type of argument.");
  91. return false;
  92. }
  93. }
  94. }
  95. /* At this point we could complain about the lack of arguments.
  96. For the moment, let's say that SOURCE, COMMAND, TARGET are always
  97. required.
  98. */
  99. if(source.empty())
  100. {
  101. this->SetError("Wrong syntax. Empty SOURCE.");
  102. return false;
  103. }
  104. if(command.empty())
  105. {
  106. this->SetError("Wrong syntax. Empty COMMAND.");
  107. return false;
  108. }
  109. if(target.empty())
  110. {
  111. this->SetError("Wrong syntax. Empty TARGET.");
  112. return false;
  113. }
  114. m_Makefile->AddCustomCommand(source.c_str(),
  115. command.c_str(),
  116. command_args,
  117. depends,
  118. outputs,
  119. target.c_str());
  120. return true;
  121. }