cmAddCustomCommandCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 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;
  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 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
  67. {
  68. switch (doing)
  69. {
  70. case doing_source:
  71. source = copy;
  72. break;
  73. case doing_command:
  74. command = copy;
  75. break;
  76. case doing_target:
  77. target = copy;
  78. break;
  79. case doing_args:
  80. command_args.push_back(copy);
  81. break;
  82. case doing_depends:
  83. depends.push_back(copy);
  84. break;
  85. case doing_outputs:
  86. outputs.push_back(copy);
  87. break;
  88. default:
  89. this->SetError("Wrong syntax. Unknow type of argument.");
  90. return false;
  91. }
  92. }
  93. }
  94. /* At this point we could complain about the lack of arguments.
  95. For the moment, let's say that COMMAND, TARGET are always
  96. required.
  97. */
  98. if(command.empty())
  99. {
  100. this->SetError("Wrong syntax. Empty COMMAND.");
  101. return false;
  102. }
  103. if(target.empty())
  104. {
  105. this->SetError("Wrong syntax. Empty TARGET.");
  106. return false;
  107. }
  108. // If source is empty, use target as source, so that this command
  109. // can be used to just attach a commmand to a target
  110. if(source.empty())
  111. {
  112. source = target;
  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. }