35 for (BuildConfig cfg : allConfigs) { |
39 for (BuildConfig cfg : allConfigs) { |
36 startTag("ProjectConfiguration", |
40 startTag("ProjectConfiguration", |
37 "Include", cfg.get("Name")); |
41 "Include", cfg.get("Name")); |
38 tagData("Configuration", cfg.get("Id")); |
42 tagData("Configuration", cfg.get("Id")); |
39 tagData("Platform", cfg.get("PlatformName")); |
43 tagData("Platform", cfg.get("PlatformName")); |
40 endTag("ProjectConfiguration"); |
44 endTag(); |
41 } |
45 } |
42 endTag("ItemGroup"); |
46 endTag(); |
43 |
47 |
44 startTag("PropertyGroup", "Label", "Globals"); |
48 startTag("PropertyGroup", "Label", "Globals"); |
45 tagData("ProjectGuid", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}"); |
49 tagData("ProjectGuid", "{8822CB5C-1C41-41C2-8493-9F6E1994338B}"); |
46 tag("SccProjectName"); |
50 tag("SccProjectName"); |
47 tag("SccLocalPath"); |
51 tag("SccLocalPath"); |
48 endTag("PropertyGroup"); |
52 endTag(); |
49 |
53 |
50 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"); |
54 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"); |
51 |
55 |
52 for (BuildConfig cfg : allConfigs) { |
56 for (BuildConfig cfg : allConfigs) { |
53 startTag(cfg, "PropertyGroup", "Label", "Configuration"); |
57 startTag(cfg, "PropertyGroup", "Label", "Configuration"); |
54 tagData("ConfigurationType", "DynamicLibrary"); |
58 tagData("ConfigurationType", "DynamicLibrary"); |
55 tagData("UseOfMfc", "false"); |
59 tagData("UseOfMfc", "false"); |
56 endTag("PropertyGroup"); |
60 endTag(); |
57 } |
61 } |
58 |
62 |
59 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.props"); |
63 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.props"); |
60 startTag("ImportGroup", "Label", "ExtensionSettings"); |
64 startTag("ImportGroup", "Label", "ExtensionSettings"); |
61 endTag("ImportGroup"); |
65 endTag(); |
62 for (BuildConfig cfg : allConfigs) { |
66 for (BuildConfig cfg : allConfigs) { |
63 startTag(cfg, "ImportGroup", "Label", "PropertySheets"); |
67 startTag(cfg, "ImportGroup", "Label", "PropertySheets"); |
64 tag("Import", |
68 tag("Import", |
65 "Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props", |
69 "Project", "$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props", |
66 "Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')", |
70 "Condition", "exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')", |
67 "Label", "LocalAppDataPlatform"); |
71 "Label", "LocalAppDataPlatform"); |
68 endTag("ImportGroup"); |
72 endTag(); |
69 } |
73 } |
70 |
74 |
71 tag("PropertyGroup", "Label", "UserMacros"); |
75 tag("PropertyGroup", "Label", "UserMacros"); |
72 |
76 |
73 startTag("PropertyGroup"); |
77 startTag("PropertyGroup"); |
80 for (BuildConfig cfg : allConfigs) { |
84 for (BuildConfig cfg : allConfigs) { |
81 tagData(cfg, "CodeAnalysisRuleSet", "AllRules.ruleset"); |
85 tagData(cfg, "CodeAnalysisRuleSet", "AllRules.ruleset"); |
82 tag(cfg, "CodeAnalysisRules"); |
86 tag(cfg, "CodeAnalysisRules"); |
83 tag(cfg, "CodeAnalysisRuleAssemblies"); |
87 tag(cfg, "CodeAnalysisRuleAssemblies"); |
84 } |
88 } |
85 endTag("PropertyGroup"); |
89 endTag(); |
86 |
90 |
87 for (BuildConfig cfg : allConfigs) { |
91 for (BuildConfig cfg : allConfigs) { |
88 startTag(cfg, "ItemDefinitionGroup"); |
92 startTag(cfg, "ItemDefinitionGroup"); |
89 startTag("ClCompile"); |
93 startTag("ClCompile"); |
90 tagV(cfg.getV("CompilerFlags")); |
94 tagV(cfg.getV("CompilerFlags")); |
91 endTag("ClCompile"); |
95 endTag(); |
92 |
96 |
93 startTag("Link"); |
97 startTag("Link"); |
94 tagV(cfg.getV("LinkerFlags")); |
98 tagV(cfg.getV("LinkerFlags")); |
95 endTag("Link"); |
99 endTag(); |
96 |
100 |
97 startTag("PostBuildEvent"); |
101 startTag("PostBuildEvent"); |
98 tagData("Message", BuildConfig.getFieldString(null, "PostbuildDescription")); |
102 tagData("Message", BuildConfig.getFieldString(null, "PostbuildDescription")); |
99 tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PostbuildCommand").replace("\t", "\r\n"))); |
103 tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PostbuildCommand").replace("\t", "\r\n"))); |
100 endTag("PostBuildEvent"); |
104 endTag(); |
101 |
105 |
102 startTag("PreLinkEvent"); |
106 startTag("PreLinkEvent"); |
103 tagData("Message", BuildConfig.getFieldString(null, "PrelinkDescription")); |
107 tagData("Message", BuildConfig.getFieldString(null, "PrelinkDescription")); |
104 tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace("\t", "\r\n"))); |
108 tagData("Command", cfg.expandFormat(BuildConfig.getFieldString(null, "PrelinkCommand").replace("\t", "\r\n"))); |
105 endTag("PreLinkEvent"); |
109 endTag(); |
106 |
110 |
107 endTag("ItemDefinitionGroup"); |
111 endTag(); |
108 } |
112 } |
109 |
113 |
110 writeFiles(allConfigs, projDir); |
114 writeFiles(allConfigs, projDir); |
111 |
115 |
112 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets"); |
116 tag("Import", "Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets"); |
113 startTag("ImportGroup", "Label", "ExtensionTargets"); |
117 startTag("ImportGroup", "Label", "ExtensionTargets"); |
114 endTag("ImportGroup"); |
118 endTag(); |
115 |
119 |
116 endTag("Project"); |
120 endTag(); |
117 printWriter.close(); |
121 printWriter.close(); |
118 System.out.println(" Done."); |
122 System.out.println(" Done."); |
119 |
123 |
120 writeFilterFile(projectFileName, projectName, allConfigs, projDir); |
124 writeFilterFile(projectFileName, projectName, allConfigs, projDir); |
121 writeUserFile(projectFileName, allConfigs); |
125 writeUserFile(projectFileName, allConfigs); |
155 printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
167 printWriter.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
156 startTag("Project", |
168 startTag("Project", |
157 "ToolsVersion", "4.0", |
169 "ToolsVersion", "4.0", |
158 "xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); |
170 "xmlns", "http://schemas.microsoft.com/developer/msbuild/2003"); |
159 |
171 |
160 Hashtable<String, FileAttribute> allFiles = computeAttributedFiles(allConfigs); |
|
161 TreeSet<FileInfo> sortedFiles = sortFiles(allFiles); |
|
162 Vector<NameFilter> filters = makeFilters(sortedFiles); |
|
163 |
|
164 // first all filters |
|
165 startTag("ItemGroup"); |
172 startTag("ItemGroup"); |
166 for (NameFilter filter : filters) { |
173 for (String filter : filters) { |
167 doWriteFilter(filter, ""); |
174 startTag("Filter", "Include",filter); |
|
175 UUID uuid = UUID.randomUUID(); |
|
176 tagData("UniqueIdentifier", "{" + uuid.toString() + "}"); |
|
177 endTag(); |
168 } |
178 } |
169 startTag("Filter", "Include", "Resource Files"); |
179 startTag("Filter", "Include", "Resource Files"); |
170 UUID uuid = UUID.randomUUID(); |
180 UUID uuid = UUID.randomUUID(); |
171 tagData("UniqueIdentifier", "{" + uuid.toString() + "}"); |
181 tagData("UniqueIdentifier", "{" + uuid.toString() + "}"); |
172 tagData("Extensions", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"); |
182 tagData("Extensions", "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"); |
173 endTag("Filter"); |
183 endTag(); |
174 endTag("ItemGroup"); |
184 endTag(); |
175 |
185 |
176 // then all cpp files |
186 //TODO - do I need to split cpp and hpp files? |
|
187 |
|
188 // then all files |
177 startTag("ItemGroup"); |
189 startTag("ItemGroup"); |
178 for (NameFilter filter : filters) { |
190 for (String[] dep : filterDeps) { |
179 doWriteFiles(sortedFiles, filter, "", "ClCompile", new Evaluator() { |
191 String tagName = getFileTagFromSuffix(dep[0]); |
180 public boolean pick(FileInfo fi) { |
192 |
181 return fi.isCpp(); |
193 startTag(tagName, "Include", dep[0]); |
182 } |
194 tagData("Filter", dep[1]); |
183 }, base); |
195 endTag(); |
184 } |
196 } |
185 endTag("ItemGroup"); |
197 endTag(); |
186 |
198 |
187 // then all header files |
199 endTag(); |
188 startTag("ItemGroup"); |
|
189 for (NameFilter filter : filters) { |
|
190 doWriteFiles(sortedFiles, filter, "", "ClInclude", new Evaluator() { |
|
191 public boolean pick(FileInfo fi) { |
|
192 return fi.isHeader(); |
|
193 } |
|
194 }, base); |
|
195 } |
|
196 endTag("ItemGroup"); |
|
197 |
|
198 // then all other files |
|
199 startTag("ItemGroup"); |
|
200 for (NameFilter filter : filters) { |
|
201 doWriteFiles(sortedFiles, filter, "", "None", new Evaluator() { |
|
202 public boolean pick(FileInfo fi) { |
|
203 return true; |
|
204 } |
|
205 }, base); |
|
206 } |
|
207 endTag("ItemGroup"); |
|
208 |
|
209 endTag("Project"); |
|
210 printWriter.close(); |
200 printWriter.close(); |
211 System.out.println(" Done."); |
201 System.out.println(" Done."); |
212 } |
202 } |
213 |
203 |
214 |
204 public String getFileTagFromSuffix(String fileName) { |
215 private void doWriteFilter(NameFilter filter, String start) { |
205 if (fileName.endsWith(".cpp")) { |
216 startTag("Filter", "Include", start + filter.fname); |
206 return"ClCompile"; |
217 UUID uuid = UUID.randomUUID(); |
207 } else if (fileName.endsWith(".c")) { |
218 tagData("UniqueIdentifier", "{" + uuid.toString() + "}"); |
208 return "ClCompile"; |
219 endTag("Filter"); |
209 } else if (fileName.endsWith(".hpp")) { |
220 if (filter instanceof ContainerFilter) { |
210 return"ClInclude"; |
221 Iterator i = ((ContainerFilter)filter).babies(); |
211 } else if (fileName.endsWith(".h")) { |
222 while (i.hasNext()) { |
212 return "ClInclude"; |
223 doWriteFilter((NameFilter)i.next(), start + filter.fname + "\\"); |
213 } else { |
224 } |
214 return"None"; |
225 } |
215 } |
226 } |
216 } |
227 |
|
228 interface Evaluator { |
|
229 boolean pick(FileInfo fi); |
|
230 } |
|
231 |
|
232 private void doWriteFiles(TreeSet<FileInfo> allFiles, NameFilter filter, String start, String tool, Evaluator eval, String base) { |
|
233 if (filter instanceof ContainerFilter) { |
|
234 Iterator i = ((ContainerFilter)filter).babies(); |
|
235 while (i.hasNext()) { |
|
236 doWriteFiles(allFiles, (NameFilter)i.next(), start + filter.fname + "\\", tool, eval, base); |
|
237 } |
|
238 } |
|
239 else { |
|
240 Iterator i = allFiles.iterator(); |
|
241 while (i.hasNext()) { |
|
242 FileInfo fi = (FileInfo)i.next(); |
|
243 |
|
244 if (!filter.match(fi)) { |
|
245 continue; |
|
246 } |
|
247 if (eval.pick(fi)) { |
|
248 startTag(tool, "Include", rel(fi.full, base)); |
|
249 tagData("Filter", start + filter.fname); |
|
250 endTag(tool); |
|
251 |
|
252 // we not gonna look at this file anymore (sic!) |
|
253 i.remove(); |
|
254 } |
|
255 } |
|
256 } |
|
257 } |
|
258 |
|
259 |
217 |
260 void writeFiles(Vector<BuildConfig> allConfigs, String projDir) { |
218 void writeFiles(Vector<BuildConfig> allConfigs, String projDir) { |
261 Hashtable<String, FileAttribute> allFiles = computeAttributedFiles(allConfigs); |
219 // This code assummes there are no config specific includes. |
262 TreeSet<FileInfo> sortedFiles = sortFiles(allFiles); |
220 startTag("ItemGroup"); |
263 |
221 |
264 // first cpp-files |
222 String sourceBase = BuildConfig.getFieldString(null, "SourceBase"); |
265 startTag("ItemGroup"); |
223 |
266 for (FileInfo fi : sortedFiles) { |
224 // Use first config for all global absolute includes. |
267 if (!fi.isCpp()) { |
225 BuildConfig baseConfig = allConfigs.firstElement(); |
268 continue; |
226 Vector<String> rv = new Vector<String>(); |
269 } |
227 |
270 writeFile("ClCompile", allConfigs, fi, projDir); |
228 // Then use first config for all relative includes |
271 } |
229 Vector<String> ri = new Vector<String>(); |
272 endTag("ItemGroup"); |
230 baseConfig.collectRelevantVectors(ri, "RelativeSrcInclude"); |
273 |
231 for (String f : ri) { |
274 // then header-files |
232 rv.add(sourceBase + Util.sep + f); |
275 startTag("ItemGroup"); |
233 } |
276 for (FileInfo fi : sortedFiles) { |
234 |
277 if (!fi.isHeader()) { |
235 baseConfig.collectRelevantVectors(rv, "AbsoluteSrcInclude"); |
278 continue; |
236 |
279 } |
237 handleIncludes(rv, allConfigs); |
280 writeFile("ClInclude", allConfigs, fi, projDir); |
238 |
281 } |
239 endTag(); |
282 endTag("ItemGroup"); |
240 } |
283 |
241 |
284 // then others |
242 // Will visit file tree for each include |
285 startTag("ItemGroup"); |
243 private void handleIncludes(Vector<String> includes, Vector<BuildConfig> allConfigs) { |
286 for (FileInfo fi : sortedFiles) { |
244 for (String path : includes) { |
287 if (fi.isHeader() || fi.isCpp()) { |
245 FileTreeCreatorVC10 ftc = new FileTreeCreatorVC10(FileSystems.getDefault().getPath(path) , allConfigs, this); |
288 continue; |
246 try { |
289 } |
247 ftc.writeFileTree(); |
290 writeFile("None", allConfigs, fi, projDir); |
248 } catch (IOException e) { |
291 } |
249 e.printStackTrace(); |
292 endTag("ItemGroup"); |
250 } |
293 } |
251 } |
294 |
|
295 /** |
|
296 * Make "path" into a relative path using "base" as the base. |
|
297 * |
|
298 * path and base are assumed to be normalized with / as the file separator. |
|
299 * returned path uses "\\" as file separator |
|
300 */ |
|
301 private String rel(String path, String base) |
|
302 { |
|
303 if(!base.endsWith("/")) { |
|
304 base += "/"; |
|
305 } |
|
306 String[] pathTok = path.split("/"); |
|
307 String[] baseTok = base.split("/"); |
|
308 int pi = 0; |
|
309 int bi = 0; |
|
310 StringBuilder newPath = new StringBuilder(); |
|
311 |
|
312 // first step past all path components that are the same |
|
313 while (pi < pathTok.length && |
|
314 bi < baseTok.length && |
|
315 pathTok[pi].equals(baseTok[bi])) { |
|
316 pi++; |
|
317 bi++; |
|
318 } |
|
319 |
|
320 // for each path component left in base, add "../" |
|
321 while (bi < baseTok.length) { |
|
322 bi++; |
|
323 newPath.append("..\\"); |
|
324 } |
|
325 |
|
326 // now add everything left in path |
|
327 while (pi < pathTok.length) { |
|
328 newPath.append(pathTok[pi]); |
|
329 pi++; |
|
330 if (pi != pathTok.length) { |
|
331 newPath.append("\\"); |
|
332 } |
|
333 } |
|
334 return newPath.toString(); |
|
335 } |
|
336 |
|
337 private void writeFile(String tool, Vector<BuildConfig> allConfigs, FileInfo fi, String base) { |
|
338 if (fi.attr.configs == null && fi.attr.pchRoot == false && fi.attr.noPch == false) { |
|
339 tag(tool, "Include", rel(fi.full, base)); |
|
340 } |
|
341 else { |
|
342 startTag(tool, "Include", rel(fi.full, base)); |
|
343 for (BuildConfig cfg : allConfigs) { |
|
344 if (fi.attr.configs != null && !fi.attr.configs.contains(cfg.get("Name"))) { |
|
345 tagData(cfg, "ExcludedFromBuild", "true"); |
|
346 } |
|
347 if (fi.attr.pchRoot) { |
|
348 tagData(cfg, "PrecompiledHeader", "Create"); |
|
349 } |
|
350 if (fi.attr.noPch) { |
|
351 startTag(cfg, "PrecompiledHeader"); |
|
352 endTag("PrecompiledHeader"); |
|
353 } |
|
354 } |
|
355 endTag(tool); |
|
356 } |
|
357 } |
252 } |
358 |
253 |
359 String buildCond(BuildConfig cfg) { |
254 String buildCond(BuildConfig cfg) { |
360 return "'$(Configuration)|$(Platform)'=='"+cfg.get("Name")+"'"; |
255 return "'$(Configuration)|$(Platform)'=='"+cfg.get("Name")+"'"; |
361 } |
256 } |
362 |
|
363 |
257 |
364 void tagV(Vector<String> v) { |
258 void tagV(Vector<String> v) { |
365 Iterator<String> i = v.iterator(); |
259 Iterator<String> i = v.iterator(); |
366 while(i.hasNext()) { |
260 while(i.hasNext()) { |
367 String name = i.next(); |
261 String name = i.next(); |