Debian Codegraph @

dist/win_projects/vs2010.template

raw
1 declare variable $xmlversion := "1.0";
2 declare variable $xmlencoding := "utf-8";
3 declare variable $msbversion := "4.0";
4 declare variable $msbdefprops := '$(VCTargetsPath)\Microsoft.Cpp.Default.props';
5 declare variable $msbprops := '$(VCTargetsPath)\Microsoft.Cpp.props';
6 declare variable $msbtargets := "$(VCTargetsPath)\Microsoft.Cpp.targets";
7 declare variable $projectList := "@PROJECT_INPUT@";
8 declare variable $mobile := xs:boolean(doc($projectList)/projects/variable[@name="mobile"]);
9 declare variable $debugOptLevel := "Disabled";
10 declare variable $releaseOptLevel := "MaxSpeed";
11 declare variable $warnLevel := "Level3";
12 declare variable $debugInfo := "ProgramDatabase";
13 declare variable $sourcePath := doc($projectList)/projects/variable[@name="sourcePath"];
14 declare variable $vsversion := "@VISUAL_STUDIO_VERSION@";
15 declare variable $dllType := "dll";
16 declare variable $appType := "Application";
17 declare variable $special_file := "src/crypto/crypto.c;src/crypto/aes_method.c";
18
19 declare function local:genImportProperty($project)
20 {
21 let $libprop := if ($project/type/text() eq "library") then "library.props"
22 else "application.props"
23 return
24 (local:indent(2),<ImportGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
25 {local:indent(4)}<Import Project="{$libprop}"/>
26 {local:indent(2)}</ImportGroup>)
27 };
28
29 declare function local:indent($n)
30 {
31 concat("&#xa;",string-join(for $i in (1 to $n) return " ", ""))
32 };
33
34 declare function local:getPlatforms($version)
35 {
36 if ($version eq "7.10") then ("Win32")
37 else ("Win32", "x64")
38 };
39
40 declare function local:getGuid($project)
41 {
42 concat("{",$project/@guid,"}")
43 };
44
45 declare function local:generateProjectConfigurations($project)
46 {
47 local:indent(2),<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Label="ProjectConfigurations">
48 {for $config in local:getConfiguration($project) return
49 for $platform in local:getPlatforms($vsversion) return
50 (local:indent(4),<ProjectConfiguration Include="{concat($config, "|",$platform)}">
51 {local:indent(6)}<Configuration>{$config}</Configuration>
52 {local:indent(6)}<Platform>{$platform}</Platform>
53 {local:indent(4)}</ProjectConfiguration>)
54 }
55 {local:indent(2)}</ItemGroup>
56 };
57
58 declare function local:generateGlobalProperty($project)
59 {
60 local:indent(2),<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Label="Globals">
61 {local:indent(2)}<ProjectGuid>{local:getGuid($project)}</ProjectGuid>
62 {local:indent(2)}</PropertyGroup>
63 };
64
65 declare function local:getProjects()
66 {
67 doc($projectList)/projects/project[@name="@PROJECT_NAME@"]
68 };
69
70 declare function local:configurationType($project, $config)
71 {
72 if ($project/type eq "library") then if (contains($config,"Static")) then
73 "StaticLibrary" else "DynamicLibrary"
74 else if ($project/type eq "app") then "Application"
75 else error(QName("","xqilla"),"configurationType:unkown project type")
76 };
77
78 declare function local:generateConfigurations($project)
79 {
80 for $platform in local:getPlatforms($vsversion) return
81 for $config in local:getConfiguration($project)
82 let $configType := local:configurationType($project,$config)
83 return
84 (local:indent(2),<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
85 Condition="'$(Configuration)|$(Platform)'=={concat("'",$config,"|",$platform,"'")}"
86 Label="Configuration">
87 {local:indent(4)}<ConfigurationType>{$configType}</ConfigurationType>
88 {local:indent(4)}<UseOfMfc>false</UseOfMfc>
89 {local:indent(4)}<CharacterSet>MultiByte</CharacterSet>
90 {local:indent(2)}</PropertyGroup>
91 )
92 };
93
94 declare function local:genExtensionSettings()
95 {
96 local:indent(2),<ImportGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Label="ExtensionSettings">
97 {local:indent(2)}</ImportGroup>
98 };
99
100 declare function local:genExtensionTargets()
101 {
102 local:indent(2),<ImportGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Label="ExtensionTargets">
103 {local:indent(2)}</ImportGroup>
104 };
105
106 declare variable $msbuserprops := "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props";
107 declare variable $msbuserpropsexit := "exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')";
108
109
110 declare function local:genPropertySheets($project)
111 {
112 local:indent(2),<ImportGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
113 {local:indent(4)}<Import xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
114 Project="{$msbuserprops}" Condition="{$msbuserpropsexit}" Label="LocalAppDataPlatform" />
115 {local:indent(4)}</ImportGroup>
116 };
117
118 declare function local:windowsPath($path) as xs:string
119 {
120 translate($path,"/","\\")
121 };
122
123
124 declare function local:getLibName($name, $config)
125 {
126 doc($projectList)/projects/library[@name=$name]/libname[@config=$config]/text()
127 };
128
129 declare function local:genMacros($project)
130 {
131 local:genDynamicMacros($project)
132 };
133
134 declare function local:genTargetName($project,$config)
135 {
136 if ($project/type eq "library") then
137 local:getLibName($project/@name, $config)
138 else
139 if (not(empty($project/@output))) then data($project/@output) else data($project/@name)
140 };
141
142 declare function local:genTargetExt($project, $config)
143 {
144 if ($project/type eq "library") then
145 if (contains($config, "Static")) then ".lib"
146 else ".dll"
147 else ".exe"
148 };
149
150 (: no static variable usage now :)
151
152 declare function local:genDynamicMacros($project)
153 {
154 let $projType := $project/type return(
155 local:indent(2),<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
156 {local:indent(4)}<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
157 {if ( not(empty($project/@output))) then
158 if ( $projType eq "library") then
159 for $platform in local:getPlatforms($vsversion) return
160 for $config in local:getConfiguration($project) return
161 (local:indent(4),<TargetName xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
162 Condition="'$(Configuration)|$(Platform)'=={concat("'",$config,"|",$platform,"'")}">{local:genTargetName($project,$config)}</TargetName>)
163 else (local:indent(4),<TargetName xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{local:genTargetName($project,"null")}</TargetName>)
164 else ()
165 }
166 {local:indent(2)}</PropertyGroup>
167 )
168 };
169
170
171 declare function local:isDebug($config) as xs:boolean
172 {
173 contains($config,"Debug")
174 };
175
176 declare function local:isRelease($config) as xs:boolean
177 {
178 contains($config,"Release")
179 };
180
181 declare function local:optLevel($config)
182 {
183 if (local:isDebug($config)) then $debugOptLevel
184 else $releaseOptLevel
185 };
186
187 declare function local:addIncludeDirectories($project,$config)
188 {
189 let $incref := for $inc in $project/include[@type="ref"] return
190 if ($inc/text() eq "all") then ()
191 else doc($projectList)/projects/include[@name=$inc]
192 let $increl := $project/include[@type="rel"]
193 return
194 if ($incref or $increl) then (
195 local:indent(6), <AdditionalIncludeDirectories xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
196 {translate(concat(string-join($incref,";"),
197 if (not(empty($increl)) and not(empty($incref))) then ";" else "",
198 string-join($increl,";"),";","%(AdditionalIncludeDirectories)"),",",";")}</AdditionalIncludeDirectories>)
199 else ()
200 };
201
202 declare function local:getProjectType($project, $config)
203 {
204 if ($project/type eq "library") then if (contains($config,"Static")) then "static_lib"
205 else "dll"
206 else if ($project/type eq "app") then if (contains($config,"Static")) then "static_app"
207 else "app"
208 else error(QName("","dbxml"),"getProjectType:unkown project type")
209 };
210
211 declare function local:generateCompilerPreprocessorDefs($project,$config)
212 {
213 let $ptype := local:getProjectType($project, $config)
214 let $proj := $project/preprocessor[@config="all" or @config=$config]
215 let $projType := $project/preprocessor[@config=$ptype]
216 return
217 if ($proj or $projType) then
218 (local:indent(6),<PreprocessorDefinitions xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
219 {concat(string-join(($proj,$projType),";"),";","%(PreprocessorDefinitions)")}</PreprocessorDefinitions>
220 )
221 else ()
222 };
223
224 declare function local:runtimeLibrary($config)
225 {
226 if (local:isDebug($config)) then
227 if (contains($config,"Static")) then "MultiThreadedDebug" else "MultiThreadedDebugDLL"
228 else
229 if (contains($config,"Static")) then "MultiThreaded" else "MultiThreadedDLL"
230 };
231
232 declare function local:makeObjectFile($project,$config)
233 {
234 concat("$(OutDir)", if (not(empty($project/@output))) then $project/@output else $project/@name,"/")
235 };
236
237 declare function local:addDebugInformation($config)
238 {
239 local:indent(6),<DebugInformationFormat xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{$debugInfo}</DebugInformationFormat>,
240 if (local:isDebug($config)) then (local:indent(6),<BasicRuntimeChecks xmlns="http://schemas.microsoft.com/developer/msbuild/2003">EnableFastChecks</BasicRuntimeChecks>) else ()
241 };
242
243 declare function local:addCompileOptions($project, $platform, $config)
244 {
245 if ($project/options/compile[contains(@platform,$platform)]) then
246 let $opt := string-join(($project/options/compile[contains(@platform, $platform)]), " ")
247 return (
248 if ($opt) then (local:indent(6),<AdditionalOptions xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{string-join(($opt,"%(AdditionalOptions)")," ")}</AdditionalOptions> )
249 else ())
250 else ()
251 };
252
253 declare function local:addLinkOptions($project, $platform, $config)
254 {
255 if ($project/options/link[contains(@config,$config)]) then
256 let $opt := string-join(($project/options/link[contains(@config,$config)])," ")
257 return (
258 if ($opt) then (local:indent(6),<AdditionalOptions xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{string-join(($opt,"%(AdditionalOptions)")," ")}</AdditionalOptions> )
259 else ())
260 else ()
261 };
262
263 declare function local:addLibraryDependencies($project,$config)
264 {
265
266 let $libdep := (
267 if (contains($project/type, "lib")) then
268 string-join(for $dep in $project/depends return concat(local:getLibName($dep,$config),".lib"), ";")
269 else (
270 string-join(for $dep in $project/depends return (
271 if (not($dep/text() eq "db")) then
272 concat(local:getLibName($dep,$config),".lib")
273 else ()
274 ), ";")
275 )) return
276 if ($libdep and not($libdep eq ";")) then (
277 local:indent(6),<AdditionalDependencies xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
278 {$libdep};%(AdditionalDependencies)</AdditionalDependencies>
279 )
280 else ()
281 };
282
283
284 declare function local:addProjectDependencies($project)
285 {
286 for $mydep in $project/references
287 let $mytemp := lower-case(concat("{",doc($projectList)/projects/project[@name=$mydep]/@guid,"}"))
288 return
289 (local:indent(4), <ProjectReference Condition="exists('{concat($mydep,".vcxproj")}')" Include="{concat($mydep,".vcxproj")}" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
290 {local:indent(6)}<Project>{$mytemp}</Project>
291 {local:indent(6)}<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
292 {local:indent(4)}</ProjectReference>)
293 };
294
295 declare function local:makeLibraryDirectory($lib,$platform,$config)
296 {
297 for $dir in $lib/platform[contains(@name,$platform)]/config[$config=./@type]/libdir
298 return
299 if (not(empty($lib/libbase[@vsver=$vsversion]))) then
300 concat($lib/libbase[@vsver=$vsversion],"/",$dir)
301 else $dir
302 };
303
304 declare function local:addLibraryDirectories($project, $platform, $config)
305 {
306 string-join((for $dep in $project/depends return local:makeLibraryDirectory(doc($projectList)/projects/library[@name=$dep],$platform,$config),"../../lib"),";")
307 };
308
309 declare function local:makeOutputPDBFile($project,$config)
310 {
311 if ($project/type eq "library") then
312 concat("$(OutDir)",local:getLibName($project/@name,$config),".pdb")
313 else
314 concat("$(OutDir)",if (not(empty($project/@output))) then $project/@output else $project/@name,".pdb")
315 };
316
317 declare function local:makeImportLibrary($project,$config)
318 {
319 if ($project/type eq "library" and not(contains($config,"Static"))) then
320 (local:indent(6),<ImportLibrary xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{concat("$(OutDir)",local:getLibName($project/@name,$config),".lib")}</ImportLibrary>)
321 else ()
322 };
323
324 declare function local:makeModuleDefinition($project,$config)
325 {
326 if (not(empty($project/moddef))) then
327 let $temp := concat($sourcePath,$project/moddef/@file)
328 return
329 (local:indent(6),<ModuleDefinitionFile xmlns="http://schemas.microsoft.com/developer/msbuild/2003">{local:windowsPath($temp)}</ModuleDefinitionFile>)
330 else ()
331 };
332
333 declare function local:generateCustomBuildTool($project,$config)
334 {
335 if (not(empty($project/event[@name="custom"]))) then
336 let $commandtext := $project/event[@name="custom"]/command[contains(@config,$config)]/text()
337 let $outputs := concat($project/event[@name="custom"]/output,";%(Outputs)")
338 return (
339 local:indent(4),<CustomBuildStep xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
340 {local:indent(6)}<Command>{$commandtext}</Command>
341 {local:indent(6)}<Outputs>{$outputs}</Outputs>
342 {local:indent(4)}</CustomBuildStep>)
343 else if (not(empty($project/event[@name="postbuild"]))) then
344 let $commandtext := $project/event[@name="postbuild"]/command[contains(@config,$config)]/text()
345 let $message := $project/event[@name="postbuild"]/description
346 return (
347 local:indent(4),<PostBuildEvent xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
348 {local:indent(6)}<Command>{$commandtext}</Command>
349 {local:indent(6)}<Message>{$message}</Message>
350 {local:indent(4)}</PostBuildEvent>)
351 else if (not(empty($project/event[@name="prebuild"]))) then
352 let $commandtext := $project/event[@name="prebuild"]/command[contains(@config,$config)]/text()
353 let $message := $project/event[@name="prebuild"]/description
354 return (
355 local:indent(4),<PreBuildEvent xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
356 {local:indent(6)}<Command>{$commandtext}</Command>
357 {local:indent(6)}<Message>{$message}</Message>
358 {local:indent(4)}</PreBuildEvent>)
359 else ()
360 };
361
362
363 declare function local:genDefinition($project)
364 {
365 local:genDynamicDefinition($project)
366 };
367
368
369 declare function local:generateConfigCompiler($project,$platform,$config)
370 {
371 let $clcompile := <ClCompile xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
372 {local:addCompileOptions($project,$platform,$config)}
373 {local:addIncludeDirectories($project,$config)}
374 {local:generateCompilerPreprocessorDefs($project,$config)}
375 {local:indent(4)}</ClCompile>
376 return
377 if ($clcompile//*) then (local:indent(4),$clcompile)
378 else ()
379 };
380 declare function local:generateDynamicLink($project, $platform, $config)
381 {
382 let $dynlink := <Link xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
383 {local:addLinkOptions($project,$platform,$config)}
384 {local:addLibraryDependencies($project,$config)}
385 {local:makeModuleDefinition($project,$config)}
386 {local:indent(4)}</Link>
387 return
388 if ($dynlink//*) then (local:indent(4),$dynlink)
389 else ()
390 };
391 declare function local:generateConfigLibrarian($project,$platform,$config)
392 { let $linkoptions := local:addLinkOptions($project,$platform,$config) return
393 if ($linkoptions) then
394 (local:indent(4),<Lib xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
395 {$linkoptions}
396 {local:indent(4)}</Lib>)
397 else ()
398 };
399
400
401 declare function local:generateStaticLink($project,$platform,$config)
402 {
403 if (contains($project/type,"lib")) then
404 local:generateConfigLibrarian($project,$platform,$config)
405 else
406 local:generateDynamicLink($project,$platform,$config)
407 };
408
409 declare function local:genDynamicDefinition($project)
410 {
411 for $platform in local:getPlatforms($vsversion) return
412 for $config in local:getConfiguration($project)
413 let $static := contains($config, "Static")
414 return
415 (
416 let $mynode := <ItemDefinitionGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
417 Condition="'$(Configuration)|$(Platform)'=={concat("'",$config,"|",$platform,"'")}">
418 {local:generateConfigCompiler($project,$platform,$config)}
419 {if ($static) then local:generateStaticLink($project,$platform,$config)
420 else local:generateDynamicLink($project,$platform,$config)}
421 {local:generateCustomBuildTool($project,$config)}
422 {local:indent(2)}</ItemDefinitionGroup>
423 return
424 if ($mynode//*) then (local:indent(2),$mynode)
425 else ()
426 )
427 };
428
429 declare function local:genStaticDefinition($project)
430 {
431 for $platform in local:getPlatforms($vsversion) return
432 for $config in local:getConfiguration($project) return
433 (
434 local:indent(2),<ItemDefinitionGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
435 Condition="'$(Configuration)|$(Platform)'=={concat("'",$config,"|",$platform,"'")}">
436 {local:generateConfigCompiler($project,$platform,$config)}
437 {local:generateStaticLink($project,$platform,$config)}
438 {local:generateCustomBuildTool($project,$config)}
439 {local:indent(2)}</ItemDefinitionGroup>
440 )
441 };
442
443 declare function local:generateIncFilesNoFilter($project)
444 { let $incfile :=
445 (for $file in $project/files//file return
446 if (ends-with($file/@name,".h") or ends-with($file/@name,".hpp")) then
447 (local:indent(4),<ClInclude xmlns="http://schemas.microsoft.com/developer/msbuild/2003" Include="{local:windowsPath(concat($sourcePath,$file/@name))}" />)
448 else ()
449 ) return
450 if (empty($incfile)) then ()
451 else (local:indent(2),<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
452 {$incfile}
453 {local:indent(2)}</ItemGroup>)
454 };
455
456 declare function local:generateSrcFilesNoFilter($project)
457 { let $srcfile :=
458 (for $file in $project/files//file return
459 if (ends-with($file/@name,".rc") or ends-with($file/@name,".def") or ends-with($file/@name,".h") or ends-with($file/@name,".hpp")) then ()
460 else (
461 if (contains($special_file, $file/@name)) then
462 (local:indent(4),<ClCompile xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
463 Condition="exists('{local:windowsPath(concat($sourcePath,$file/@name))}')"
464 Include="{local:windowsPath(concat($sourcePath,$file/@name))}"/>)
465 else
466 (local:indent(4),<ClCompile xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
467 Include="{local:windowsPath(concat($sourcePath,$file/@name))}"/>)
468 )
469 ) return
470 if (empty($srcfile)) then ()
471 else (local:indent(2),<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
472 {$srcfile}
473 {local:indent(2)}</ItemGroup>)
474 };
475
476
477 declare function local:generateRcFilesNoFilter($project)
478 {
479 for $file in $project/files//file return
480 if (ends-with($file/@name,".rc")) then
481 (local:indent(2),<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
482 {local:indent(4)}<ResourceCompile Include="{local:windowsPath(concat($sourcePath,$file/@name))}">
483 {for $platform in local:getPlatforms($vsversion) return
484 for $config in local:getConfiguration($project) return(
485 local:indent(6), <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=={concat("'",$config,"|",$platform,"'")}">{concat(if ($config="Debug") then "_DEBUG" else "NDEBUG",";","$(NoInherit))",";%(PreprocessorDefinitions)")}</PreprocessorDefinitions>)
486 }
487 {local:indent(4)}</ResourceCompile>
488 {local:indent(2)}</ItemGroup>
489 )
490 else ()
491
492
493 };
494
495
496 declare function local:generateDefFilesNoFilter($project)
497 {
498 for $file in $project/files//file return
499 if (ends-with($file/@name,".def")) then
500 (
501 local:indent(2),<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
502 {local:indent(4)}<None Include="../{substring-after($file/@name,"/")}" />
503 {local:indent(2)}</ItemGroup>
504 )
505 else ()
506 };
507
508 declare function local:generateFilesWithFilter($project,$filter)
509 {
510 <a/>
511 };
512
513 declare function local:genFiles($project)
514 {
515 local:generateIncFilesNoFilter($project),
516 local:generateSrcFilesNoFilter($project),
517 local:generateDefFilesNoFilter($project),
518 local:generateRcFilesNoFilter($project)
519 };
520
521
522 declare function local:getConfiguration($project)
523 {
524 for $compType in ("Debug", "Release") return
525 for $config in $project/configuration return
526 concat($config, $compType)
527 };
528
529
530 for $project in local:getProjects()
531 return
532 ('<?xml version="1.0" encoding="utf-8" ?>',
533 <Project DefaultTargets="Build" ToolsVersion="{$msbversion}" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
534 {local:generateProjectConfigurations($project)}
535 {local:generateGlobalProperty($project)}
536 {local:indent(2)}<Import Project="{$msbdefprops}" />
537 {local:generateConfigurations($project)}
538 {local:indent(2)}<Import Project="{$msbprops}" />
539 {local:genExtensionSettings()}
540 {local:genPropertySheets($project)}
541 {local:genImportProperty($project)}
542 {local:indent(2)}<PropertyGroup Label="UserMacros" />
543 {local:genMacros($project)}
544 {local:genDefinition($project)}
545 {local:genFiles($project)}
546 {local:indent(2)}<Import Project="{$msbtargets}" />
547 {local:genExtensionTargets()}
548 {local:indent(2)}<ItemGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
549 {local:addProjectDependencies($project)}
550 {local:indent(2)}</ItemGroup>
551 {local:indent(0)}</Project>)