Merge pull request #224 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / VC7WorkspaceCreator.pm
blobcd07b1bd799f225f93402e5c8cfcbdea0c453f91
1 package VC7WorkspaceCreator;
3 # ************************************************************
4 # Description : A VC7 Workspace Creator
5 # Author : Chad Elliott
6 # Create Date : 5/14/2002
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use VC7ProjectCreator;
16 use WinWorkspaceBase;
17 use WorkspaceCreator;
18 use VCPropertyBase;
20 use vars qw(@ISA);
21 @ISA = qw(VCPropertyBase WinWorkspaceBase WorkspaceCreator);
23 # ************************************************************
24 # Data Section
25 # ************************************************************
27 ## NOTE: We call the constant as a function to support Perl 5.6.
28 my %guids = (Creator::cplusplus() => '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942',
29 Creator::csharp() => 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC',
30 Creator::java() => 'E6FDF86B-F3D1-11D4-8576-0002A516ECE8',
31 Creator::vb() => 'F184B08F-C81C-45F6-A57F-5ABD9991F28F',
32 Creator::website() => 'E24C65DC-7377-472B-9ABA-BC803B73C61A',
35 # ************************************************************
36 # Subroutine Section
37 # ************************************************************
39 sub compare_output {
40 #my $self = shift;
41 return 1;
45 sub workspace_file_extension {
46 #my $self = shift;
47 return '.sln';
51 sub pre_workspace {
52 my($self, $fh) = @_;
53 my $crlf = $self->crlf();
55 ## This identifies it as a Visual Studio file
56 print $fh 'Microsoft Visual Studio Solution File, Format Version 7.00', $crlf;
58 ## Optionally print the workspace comment
59 $self->print_workspace_comment($fh,
60 '#', $crlf,
61 '# This file was generated by MPC. Any changes made directly to', $crlf,
62 '# this file will be lost the next time it is generated.', $crlf,
63 '#', $crlf,
64 '# MPC Command:', $crlf,
65 '# ', $self->create_command_line_string($0, @ARGV), $crlf);
69 sub print_inner_project {
70 #my $self = shift;
71 #my $fh = shift;
72 #my $gen = shift;
73 #my $pguid = shift;
74 #my $deps = shift;
75 #my $name = shift;
76 #my $name_to_guid_map = shift;
77 #my $proj_language = shift;
78 #my $cfgs = shift;
83 sub print_configs {
84 my($self, $fh, $configs) = @_;
85 my $crlf = $self->crlf();
86 my $count = 0;
88 ## Print out the configurations for the solution
89 foreach my $key (sort keys %$configs) {
90 print $fh "\t\tConfigName.$count = $key$crlf";
91 $count++;
96 sub print_dependencies {
97 my($self, $fh, $gen, $list, $pjs) = @_;
98 my $crlf = $self->crlf();
100 ## I hate to add yet another loop through all the projects, but
101 ## we must have some way to map plain project names to guids.
102 my %name_to_guid_map;
103 foreach my $project (@$list) {
104 my($name, $guid) = $gen->access_pi_values($pjs, $project,
105 ProjectCreator::PROJECT_NAME,
106 ProjectCreator::PROJECT_GUID);
107 $name_to_guid_map{$name} = $guid;
110 ## Project Dependencies
111 print $fh "\tGlobalSection(ProjectDependencies) = postSolution$crlf";
112 foreach my $project (@$list) {
113 my($name, $project_guid) = $gen->access_pi_values(
114 $pjs, $project,
115 ProjectCreator::PROJECT_NAME,
116 ProjectCreator::PROJECT_GUID);
117 my $deps = $self->get_validated_ordering($project);
118 if (defined $$deps[0]) {
119 my $i = 0;
120 foreach my $dep (@$deps) {
121 my $guid = $name_to_guid_map{$dep};
122 if (defined $guid) {
123 print $fh "\t\t{$project_guid}.$i = {$guid}$crlf";
124 $i++;
129 print $fh "\tEndGlobalSection$crlf";
133 sub write_comps {
134 my($self, $fh, $gen) = @_;
135 my $projects = $self->get_projects();
136 my $pjs = $self->get_project_info();
137 my @list = sort @$projects;
138 my $crlf = $self->crlf();
140 ## I hate to add yet another loop through all the projects, but
141 ## we must have some way to map plain project names to guids.
142 my %name_to_guid_map;
143 foreach my $project (@list) {
144 my($name, $guid) = $gen->access_pi_values($pjs, $project,
145 ProjectCreator::PROJECT_NAME,
146 ProjectCreator::PROJECT_GUID);
147 $name_to_guid_map{$name} = $guid;
150 ## Project Information
151 foreach my $project (@list) {
152 my($pname, $guid, $language, @cfgs) =
153 $gen->access_pi_values($pjs, $project,
154 ProjectCreator::PROJECT_NAME,
155 ProjectCreator::PROJECT_GUID,
156 ProjectCreator::LANGUAGE,
157 ProjectCreator::CONFIGURATIONS);
158 my $pguid = $guids{$language};
159 my $deps = $self->get_validated_ordering($project);
160 my($name, $proj) = $self->adjust_names($pname, $project, $language);
161 print $fh "Project(\"{$pguid}\") = \"$name\", \"$proj\", \"{$guid}\"$crlf";
162 $self->print_inner_project($fh, $gen, $guid, $deps,
163 $name, \%name_to_guid_map,
164 $language, \@cfgs);
165 print $fh "EndProject$crlf";
168 ## This block creates the different possible configurations for this
169 ## solution.
170 print $fh "Global$crlf",
171 "\tGlobalSection(",
172 $self->get_solution_config_section_name(),
173 ") = preSolution$crlf";
174 my %configs;
175 foreach my $project (@list) {
176 my @cfgs = $gen->access_pi_values($pjs, $project,
177 ProjectCreator::CONFIGURATIONS);
178 foreach my $cfg (@cfgs) {
179 $configs{$self->get_short_config_name($cfg)} = $cfg;
182 $self->print_configs($fh, \%configs);
183 print $fh "\tEndGlobalSection$crlf";
185 ## Print dependencies if there are any
186 $self->print_dependencies($fh, $gen, \@list, $pjs);
188 ## Project Configuration Names
189 print $fh "\tGlobalSection(",
190 $self->get_project_config_section_name(),
191 ") = postSolution$crlf";
193 ## See if there is an 'Any CPU' or '.NET' configuration
194 my $anycpu;
195 foreach my $key (keys %configs) {
196 if (index($key, 'Any CPU') >= 0 || index($key, '.NET') >= 0) {
197 $anycpu = 1;
198 last;
202 ## Go through each project and print out the settings per GUID
203 foreach my $project (@list) {
204 my($pguid, $custom_only, $nocross, @cfgs) =
205 $gen->access_pi_values($pjs, $project,
206 ProjectCreator::PROJECT_GUID,
207 ProjectCreator::CUSTOM_ONLY,
208 ProjectCreator::NO_CROSS_COMPILE,
209 ProjectCreator::CONFIGURATIONS);
210 my %all_configs = %configs;
211 foreach my $cfg (sort @cfgs) {
212 my $c = $self->get_short_config_name($cfg);
213 my $deployable = !$nocross && !$custom_only;
214 my $buildable = !$nocross;
216 ## I don't like this hard-coded configuration information.
217 ## CAE 11/4/2010
218 if (index($cfg, 'Win32') >= 0 || index($cfg, 'x64') >= 0) {
219 $deployable = undef;
220 $buildable = 1;
223 if (defined $anycpu) {
224 ## There is a non-C++ project; there is no need to explicitly
225 ## enable building of the configurations for this project. So, we
226 ## get rid of the configuration settings from the copy of the
227 ## configs map.
228 delete $all_configs{$c};
230 else {
231 print $fh "\t\t{$pguid}.$c.ActiveCfg = $cfg$crlf";
232 print $fh "\t\t{$pguid}.$c.Build.0 = $cfg$crlf" if ($buildable);
233 print $fh "\t\t{$pguid}.$c.Deploy.0 = $cfg$crlf" if ($deployable);
237 ## If this is a mixed language workspace, we need to explicitly
238 ## enable the building of the non-C++ projects when any platform
239 ## other than Any CPU/.NET is selected.
240 if (defined $anycpu) {
241 my %printed;
242 foreach my $c (sort @cfgs) {
243 if ($c =~ /(.+\|)/) {
244 my $cfg = $1;
245 foreach my $remainder (sort keys %all_configs) {
246 if (index($remainder, $cfg) == 0) {
247 if (!$printed{$pguid.$remainder}) {
248 print $fh "\t\t{$pguid}.$remainder.ActiveCfg = $c$crlf",
249 "\t\t{$pguid}.$remainder.Build.0 = $c$crlf";
250 $printed{$pguid.$remainder} = 1;
255 print $fh "\t\t{$pguid}.$c.ActiveCfg = $c$crlf",
256 "\t\t{$pguid}.$c.Build.0 = $c$crlf";
259 else {
260 ## Non-C++ projects have no configurations
261 if (!defined $cfgs[0]) {
262 foreach my $c (sort keys %configs) {
263 my $cfg = $c . '|.NET';
264 print $fh "\t\t{$pguid}.$c.ActiveCfg = $cfg$crlf",
265 "\t\t{$pguid}.$c.Build.0 = $cfg$crlf";
270 print $fh "\tEndGlobalSection$crlf";
272 $self->print_additional_sections($fh);
274 print $fh "EndGlobal$crlf";
278 sub adjust_names {
279 my($self, $name, $proj, $lang) = @_;
280 $proj =~ s/\//\\/g;
281 return $name, $proj;
285 sub get_short_config_name {
286 my($self, $cfg) = @_;
287 $cfg =~ s/\|.*//;
288 return $cfg;
292 sub get_solution_config_section_name {
293 #my $self = shift;
294 return 'SolutionConfiguration';
298 sub get_project_config_section_name {
299 #my $self = shift;
300 return 'ProjectConfiguration';
304 sub print_additional_sections {
305 my($self, $fh) = @_;
306 my $crlf = $self->crlf();
308 print $fh "\tGlobalSection(ExtensibilityGlobals) = postSolution$crlf",
309 "\tEndGlobalSection$crlf",
310 "\tGlobalSection(ExtensibilityAddIns) = postSolution$crlf",
311 "\tEndGlobalSection$crlf";