ENH: keep cleaning up Tcl/Tk modules
[cmake.git] / Source / cmSetSourceFilesPropertiesCommand.cxx
blobfa485aa54f85496a22ba49432a8563509fd21122
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSetSourceFilesPropertiesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.18 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 "cmSetSourceFilesPropertiesCommand.h"
19 #include "cmSourceFile.h"
21 // cmSetSourceFilesPropertiesCommand
22 bool cmSetSourceFilesPropertiesCommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() < 2 )
27 this->SetError("called with incorrect number of arguments");
28 return false;
31 // break the arguments into source file names and properties
32 int numFiles = 0;
33 std::vector<std::string>::const_iterator j;
34 j = args.begin();
35 // old style allows for specifier before PROPERTIES keyword
36 while (*j != "ABSTRACT" &&
37 *j != "WRAP_EXCLUDE" &&
38 *j != "GENERATED" &&
39 *j != "COMPILE_FLAGS" &&
40 *j != "OBJECT_DEPENDS" &&
41 *j != "PROPERTIES")
43 numFiles++;
44 ++j;
47 // now call the worker function
48 std::string errors;
49 bool ret =
50 cmSetSourceFilesPropertiesCommand
51 ::RunCommand(this->Makefile,
52 args.begin(),
53 args.begin() + numFiles,
54 args.begin() + numFiles,
55 args.end(), errors);
56 if (!ret)
58 this->SetError(errors.c_str());
60 return ret;
63 bool cmSetSourceFilesPropertiesCommand
64 ::RunCommand(cmMakefile *mf,
65 std::vector<std::string>::const_iterator filebeg,
66 std::vector<std::string>::const_iterator fileend,
67 std::vector<std::string>::const_iterator propbeg,
68 std::vector<std::string>::const_iterator propend,
69 std::string &errors)
71 std::vector<std::string> propertyPairs;
72 bool generated = false;
73 std::vector<std::string>::const_iterator j;
74 // build the property pairs
75 for(j= propbeg; j != propend;++j)
77 // old style allows for specifier before PROPERTIES keyword
78 if(*j == "ABSTRACT")
80 propertyPairs.push_back("ABSTRACT");
81 propertyPairs.push_back("1");
83 else if(*j == "WRAP_EXCLUDE")
85 propertyPairs.push_back("WRAP_EXCLUDE");
86 propertyPairs.push_back("1");
88 else if(*j == "GENERATED")
90 generated = true;
91 propertyPairs.push_back("GENERATED");
92 propertyPairs.push_back("1");
94 else if(*j == "COMPILE_FLAGS")
96 propertyPairs.push_back("COMPILE_FLAGS");
97 ++j;
98 if(j == propend)
100 errors = "called with incorrect number of arguments "
101 "COMPILE_FLAGS with no flags";
102 return false;
104 propertyPairs.push_back(*j);
106 else if(*j == "OBJECT_DEPENDS")
108 propertyPairs.push_back("OBJECT_DEPENDS");
109 ++j;
110 if(j == propend)
112 errors = "called with incorrect number of arguments "
113 "OBJECT_DEPENDS with no dependencies";
114 return false;
116 propertyPairs.push_back(*j);
118 else if(*j == "PROPERTIES")
120 // now loop through the rest of the arguments, new style
121 ++j;
122 bool dontPush = false;
123 while (j != propend)
125 propertyPairs.push_back(*j);
126 if(*j == "GENERATED")
128 ++j;
129 if(j != propend && cmSystemTools::IsOn(j->c_str()))
131 generated = true;
134 else if(*j == "MACOSX_PACKAGE_LOCATION")
136 ++j;
137 if(j == propend)
139 errors = "called with incorrect number of arguments "
140 "MACOSX_PACKAGE_LOCATION with no flags";
141 return false;
143 propertyPairs.push_back(*j);
144 propertyPairs.push_back("EXTRA_CONTENT");
145 propertyPairs.push_back("1");
146 propertyPairs.push_back("MACOSX_CONTENT");
147 propertyPairs.push_back("1");
148 propertyPairs.push_back("KEEP_EXTENSION");
149 propertyPairs.push_back("1");
150 propertyPairs.push_back("LANGUAGE");
151 propertyPairs.push_back("MacOSX_Content");
152 dontPush = true;
154 else
156 ++j;
158 if(j == propend)
160 errors = "called with incorrect number of arguments.";
161 return false;
163 if ( !dontPush )
165 propertyPairs.push_back(*j);
167 ++j;
168 dontPush = false;
170 // break out of the loop because j is already == end
171 break;
173 else
175 errors = "called with illegal arguments, maybe missing a "
176 "PROPERTIES specifier?";
177 return false;
181 // now loop over all the files
182 for(j= filebeg; j != fileend;++j)
184 // get the source file
185 cmSourceFile* sf =
186 mf->GetOrCreateSource(j->c_str(), generated);
187 if(sf)
189 // now loop through all the props and set them
190 unsigned int k;
191 for (k = 0; k < propertyPairs.size(); k = k + 2)
193 sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
197 return true;