Add scripts to generate projects for other buildsystems (MSVC vcproj, QMake)
[alt-git.git] / contrib / buildsystems / Generators / Vcproj.pm
blob00ec0c136913a8faf9489fd56795b6e25d4022f4
1 package Generators::Vcproj;
2 require Exporter;
4 use strict;
5 use vars qw($VERSION);
7 our $VERSION = '1.00';
8 our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
9 @ISA = qw(Exporter);
11 BEGIN {
12 push @EXPORT_OK, qw(generate);
15 my $guid_index = 0;
16 my @GUIDS = (
17 "{E07B9989-2BF7-4F21-8918-BE22BA467AC3}",
18 "{278FFB51-0296-4A44-A81A-22B87B7C3592}",
19 "{7346A2C4-F0FD-444F-9EBE-1AF23B2B5650}",
20 "{67F421AC-EB34-4D49-820B-3196807B423F}",
21 "{385DCFE1-CC8C-4211-A451-80FCFC31CA51}",
22 "{97CC46C5-D2CC-4D26-B634-E75792B79916}",
23 "{C7CE21FE-6EF8-4012-A5C7-A22BCEDFBA11}",
24 "{51575134-3FDF-42D1-BABD-3FB12669C6C9}",
25 "{0AE195E4-9823-4B87-8E6F-20C5614AF2FF}",
26 "{4B918255-67CA-43BB-A46C-26704B666E6B}",
27 "{18CCFEEF-C8EE-4CC1-A265-26F95C9F4649}",
28 "{5D5D90FA-01B7-4973-AFE5-CA88C53AC197}",
29 "{1F054320-036D-49E1-B384-FB5DF0BC8AC0}",
30 "{7CED65EE-F2D9-4171-825B-C7D561FE5786}",
31 "{8D341679-0F07-4664-9A56-3BA0DE88B9BC}",
32 "{C189FEDC-2957-4BD7-9FA4-7622241EA145}",
33 "{66844203-1B9F-4C53-9274-164FFF95B847}",
34 "{E4FEA145-DECC-440D-AEEA-598CF381FD43}",
35 "{73300A8E-C8AC-41B0-B555-4F596B681BA7}",
36 "{873FDEB1-D01D-40BF-A1BF-8BBC58EC0F51}",
37 "{7922C8BE-76C5-4AC6-8BF7-885C0F93B782}",
38 "{E245D370-308B-4A49-BFC1-1E527827975F}",
39 "{F6FA957B-66FC-4ED7-B260-E59BBE4FE813}",
40 "{E6055070-0198-431A-BC49-8DB6CEE770AE}",
41 "{54159234-C3EB-43DA-906B-CE5DA5C74654}",
42 "{594CFC35-0B60-46F6-B8EF-9983ACC1187D}",
43 "{D93FCAB7-1F01-48D2-B832-F761B83231A5}",
44 "{DBA5E6AC-E7BE-42D3-8703-4E787141526E}",
45 "{6171953F-DD26-44C7-A3BE-CC45F86FC11F}",
46 "{9E19DDBE-F5E4-4A26-A2FE-0616E04879B8}",
47 "{AE81A615-99E3-4885-9CE0-D9CAA193E867}",
48 "{FBF4067E-1855-4F6C-8BCD-4D62E801A04D}",
49 "{17007948-6593-4AEB-8106-F7884B4F2C19}",
50 "{199D4C8D-8639-4DA6-82EF-08668C35DEE0}",
51 "{E085E50E-C140-4CF3-BE4B-094B14F0DDD6}",
52 "{00785268-A9CC-4E40-AC29-BAC0019159CE}",
53 "{4C06F56A-DCDB-46A6-B67C-02339935CF12}",
54 "{3A62D3FD-519E-4EC9-8171-D2C1BFEA022F}",
55 "{3A62D3FD-519E-4EC9-8171-D2C1BFEA022F}",
56 "{9392EB58-D7BA-410B-B1F0-B2FAA6BC89A7}",
57 "{2ACAB2D5-E0CE-4027-BCA0-D78B2D7A6C66}",
58 "{86E216C3-43CE-481A-BCB2-BE5E62850635}",
59 "{FB631291-7923-4B91-9A57-7B18FDBB7A42}",
60 "{0A176EC9-E934-45B8-B87F-16C7F4C80039}",
61 "{DF55CA80-46E8-4C53-B65B-4990A23DD444}",
62 "{3A0F9895-55D2-4710-BE5E-AD7498B5BF44}",
63 "{294BDC5A-F448-48B6-8110-DD0A81820F8C}",
64 "{4B9F66E9-FAC9-47AB-B1EF-C16756FBFD06}",
65 "{72EA49C6-2806-48BD-B81B-D4905102E19C}",
66 "{5728EB7E-8929-486C-8CD5-3238D060E768}"
69 sub generate {
70 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
71 my @libs = @{$build_structure{"LIBS"}};
72 foreach (@libs) {
73 createLibProject($_, $git_dir, $out_dir, $rel_dir, \%build_structure);
76 my @apps = @{$build_structure{"APPS"}};
77 foreach (@apps) {
78 createAppProject($_, $git_dir, $out_dir, $rel_dir, \%build_structure);
81 createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
82 return 0;
85 sub createLibProject {
86 my ($libname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
87 print "Generate $libname vcproj lib project\n";
88 $rel_dir = "..\\$rel_dir";
89 $rel_dir =~ s/\//\\/g;
91 my $target = $libname;
92 $target =~ s/\//_/g;
93 $target =~ s/\.a//;
95 my $uuid = $GUIDS[$guid_index];
96 $$build_structure{"LIBS_${target}_GUID"} = $uuid;
97 $guid_index += 1;
99 my @srcs = sort(map("$rel_dir\\$_", @{$$build_structure{"LIBS_${libname}_SOURCES"}}));
100 my @sources;
101 foreach (@srcs) {
102 $_ =~ s/\//\\/g;
103 push(@sources, $_);
105 my $defines = join(",", sort(@{$$build_structure{"LIBS_${libname}_DEFINES"}}));
106 my $includes= join(";", sort(map(""$rel_dir\\$_"", @{$$build_structure{"LIBS_${libname}_INCLUDES"}})));
107 my $cflags = join(" ", sort(@{$$build_structure{"LIBS_${libname}_CFLAGS"}}));
108 $cflags =~ s/\"/"/g;
110 my $cflags_debug = $cflags;
111 $cflags_debug =~ s/-MT/-MTd/;
112 $cflags_debug =~ s/-O.//;
114 my $cflags_release = $cflags;
115 $cflags_release =~ s/-MTd/-MT/;
117 my @tmp = @{$$build_structure{"LIBS_${libname}_LFLAGS"}};
118 my @tmp2 = ();
119 foreach (@tmp) {
120 if (/^-LTCG/) {
121 } elsif (/^-L/) {
122 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
124 push(@tmp2, $_);
126 my $lflags = join(" ", sort(@tmp));
128 $defines =~ s/-D//g;
129 $defines =~ s/\"/\\"/g;
130 $defines =~ s/\'//g;
131 $includes =~ s/-I//g;
132 mkdir "$target" || die "Could not create the directory $target for lib project!\n";
133 open F, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
134 print F << "EOM";
135 <?xml version="1.0" encoding = "Windows-1252"?>
136 <VisualStudioProject
137 ProjectType="Visual C++"
138 Version="9,00"
139 Name="$target"
140 ProjectGUID="$uuid">
141 <Platforms>
142 <Platform
143 Name="Win32"/>
144 </Platforms>
145 <ToolFiles>
146 </ToolFiles>
147 <Configurations>
148 <Configuration
149 Name="Debug|Win32"
150 OutputDirectory="$rel_dir"
151 ConfigurationType="4"
152 CharacterSet="0"
153 IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
155 <Tool
156 Name="VCPreBuildEventTool"
158 <Tool
159 Name="VCCustomBuildTool"
161 <Tool
162 Name="VCXMLDataGeneratorTool"
164 <Tool
165 Name="VCWebServiceProxyGeneratorTool"
167 <Tool
168 Name="VCMIDLTool"
170 <Tool
171 Name="VCCLCompilerTool"
172 AdditionalOptions="$cflags_debug"
173 Optimization="0"
174 InlineFunctionExpansion="1"
175 AdditionalIncludeDirectories="$includes"
176 PreprocessorDefinitions="UNICODE,WIN32,_DEBUG,$defines"
177 MinimalRebuild="true"
178 RuntimeLibrary="1"
179 UsePrecompiledHeader="0"
180 WarningLevel="3"
181 DebugInformationFormat="3"
183 <Tool
184 Name="VCManagedResourceCompilerTool"
186 <Tool
187 Name="VCResourceCompilerTool"
189 <Tool
190 Name="VCPreLinkEventTool"
192 <Tool
193 Name="VCLibrarianTool"
194 SuppressStartupBanner="true"
196 <Tool
197 Name="VCALinkTool"
199 <Tool
200 Name="VCXDCMakeTool"
202 <Tool
203 Name="VCBscMakeTool"
205 <Tool
206 Name="VCFxCopTool"
208 <Tool
209 Name="VCPostBuildEventTool"
211 </Configuration>
212 <Configuration
213 Name="Release|Win32"
214 OutputDirectory="$rel_dir"
215 ConfigurationType="4"
216 CharacterSet="0"
217 WholeProgramOptimization="1"
218 IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
220 <Tool
221 Name="VCPreBuildEventTool"
223 <Tool
224 Name="VCCustomBuildTool"
226 <Tool
227 Name="VCXMLDataGeneratorTool"
229 <Tool
230 Name="VCWebServiceProxyGeneratorTool"
232 <Tool
233 Name="VCMIDLTool"
235 <Tool
236 Name="VCCLCompilerTool"
237 AdditionalOptions="$cflags_release"
238 Optimization="2"
239 InlineFunctionExpansion="1"
240 EnableIntrinsicFunctions="true"
241 AdditionalIncludeDirectories="$includes"
242 PreprocessorDefinitions="UNICODE,WIN32,NDEBUG,$defines"
243 RuntimeLibrary="0"
244 EnableFunctionLevelLinking="true"
245 UsePrecompiledHeader="0"
246 WarningLevel="3"
247 DebugInformationFormat="3"
249 <Tool
250 Name="VCManagedResourceCompilerTool"
252 <Tool
253 Name="VCResourceCompilerTool"
255 <Tool
256 Name="VCPreLinkEventTool"
258 <Tool
259 Name="VCLibrarianTool"
260 SuppressStartupBanner="true"
262 <Tool
263 Name="VCALinkTool"
265 <Tool
266 Name="VCXDCMakeTool"
268 <Tool
269 Name="VCBscMakeTool"
271 <Tool
272 Name="VCFxCopTool"
274 <Tool
275 Name="VCPostBuildEventTool"
277 </Configuration>
278 </Configurations>
279 <Files>
280 <Filter
281 Name="Source Files"
282 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
283 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
285 foreach(@sources) {
286 print F << "EOM";
287 <File
288 RelativePath="$_"/>
291 print F << "EOM";
292 </Filter>
293 </Files>
294 <Globals>
295 </Globals>
296 </VisualStudioProject>
298 close F;
301 sub createAppProject {
302 my ($appname, $git_dir, $out_dir, $rel_dir, $build_structure) = @_;
303 print "Generate $appname vcproj app project\n";
304 $rel_dir = "..\\$rel_dir";
305 $rel_dir =~ s/\//\\/g;
307 my $target = $appname;
308 $target =~ s/\//_/g;
309 $target =~ s/\.exe//;
311 my $uuid = $GUIDS[$guid_index];
312 $$build_structure{"APPS_${target}_GUID"} = $uuid;
313 $guid_index += 1;
315 my @srcs = sort(map("$rel_dir\\$_", @{$$build_structure{"APPS_${appname}_SOURCES"}}));
316 my @sources;
317 foreach (@srcs) {
318 $_ =~ s/\//\\/g;
319 push(@sources, $_);
321 my $defines = join(",", sort(@{$$build_structure{"APPS_${appname}_DEFINES"}}));
322 my $includes= join(";", sort(map("&quot;$rel_dir\\$_&quot;", @{$$build_structure{"APPS_${appname}_INCLUDES"}})));
323 my $cflags = join(" ", sort(@{$$build_structure{"APPS_${appname}_CFLAGS"}}));
324 $cflags =~ s/\"/&quot;/g;
326 my $cflags_debug = $cflags;
327 $cflags_debug =~ s/-MT/-MTd/;
328 $cflags_debug =~ s/-O.//;
330 my $cflags_release = $cflags;
331 $cflags_release =~ s/-MTd/-MT/;
333 my $libs;
334 foreach (sort(@{$$build_structure{"APPS_${appname}_LIBS"}})) {
335 $_ =~ s/\//_/g;
336 $libs .= " $_";
338 my @tmp = @{$$build_structure{"APPS_${appname}_LFLAGS"}};
339 my @tmp2 = ();
340 foreach (@tmp) {
341 if (/^-LTCG/) {
342 } elsif (/^-L/) {
343 $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
345 push(@tmp2, $_);
347 my $lflags = join(" ", sort(@tmp)) . " -LIBPATH:$rel_dir";
349 $defines =~ s/-D//g;
350 $defines =~ s/\"/\\&quot;/g;
351 $defines =~ s/\'//g;
352 $defines =~ s/\\\\/\\/g;
353 $includes =~ s/-I//g;
354 mkdir "$target" || die "Could not create the directory $target for lib project!\n";
355 open F, ">$target/$target.vcproj" || die "Could not open $target/$target.pro for writing!\n";
356 print F << "EOM";
357 <?xml version="1.0" encoding = "Windows-1252"?>
358 <VisualStudioProject
359 ProjectType="Visual C++"
360 Version="9,00"
361 Name="$target"
362 ProjectGUID="$uuid">
363 <Platforms>
364 <Platform
365 Name="Win32"/>
366 </Platforms>
367 <ToolFiles>
368 </ToolFiles>
369 <Configurations>
370 <Configuration
371 Name="Debug|Win32"
372 OutputDirectory="$rel_dir"
373 ConfigurationType="1"
374 CharacterSet="0"
375 IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
377 <Tool
378 Name="VCPreBuildEventTool"
380 <Tool
381 Name="VCCustomBuildTool"
383 <Tool
384 Name="VCXMLDataGeneratorTool"
386 <Tool
387 Name="VCWebServiceProxyGeneratorTool"
389 <Tool
390 Name="VCMIDLTool"
392 <Tool
393 Name="VCCLCompilerTool"
394 AdditionalOptions="$cflags_debug"
395 Optimization="0"
396 InlineFunctionExpansion="1"
397 AdditionalIncludeDirectories="$includes"
398 PreprocessorDefinitions="UNICODE,WIN32,_DEBUG,$defines"
399 MinimalRebuild="true"
400 RuntimeLibrary="1"
401 UsePrecompiledHeader="0"
402 WarningLevel="3"
403 DebugInformationFormat="3"
405 <Tool
406 Name="VCManagedResourceCompilerTool"
408 <Tool
409 Name="VCResourceCompilerTool"
411 <Tool
412 Name="VCPreLinkEventTool"
414 <Tool
415 Name="VCLinkerTool"
416 AdditionalDependencies="$libs"
417 AdditionalOptions="$lflags"
418 LinkIncremental="2"
419 GenerateDebugInformation="true"
420 SubSystem="1"
421 TargetMachine="1"
423 <Tool
424 Name="VCALinkTool"
426 <Tool
427 Name="VCXDCMakeTool"
429 <Tool
430 Name="VCBscMakeTool"
432 <Tool
433 Name="VCFxCopTool"
435 <Tool
436 Name="VCPostBuildEventTool"
438 </Configuration>
439 <Configuration
440 Name="Release|Win32"
441 OutputDirectory="$rel_dir"
442 ConfigurationType="1"
443 CharacterSet="0"
444 WholeProgramOptimization="1"
445 IntermediateDirectory="\$(ProjectDir)\$(ConfigurationName)"
447 <Tool
448 Name="VCPreBuildEventTool"
450 <Tool
451 Name="VCCustomBuildTool"
453 <Tool
454 Name="VCXMLDataGeneratorTool"
456 <Tool
457 Name="VCWebServiceProxyGeneratorTool"
459 <Tool
460 Name="VCMIDLTool"
462 <Tool
463 Name="VCCLCompilerTool"
464 AdditionalOptions="$cflags_release"
465 Optimization="2"
466 InlineFunctionExpansion="1"
467 EnableIntrinsicFunctions="true"
468 AdditionalIncludeDirectories="$includes"
469 PreprocessorDefinitions="UNICODE,WIN32,NDEBUG,$defines"
470 RuntimeLibrary="0"
471 EnableFunctionLevelLinking="true"
472 UsePrecompiledHeader="0"
473 WarningLevel="3"
474 DebugInformationFormat="3"
476 <Tool
477 Name="VCManagedResourceCompilerTool"
479 <Tool
480 Name="VCResourceCompilerTool"
482 <Tool
483 Name="VCPreLinkEventTool"
485 <Tool
486 Name="VCLinkerTool"
487 AdditionalDependencies="$libs"
488 AdditionalOptions="$lflags"
489 LinkIncremental="1"
490 GenerateDebugInformation="true"
491 SubSystem="1"
492 TargetMachine="1"
493 OptimizeReferences="2"
494 EnableCOMDATFolding="2"
496 <Tool
497 Name="VCALinkTool"
499 <Tool
500 Name="VCXDCMakeTool"
502 <Tool
503 Name="VCBscMakeTool"
505 <Tool
506 Name="VCFxCopTool"
508 <Tool
509 Name="VCPostBuildEventTool"
511 </Configuration>
512 </Configurations>
513 <Files>
514 <Filter
515 Name="Source Files"
516 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
517 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
519 foreach(@sources) {
520 print F << "EOM";
521 <File
522 RelativePath="$_"/>
525 print F << "EOM";
526 </Filter>
527 </Files>
528 <Globals>
529 </Globals>
530 </VisualStudioProject>
532 close F;
535 sub createGlueProject {
536 my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
537 print "Generate solutions file\n";
538 $rel_dir = "..\\$rel_dir";
539 $rel_dir =~ s/\//\\/g;
540 my $SLN_HEAD = "Microsoft Visual Studio Solution File, Format Version 10.00\n";
541 my $SLN_PRE = "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = ";
542 my $SLN_POST = "\nEndProject\n";
544 my @libs = @{$build_structure{"LIBS"}};
545 my @tmp;
546 foreach (@libs) {
547 $_ =~ s/\//_/g;
548 $_ =~ s/\.a//;
549 push(@tmp, $_);
551 @libs = @tmp;
553 my @apps = @{$build_structure{"APPS"}};
554 @tmp = ();
555 foreach (@apps) {
556 $_ =~ s/\//_/g;
557 $_ =~ s/\.exe//;
558 push(@tmp, $_);
560 @apps = @tmp;
562 open F, ">git.sln" || die "Could not open git.sln for writing!\n";
563 print F "$SLN_HEAD";
564 foreach (@libs) {
565 my $libname = $_;
566 my $uuid = $build_structure{"LIBS_${libname}_GUID"};
567 print F "$SLN_PRE";
568 print F "\"${libname}\", \"${libname}\\${libname}.vcproj\", \"${uuid}\"";
569 print F "$SLN_POST";
571 foreach (@apps) {
572 my $appname = $_;
573 my $uuid = $build_structure{"APPS_${appname}_GUID"};
574 print F "$SLN_PRE";
575 print F "\"${appname}\", \"${appname}\\${appname}.vcproj\", \"${uuid}\"";
576 print F "$SLN_POST";
579 print F << "EOM";
580 Global
581 GlobalSection(SolutionConfiguration) = preSolution
582 ConfigName.0 = Debug|Win32
583 ConfigName.1 = Release|Win32
584 EndGlobalSection
585 GlobalSection(ProjectDependencies) = postSolution
587 foreach (@{$build_structure{"APPS"}}) {
588 my $appname = $_;
589 my $appname_clean = $_;
590 $appname_clean =~ s/\//_/g;
591 $appname_clean =~ s/\.exe//;
593 my $uuid = $build_structure{"APPS_${appname_clean}_GUID"};
594 my $dep_index = 0;
595 foreach(@{$build_structure{"APPS_${appname}_LIBS"}}) {
596 my $libname = $_;
597 $libname =~ s/\//_/g;
598 $libname =~ s/\.(a|lib)//;
599 my $libuuid = $build_structure{"LIBS_${libname}_GUID"};
600 if (defined $libuuid) {
601 print F "\t\t${uuid}.${dep_index} = ${libuuid}\n";
602 $dep_index += 1;
607 print F << "EOM";
608 EndGlobalSection
609 GlobalSection(ProjectConfiguration) = postSolution
611 foreach (@libs) {
612 my $libname = $_;
613 my $uuid = $build_structure{"LIBS_${libname}_GUID"};
614 print F "\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
615 print F "\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
616 print F "\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
617 print F "\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";
619 foreach (@apps) {
620 my $appname = $_;
621 my $uuid = $build_structure{"APPS_${appname}_GUID"};
622 print F "\t\t${uuid}.Debug|Win32.ActiveCfg = Debug|Win32\n";
623 print F "\t\t${uuid}.Debug|Win32.Build.0 = Debug|Win32\n";
624 print F "\t\t${uuid}.Release|Win32.ActiveCfg = Release|Win32\n";
625 print F "\t\t${uuid}.Release|Win32.Build.0 = Release|Win32\n";
628 print F << "EOM";
629 EndGlobalSection
630 GlobalSection(ExtensibilityGlobals) = postSolution
631 EndGlobalSection
632 GlobalSection(ExtensibilityAddIns) = postSolution
633 EndGlobalSection
634 EndGlobal
636 close F;