cmAddCustomCommandCommand.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. #include "cmTarget.h"
  15. // cmAddCustomCommandCommand
  16. bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. /* Let's complain at the end of this function about the lack of a particular
  19. arg. For the moment, let's say that COMMAND, and either TARGET or SOURCE
  20. are required.
  21. */
  22. if (args.size() < 4)
  23. {
  24. this->SetError("called with wrong number of arguments.");
  25. return false;
  26. }
  27. std::string source, command, target, comment, output, main_dependency;
  28. std::vector<std::string> command_args, depends, outputs;
  29. cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
  30. enum tdoing {
  31. doing_source,
  32. doing_command,
  33. doing_target,
  34. doing_args,
  35. doing_depends,
  36. doing_main_dependency,
  37. doing_output,
  38. doing_outputs,
  39. doing_comment,
  40. doing_nothing
  41. };
  42. tdoing doing = doing_nothing;
  43. for (unsigned int j = 0; j < args.size(); ++j)
  44. {
  45. std::string const& copy = args[j];
  46. if(copy == "SOURCE")
  47. {
  48. doing = doing_source;
  49. }
  50. else if(copy == "COMMAND")
  51. {
  52. doing = doing_command;
  53. }
  54. else if(copy == "PRE_BUILD")
  55. {
  56. cctype = cmTarget::PRE_BUILD;
  57. }
  58. else if(copy == "PRE_LINK")
  59. {
  60. cctype = cmTarget::PRE_LINK;
  61. }
  62. else if(copy == "POST_BUILD")
  63. {
  64. cctype = cmTarget::POST_BUILD;
  65. }
  66. else if(copy == "TARGET")
  67. {
  68. doing = doing_target;
  69. }
  70. else if(copy == "ARGS")
  71. {
  72. doing = doing_args;
  73. }
  74. else if (copy == "DEPENDS")
  75. {
  76. doing = doing_depends;
  77. }
  78. else if (copy == "OUTPUTS")
  79. {
  80. doing = doing_outputs;
  81. }
  82. else if (copy == "OUTPUT")
  83. {
  84. doing = doing_output;
  85. }
  86. else if (copy == "MAIN_DEPENDENCY")
  87. {
  88. doing = doing_main_dependency;
  89. }
  90. else if (copy == "COMMENT")
  91. {
  92. doing = doing_comment;
  93. }
  94. else
  95. {
  96. switch (doing)
  97. {
  98. case doing_source:
  99. source = copy;
  100. break;
  101. case doing_output:
  102. output = copy;
  103. break;
  104. case doing_main_dependency:
  105. main_dependency = copy;
  106. break;
  107. case doing_command:
  108. command = copy;
  109. break;
  110. case doing_target:
  111. target = copy;
  112. break;
  113. case doing_args:
  114. command_args.push_back(copy);
  115. break;
  116. case doing_depends:
  117. depends.push_back(copy);
  118. break;
  119. case doing_outputs:
  120. outputs.push_back(copy);
  121. break;
  122. case doing_comment:
  123. comment = copy;
  124. break;
  125. default:
  126. this->SetError("Wrong syntax. Unknow type of argument.");
  127. return false;
  128. }
  129. }
  130. }
  131. /* At this point we could complain about the lack of arguments.
  132. For the moment, let's say that COMMAND, TARGET are always
  133. required.
  134. */
  135. if (output.empty() && target.empty())
  136. {
  137. this->SetError("Wrong syntax. A TARGET or OUTPUT must be specified.");
  138. return false;
  139. }
  140. // If source is empty, use the target
  141. if(source.empty() && output.empty())
  142. {
  143. m_Makefile->AddCustomCommandToTarget(target.c_str(),
  144. command.c_str(),
  145. command_args,
  146. cctype,
  147. comment.c_str());
  148. return true;
  149. }
  150. // If target is empty, use the output
  151. if(target.empty())
  152. {
  153. m_Makefile->AddCustomCommandToOutput(output.c_str(),
  154. command.c_str(),
  155. command_args,
  156. main_dependency.c_str(),
  157. depends,
  158. comment.c_str());
  159. return true;
  160. }
  161. // otherwise backwards compatiblity mode
  162. m_Makefile->AddCustomCommand(source.c_str(),
  163. command.c_str(),
  164. command_args,
  165. depends,
  166. outputs,
  167. target.c_str(),
  168. comment.c_str());
  169. return true;
  170. }