cmSourceGroup.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 "cmSourceGroup.h"
  14. /**
  15. * The constructor initializes the group's regular expression.
  16. */
  17. cmSourceGroup::cmSourceGroup(const char* name, const char* regex):
  18. m_Name(name),
  19. m_GroupRegex(regex)
  20. {
  21. }
  22. /**
  23. * Copy constructor.
  24. */
  25. cmSourceGroup::cmSourceGroup(const cmSourceGroup& r):
  26. m_Name(r.m_Name),
  27. m_GroupRegex(r.m_GroupRegex),
  28. m_BuildRules(r.m_BuildRules)
  29. {
  30. }
  31. /**
  32. * Returns whether the given name matches the group's regular expression.
  33. */
  34. bool cmSourceGroup::Matches(const char* name)
  35. {
  36. return m_GroupRegex.find(name);
  37. }
  38. /**
  39. * Add a source to the group that the compiler will know how to build.
  40. */
  41. void cmSourceGroup::AddSource(const char* name, const cmSourceFile* sf)
  42. {
  43. BuildRules::iterator s = m_BuildRules.find(name);
  44. if(s == m_BuildRules.end())
  45. {
  46. SourceAndCommands sc;
  47. sc.m_SourceFile = sf;
  48. // The source was not found. Add it with no commands.
  49. m_BuildRules[name] = sc;
  50. return;
  51. }
  52. }
  53. /**
  54. * Add a source and corresponding custom command to the group. If the
  55. * source already exists, the command will be added to its set of commands.
  56. * If the command also already exists, the given dependencies and outputs
  57. * are added to it.
  58. */
  59. void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
  60. {
  61. std::string commandAndArgs = cmd.GetCommandAndArguments();
  62. BuildRules::iterator s = m_BuildRules.find(cmd.GetSourceName());
  63. if(s == m_BuildRules.end())
  64. {
  65. // The source was not found. Add it with this command.
  66. CommandFiles& cmdFiles =
  67. m_BuildRules[cmd.GetSourceName()].m_Commands[commandAndArgs];
  68. cmdFiles.m_Command = cmd.GetCommand();
  69. cmdFiles.m_Arguments = cmd.GetArguments();
  70. cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
  71. cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
  72. return;
  73. }
  74. // The source already exists. See if the command exists.
  75. Commands& commands = s->second.m_Commands;
  76. Commands::iterator c = commands.find(commandAndArgs);
  77. if(c == commands.end())
  78. {
  79. // The command did not exist. Add it.
  80. commands[commandAndArgs].m_Command = cmd.GetCommand();
  81. commands[commandAndArgs].m_Arguments = cmd.GetArguments();
  82. commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
  83. cmd.GetDepends().end());
  84. commands[commandAndArgs].m_Outputs.insert(cmd.GetOutputs().begin(),
  85. cmd.GetOutputs().end());
  86. return;
  87. }
  88. // The command already exists for this source. Merge the sets.
  89. CommandFiles& commandFiles = c->second;
  90. commandFiles.m_Depends.insert(cmd.GetDepends().begin(),
  91. cmd.GetDepends().end());
  92. commandFiles.m_Outputs.insert(cmd.GetOutputs().begin(),
  93. cmd.GetOutputs().end());
  94. }
  95. void cmSourceGroup::Print() const
  96. {
  97. std::cout << "cmSourceGroup: " << m_Name.c_str() << "\n";
  98. for(BuildRules::const_iterator i = m_BuildRules.begin();
  99. i != m_BuildRules.end(); ++i)
  100. {
  101. std::cout << "BuildRule: " << i->first.c_str() << "\n";
  102. for(Commands::const_iterator j = i->second.m_Commands.begin();
  103. j != i->second.m_Commands.end(); ++j)
  104. {
  105. std::cout << "FullCommand: " << j->first.c_str() << "\n";
  106. std::cout << "Command: " << j->second.m_Command.c_str() << "\n";
  107. std::cout << "Arguments: " << j->second.m_Arguments.c_str() << "\n";
  108. std::cout << "Command Outputs " << j->second.m_Outputs.size() << "\n";
  109. std::cout << "Command Depends " << j->second.m_Depends.size() << "\n";
  110. }
  111. }
  112. }
  113. void cmSourceGroup::CommandFiles::Merge(const CommandFiles &r)
  114. {
  115. std::set<std::string>::const_iterator dep = r.m_Depends.begin();
  116. std::set<std::string>::const_iterator out = r.m_Outputs.begin();
  117. for (;dep != r.m_Depends.end(); ++dep)
  118. {
  119. this->m_Depends.insert(*dep);
  120. }
  121. for (;out != r.m_Outputs.end(); ++out)
  122. {
  123. this->m_Outputs.insert(*out);
  124. }
  125. }