packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmSetSourceFilesPropertiesCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmSetSourceFilesPropertiesCommand.h"
13
14 #include "cmSourceFile.h"
15
16 // cmSetSourceFilesPropertiesCommand
17 bool cmSetSourceFilesPropertiesCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() < 2 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25
26   // break the arguments into source file names and properties
27   int numFiles = 0;
28   std::vector<std::string>::const_iterator j;
29   j = args.begin();
30   // old style allows for specifier before PROPERTIES keyword
31   while (j != args.end() &&
32          *j != "ABSTRACT" &&
33          *j != "WRAP_EXCLUDE" &&
34          *j != "GENERATED" &&
35          *j != "COMPILE_FLAGS" &&
36          *j != "OBJECT_DEPENDS" &&
37          *j != "PROPERTIES")
38     {
39     numFiles++;
40     ++j;
41     }
42
43   // now call the worker function
44   std::string errors;
45   bool ret =
46     cmSetSourceFilesPropertiesCommand
47     ::RunCommand(this->Makefile,
48                  args.begin(),
49                  args.begin() + numFiles,
50                  args.begin() + numFiles,
51                  args.end(), errors);
52   if (!ret)
53     {
54     this->SetError(errors.c_str());
55     }
56   return ret;
57 }
58
59 bool cmSetSourceFilesPropertiesCommand
60 ::RunCommand(cmMakefile *mf,
61              std::vector<std::string>::const_iterator filebeg,
62              std::vector<std::string>::const_iterator fileend,
63              std::vector<std::string>::const_iterator propbeg,
64              std::vector<std::string>::const_iterator propend,
65              std::string &errors)
66 {
67   std::vector<std::string> propertyPairs;
68   bool generated = false;
69   std::vector<std::string>::const_iterator j;
70   // build the property pairs
71   for(j= propbeg; j != propend;++j)
72     {
73     // old style allows for specifier before PROPERTIES keyword
74     if(*j == "ABSTRACT")
75       {
76       propertyPairs.push_back("ABSTRACT");
77       propertyPairs.push_back("1");
78       }
79     else if(*j == "WRAP_EXCLUDE")
80       {
81       propertyPairs.push_back("WRAP_EXCLUDE");
82       propertyPairs.push_back("1");
83       }
84     else if(*j == "GENERATED")
85       {
86       generated = true;
87       propertyPairs.push_back("GENERATED");
88       propertyPairs.push_back("1");
89       }
90     else if(*j == "COMPILE_FLAGS")
91       {
92       propertyPairs.push_back("COMPILE_FLAGS");
93       ++j;
94       if(j == propend)
95         {
96         errors = "called with incorrect number of arguments "
97           "COMPILE_FLAGS with no flags";
98         return false;
99         }
100       propertyPairs.push_back(*j);
101       }
102     else if(*j == "OBJECT_DEPENDS")
103       {
104       propertyPairs.push_back("OBJECT_DEPENDS");
105       ++j;
106       if(j == propend)
107         {
108         errors = "called with incorrect number of arguments "
109           "OBJECT_DEPENDS with no dependencies";
110         return false;
111         }
112       propertyPairs.push_back(*j);
113       }
114     else if(*j == "PROPERTIES")
115       {
116       // now loop through the rest of the arguments, new style
117       ++j;
118       while (j != propend)
119         {
120         propertyPairs.push_back(*j);
121         if(*j == "GENERATED")
122           {
123           ++j;
124           if(j != propend && cmSystemTools::IsOn(j->c_str()))
125             {
126             generated = true;
127             }
128           }
129         else
130           {
131           ++j;
132           }
133         if(j == propend)
134           {
135           errors = "called with incorrect number of arguments.";
136           return false;
137           }
138         propertyPairs.push_back(*j);
139         ++j;
140         }
141       // break out of the loop because j is already == end
142       break;
143       }
144     else
145       {
146       errors = "called with illegal arguments, maybe missing a "
147         "PROPERTIES specifier?";
148       return false;
149       }
150     }
151
152   // now loop over all the files
153   for(j= filebeg; j != fileend;++j)
154     {
155     // get the source file
156     cmSourceFile* sf =
157       mf->GetOrCreateSource(j->c_str(), generated);
158     if(sf)
159       {
160       // now loop through all the props and set them
161       unsigned int k;
162       for (k = 0; k < propertyPairs.size(); k = k + 2)
163         {
164         sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
165         }
166       }
167     }
168   return true;
169 }
170