cmAddCustomCommandCommand.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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& argsIn)
  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 COMMAND, TARGET are always
  19. required.
  20. */
  21. if (argsIn.size() < 4)
  22. {
  23. this->SetError("called with wrong number of arguments.");
  24. return false;
  25. }
  26. std::vector<std::string> args;
  27. cmSystemTools::ExpandListArguments(argsIn, args);
  28. std::string source, command, target;
  29. std::vector<std::string> command_args, depends, outputs;
  30. enum tdoing {
  31. doing_source,
  32. doing_command,
  33. doing_target,
  34. doing_args,
  35. doing_depends,
  36. doing_outputs,
  37. doing_nothing
  38. };
  39. tdoing doing = doing_nothing;
  40. for (unsigned int j = 0; j < args.size(); ++j)
  41. {
  42. std::string const& copy = args[j];
  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 COMMAND, TARGET are always
  97. required.
  98. */
  99. if(command.empty())
  100. {
  101. this->SetError("Wrong syntax. Empty COMMAND.");
  102. return false;
  103. }
  104. if(target.empty())
  105. {
  106. this->SetError("Wrong syntax. Empty TARGET.");
  107. return false;
  108. }
  109. // If source is empty, use target as source, so that this command
  110. // can be used to just attach a commmand to a target
  111. if(source.empty())
  112. {
  113. source = target;
  114. }
  115. m_Makefile->AddCustomCommand(source.c_str(),
  116. command.c_str(),
  117. command_args,
  118. depends,
  119. outputs,
  120. target.c_str());
  121. return true;
  122. }