cmAddCustomCommandCommand.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. std::string outDir = m_Makefile->GetCurrentOutputDirectory();
  31. enum tdoing {
  32. doing_source,
  33. doing_command,
  34. doing_target,
  35. doing_args,
  36. doing_depends,
  37. doing_outputs,
  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
  69. {
  70. switch (doing)
  71. {
  72. case doing_source:
  73. source = copy;
  74. break;
  75. case doing_command:
  76. command = copy;
  77. break;
  78. case doing_target:
  79. target = copy;
  80. break;
  81. case doing_args:
  82. command_args.push_back(copy);
  83. break;
  84. case doing_depends:
  85. depends.push_back(copy);
  86. break;
  87. case doing_outputs:
  88. outputs.push_back(copy);
  89. break;
  90. default:
  91. this->SetError("Wrong syntax. Unknow type of argument.");
  92. return false;
  93. }
  94. }
  95. }
  96. /* At this point we could complain about the lack of arguments.
  97. For the moment, let's say that COMMAND, TARGET are always
  98. required.
  99. */
  100. if(command.empty())
  101. {
  102. this->SetError("Wrong syntax. Empty COMMAND.");
  103. return false;
  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. return true;
  123. }