cmAddCustomCommandCommand.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // 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, comment;
  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_comment,
  38. doing_nothing
  39. };
  40. tdoing doing = doing_nothing;
  41. for (unsigned int j = 0; j < args.size(); ++j)
  42. {
  43. std::string const& copy = args[j];
  44. if(copy == "SOURCE")
  45. {
  46. doing = doing_source;
  47. }
  48. else if(copy == "COMMAND")
  49. {
  50. doing = doing_command;
  51. }
  52. else if(copy == "TARGET")
  53. {
  54. doing = doing_target;
  55. }
  56. else if(copy == "ARGS")
  57. {
  58. doing = doing_args;
  59. }
  60. else if (copy == "DEPENDS")
  61. {
  62. doing = doing_depends;
  63. }
  64. else if (copy == "OUTPUTS")
  65. {
  66. doing = doing_outputs;
  67. }
  68. else if (copy == "COMMENT")
  69. {
  70. doing = doing_comment;
  71. }
  72. else
  73. {
  74. switch (doing)
  75. {
  76. case doing_source:
  77. source = copy;
  78. break;
  79. case doing_command:
  80. command = copy;
  81. break;
  82. case doing_target:
  83. target = copy;
  84. break;
  85. case doing_args:
  86. command_args.push_back(copy);
  87. break;
  88. case doing_depends:
  89. depends.push_back(copy);
  90. break;
  91. case doing_outputs:
  92. outputs.push_back(copy);
  93. break;
  94. case doing_comment:
  95. comment = copy;
  96. break;
  97. default:
  98. this->SetError("Wrong syntax. Unknow type of argument.");
  99. return false;
  100. }
  101. }
  102. }
  103. /* At this point we could complain about the lack of arguments.
  104. For the moment, let's say that COMMAND, TARGET are always
  105. required.
  106. */
  107. if(target.empty())
  108. {
  109. this->SetError("Wrong syntax. Empty TARGET.");
  110. return false;
  111. }
  112. // If source is empty, use target as source, so that this command
  113. // can be used to just attach a commmand to a target
  114. if(source.empty())
  115. {
  116. source = target;
  117. }
  118. m_Makefile->AddCustomCommand(source.c_str(),
  119. command.c_str(),
  120. command_args,
  121. depends,
  122. outputs,
  123. target.c_str(),
  124. comment.c_str());
  125. return true;
  126. }