1
0

cmAddCustomCommandCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. std::string outDir = m_Makefile->GetCurrentOutputDirectory();
  27. enum tdoing {
  28. doing_source,
  29. doing_command,
  30. doing_target,
  31. doing_args,
  32. doing_depends,
  33. doing_outputs,
  34. doing_nothing
  35. };
  36. tdoing doing = doing_nothing;
  37. for (unsigned int j = 0; j < args.size(); ++j)
  38. {
  39. std::string copy = args[j];
  40. m_Makefile->ExpandVariablesInString(copy);
  41. if(copy == "SOURCE")
  42. {
  43. doing = doing_source;
  44. }
  45. else if(copy == "COMMAND")
  46. {
  47. doing = doing_command;
  48. }
  49. else if(copy == "TARGET")
  50. {
  51. doing = doing_target;
  52. }
  53. else if(copy == "ARGS")
  54. {
  55. doing = doing_args;
  56. }
  57. else if (copy == "DEPENDS")
  58. {
  59. doing = doing_depends;
  60. }
  61. else if (copy == "OUTPUTS")
  62. {
  63. doing = doing_outputs;
  64. }
  65. else
  66. {
  67. switch (doing)
  68. {
  69. case doing_source:
  70. source = copy;
  71. break;
  72. case doing_command:
  73. command = copy;
  74. break;
  75. case doing_target:
  76. target = copy;
  77. break;
  78. case doing_args:
  79. command_args.push_back(copy);
  80. break;
  81. case doing_depends:
  82. depends.push_back(copy);
  83. break;
  84. case doing_outputs:
  85. outputs.push_back(copy);
  86. break;
  87. default:
  88. this->SetError("Wrong syntax. Unknow type of argument.");
  89. return false;
  90. }
  91. }
  92. }
  93. /* At this point we could complain about the lack of arguments.
  94. For the moment, let's say that SOURCE, COMMAND, TARGET are always
  95. required.
  96. */
  97. if(source.empty())
  98. {
  99. this->SetError("Wrong syntax. Empty SOURCE.");
  100. return false;
  101. }
  102. if(command.empty())
  103. {
  104. this->SetError("Wrong syntax. Empty COMMAND.");
  105. return false;
  106. }
  107. if(target.empty())
  108. {
  109. this->SetError("Wrong syntax. Empty TARGET.");
  110. return false;
  111. }
  112. m_Makefile->AddCustomCommand(source.c_str(),
  113. command.c_str(),
  114. command_args,
  115. depends,
  116. outputs,
  117. target.c_str());
  118. // All this is a hack for now
  119. int cc = outputs.size()-1;
  120. while( cc >= 0 )
  121. {
  122. std::string fileName = outputs[cc];
  123. std::string directory = cmSystemTools::GetFilenamePath(fileName);
  124. if ( directory == std::string() )
  125. {
  126. directory = outDir;
  127. }
  128. fileName = cmSystemTools::GetFilenameName(fileName);
  129. std::string::size_type pos = fileName.rfind(".");
  130. fileName = fileName.substr(0, pos);
  131. // Add the generated source to the package target's source list.
  132. cmSourceFile file;
  133. file.SetName(fileName.c_str(), directory.c_str(), "c", false);
  134. m_Makefile->AddSource(file, target.c_str());
  135. cc--;
  136. }
  137. if ( outputs.size() > 0 )
  138. {
  139. std::cout << "Target: " << target << std::endl;
  140. m_Makefile->GetTargets()[target.c_str()].GetSourceLists().push_back(target);
  141. }
  142. return true;
  143. }