cmAddCustomCommandCommand.cxx 3.4 KB

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