Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmSetSourceFilesPropertiesCommand.cxx
blob536a800f7156f7444aad8c6ae590e1753705405e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSetSourceFilesPropertiesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-05-08 19:49:53 $
7 Version: $Revision: 1.20 $
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 != args.end() &&
37 *j != "ABSTRACT" &&
38 *j != "WRAP_EXCLUDE" &&
39 *j != "GENERATED" &&
40 *j != "COMPILE_FLAGS" &&
41 *j != "OBJECT_DEPENDS" &&
42 *j != "PROPERTIES")
44 numFiles++;
45 ++j;
48 // now call the worker function
49 std::string errors;
50 bool ret =
51 cmSetSourceFilesPropertiesCommand
52 ::RunCommand(this->Makefile,
53 args.begin(),
54 args.begin() + numFiles,
55 args.begin() + numFiles,
56 args.end(), errors);
57 if (!ret)
59 this->SetError(errors.c_str());
61 return ret;
64 bool cmSetSourceFilesPropertiesCommand
65 ::RunCommand(cmMakefile *mf,
66 std::vector<std::string>::const_iterator filebeg,
67 std::vector<std::string>::const_iterator fileend,
68 std::vector<std::string>::const_iterator propbeg,
69 std::vector<std::string>::const_iterator propend,
70 std::string &errors)
72 std::vector<std::string> propertyPairs;
73 bool generated = false;
74 std::vector<std::string>::const_iterator j;
75 // build the property pairs
76 for(j= propbeg; j != propend;++j)
78 // old style allows for specifier before PROPERTIES keyword
79 if(*j == "ABSTRACT")
81 propertyPairs.push_back("ABSTRACT");
82 propertyPairs.push_back("1");
84 else if(*j == "WRAP_EXCLUDE")
86 propertyPairs.push_back("WRAP_EXCLUDE");
87 propertyPairs.push_back("1");
89 else if(*j == "GENERATED")
91 generated = true;
92 propertyPairs.push_back("GENERATED");
93 propertyPairs.push_back("1");
95 else if(*j == "COMPILE_FLAGS")
97 propertyPairs.push_back("COMPILE_FLAGS");
98 ++j;
99 if(j == propend)
101 errors = "called with incorrect number of arguments "
102 "COMPILE_FLAGS with no flags";
103 return false;
105 propertyPairs.push_back(*j);
107 else if(*j == "OBJECT_DEPENDS")
109 propertyPairs.push_back("OBJECT_DEPENDS");
110 ++j;
111 if(j == propend)
113 errors = "called with incorrect number of arguments "
114 "OBJECT_DEPENDS with no dependencies";
115 return false;
117 propertyPairs.push_back(*j);
119 else if(*j == "PROPERTIES")
121 // now loop through the rest of the arguments, new style
122 ++j;
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
136 ++j;
138 if(j == propend)
140 errors = "called with incorrect number of arguments.";
141 return false;
143 propertyPairs.push_back(*j);
144 ++j;
146 // break out of the loop because j is already == end
147 break;
149 else
151 errors = "called with illegal arguments, maybe missing a "
152 "PROPERTIES specifier?";
153 return false;
157 // now loop over all the files
158 for(j= filebeg; j != fileend;++j)
160 // get the source file
161 cmSourceFile* sf =
162 mf->GetOrCreateSource(j->c_str(), generated);
163 if(sf)
165 // now loop through all the props and set them
166 unsigned int k;
167 for (k = 0; k < propertyPairs.size(); k = k + 2)
169 sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
173 return true;