FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmSourceGroup.cxx
blobf556605d6a715c3034bf72881d62377b98c0c182
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmSourceGroup.cxx,v $
5 Language: C++
6 Date: $Date: 2002-03-13 15:25:10 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmSourceGroup.h"
20 /**
21 * The constructor initializes the group's regular expression.
23 cmSourceGroup::cmSourceGroup(const char* name, const char* regex):
24 m_Name(name),
25 m_GroupRegex(regex)
30 /**
31 * Copy constructor.
33 cmSourceGroup::cmSourceGroup(const cmSourceGroup& r):
34 m_Name(r.m_Name),
35 m_GroupRegex(r.m_GroupRegex),
36 m_BuildRules(r.m_BuildRules)
41 /**
42 * Returns whether the given name matches the group's regular expression.
44 bool cmSourceGroup::Matches(const char* name)
46 return m_GroupRegex.find(name);
50 /**
51 * Add a source to the group that the compiler will know how to build.
53 void cmSourceGroup::AddSource(const char* name, const cmSourceFile* sf)
55 BuildRules::iterator s = m_BuildRules.find(name);
56 if(s == m_BuildRules.end())
58 SourceAndCommands sc;
59 sc.m_SourceFile = sf;
60 // The source was not found. Add it with no commands.
61 m_BuildRules[name] = sc;
62 return;
67 /**
68 * Add a source and corresponding custom command to the group. If the
69 * source already exists, the command will be added to its set of commands.
70 * If the command also already exists, the given dependencies and outputs
71 * are added to it.
73 void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
75 std::string commandAndArgs = cmd.GetCommandAndArguments();
76 BuildRules::iterator s = m_BuildRules.find(cmd.GetSourceName());
77 if(s == m_BuildRules.end())
79 // The source was not found. Add it with this command.
80 CommandFiles& cmdFiles =
81 m_BuildRules[cmd.GetSourceName()].m_Commands[commandAndArgs];
82 cmdFiles.m_Command = cmd.GetCommand();
83 cmdFiles.m_Arguments = cmd.GetArguments();
84 cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
85 cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
86 return;
89 // The source already exists. See if the command exists.
90 Commands& commands = s->second.m_Commands;
91 Commands::iterator c = commands.find(commandAndArgs);
92 if(c == commands.end())
94 // The command did not exist. Add it.
95 commands[commandAndArgs].m_Command = cmd.GetCommand();
96 commands[commandAndArgs].m_Arguments = cmd.GetArguments();
97 commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
98 cmd.GetDepends().end());
99 commands[commandAndArgs].m_Outputs.insert(cmd.GetOutputs().begin(),
100 cmd.GetOutputs().end());
101 return;
104 // The command already exists for this source. Merge the sets.
105 CommandFiles& commandFiles = c->second;
106 commandFiles.m_Depends.insert(cmd.GetDepends().begin(),
107 cmd.GetDepends().end());
108 commandFiles.m_Outputs.insert(cmd.GetOutputs().begin(),
109 cmd.GetOutputs().end());
112 void cmSourceGroup::Print() const
114 std::cout << "cmSourceGroup: " << m_Name.c_str() << "\n";
115 for(BuildRules::const_iterator i = m_BuildRules.begin();
116 i != m_BuildRules.end(); ++i)
118 std::cout << "BuildRule: " << i->first.c_str() << "\n";
119 for(Commands::const_iterator j = i->second.m_Commands.begin();
120 j != i->second.m_Commands.end(); ++j)
122 std::cout << "FullCommand: " << j->first.c_str() << "\n";
123 std::cout << "Command: " << j->second.m_Command.c_str() << "\n";
124 std::cout << "Arguments: " << j->second.m_Arguments.c_str() << "\n";
125 std::cout << "Command Outputs "
126 << static_cast<int>(j->second.m_Outputs.size()) << "\n";
127 std::cout << "Command Depends "
128 << static_cast<int>(j->second.m_Depends.size()) << "\n";
134 void cmSourceGroup::CommandFiles::Merge(const CommandFiles &r)
136 std::set<std::string>::const_iterator dep = r.m_Depends.begin();
137 std::set<std::string>::const_iterator out = r.m_Outputs.begin();
138 for (;dep != r.m_Depends.end(); ++dep)
140 this->m_Depends.insert(*dep);
142 for (;out != r.m_Outputs.end(); ++out)
144 this->m_Outputs.insert(*out);