cmAddCustomCommandCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmAddCustomCommandCommand.h"
  12. // cmAddCustomCommandCommand
  13. bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
  14. {
  15. /* Let's complain at the end of this function about the lack of a particular
  16. arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
  17. required.
  18. */
  19. if (args.size() < 6)
  20. {
  21. this->SetError("called with wrong number of arguments.");
  22. return false;
  23. }
  24. std::string source, command, target;
  25. std::vector<std::string> command_args, depends, outputs;
  26. enum tdoing {
  27. doing_source,
  28. doing_command,
  29. doing_target,
  30. doing_args,
  31. doing_depends,
  32. doing_outputs,
  33. doing_nothing
  34. };
  35. tdoing doing = doing_nothing;
  36. for (unsigned int j = 0; j < args.size(); ++j)
  37. {
  38. std::string copy = args[j];
  39. m_Makefile->ExpandVariablesInString(copy);
  40. if(copy == "SOURCE")
  41. {
  42. doing = doing_source;
  43. }
  44. else if(copy == "COMMAND")
  45. {
  46. doing = doing_command;
  47. }
  48. else if(copy == "TARGET")
  49. {
  50. doing = doing_target;
  51. }
  52. else if(copy == "ARGS")
  53. {
  54. doing = doing_args;
  55. }
  56. else if (copy == "DEPENDS")
  57. {
  58. doing = doing_depends;
  59. }
  60. else if (copy == "OUTPUTS")
  61. {
  62. doing = doing_outputs;
  63. }
  64. else
  65. {
  66. switch (doing)
  67. {
  68. case doing_source:
  69. source = copy;
  70. break;
  71. case doing_command:
  72. command = copy;
  73. break;
  74. case doing_target:
  75. target = copy;
  76. break;
  77. case doing_args:
  78. command_args.push_back(copy);
  79. break;
  80. case doing_depends:
  81. depends.push_back(copy);
  82. break;
  83. case doing_outputs:
  84. outputs.push_back(copy);
  85. break;
  86. default:
  87. this->SetError("Wrong syntax. Unknow type of argument.");
  88. return false;
  89. }
  90. }
  91. }
  92. /* At this point we could complain about the lack of arguments.
  93. For the moment, let's say that SOURCE, COMMAND, TARGET are always
  94. required.
  95. */
  96. if(source.empty())
  97. {
  98. this->SetError("Wrong syntax. Empty SOURCE.");
  99. return false;
  100. }
  101. if(command.empty())
  102. {
  103. this->SetError("Wrong syntax. Empty COMMAND.");
  104. return false;
  105. }
  106. if(target.empty())
  107. {
  108. this->SetError("Wrong syntax. Empty TARGET.");
  109. return false;
  110. }
  111. m_Makefile->AddCustomCommand(source.c_str(),
  112. command.c_str(),
  113. command_args,
  114. depends,
  115. outputs,
  116. target.c_str());
  117. return true;
  118. }