Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio71Generator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "windows.h" // this must be first to define GetCurrentDirectory
13 #include "cmGlobalVisualStudio71Generator.h"
14 #include "cmLocalVisualStudio7Generator.h"
15 #include "cmMakefile.h"
16 #include "cmake.h"
17
18 //----------------------------------------------------------------------------
19 cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
20 {
21   this->FindMakeProgramFile = "CMakeVS71FindMake.cmake";
22   this->ProjectConfigurationSectionName = "ProjectConfiguration";
23 }
24
25 //----------------------------------------------------------------------------
26 ///! Create a local generator appropriate to this Global Generator
27 cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
28 {
29   cmLocalVisualStudio7Generator *lg =
30     new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS71);
31   lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
32   lg->SetGlobalGenerator(this);
33   return lg;
34 }
35
36 //----------------------------------------------------------------------------
37 void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf)
38 {
39   this->cmGlobalVisualStudio7Generator::AddPlatformDefinitions(mf);
40   mf->RemoveDefinition("MSVC70");
41   mf->AddDefinition("MSVC71", "1");
42 }
43
44 //----------------------------------------------------------------------------
45 std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
46 {
47   // Macros not supported on Visual Studio 7.1 and earlier because
48   // they do not appear to work *during* a build when called by an
49   // outside agent...
50   //
51   return "";
52
53 #if 0
54   //
55   // The COM result from calling a Visual Studio macro with 7.1 indicates
56   // that the call succeeds, but the macro does not appear to execute...
57   //
58   // So, I am leaving this code here to show how to do it, but have not
59   // yet figured out what the issue is in terms of why the macro does not
60   // appear to execute...
61   //
62   std::string base;
63   std::string path;
64
65   // base begins with the VisualStudioProjectsLocation reg value...
66   if (cmSystemTools::ReadRegistryValue(
67     "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
68     "VisualStudioProjectsLocation",
69     base))
70     {
71     cmSystemTools::ConvertToUnixSlashes(base);
72
73     // 7.1 macros folder:
74     path = base + "/VSMacros71";
75     }
76
77   // path is (correctly) still empty if we did not read the base value from
78   // the Registry value
79   return path;
80 #endif
81 }
82
83 //----------------------------------------------------------------------------
84 std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
85 {
86   // Macros not supported on Visual Studio 7.1 and earlier because
87   // they do not appear to work *during* a build when called by an
88   // outside agent...
89   //
90   return "";
91
92 #if 0
93   return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
94 #endif
95 }
96
97 //----------------------------------------------------------------------------
98 void cmGlobalVisualStudio71Generator
99 ::WriteSLNFile(std::ostream& fout,
100                cmLocalGenerator* root,
101                std::vector<cmLocalGenerator*>& generators)
102
103   // Write out the header for a SLN file
104   this->WriteSLNHeader(fout);
105
106   // Collect all targets under this root generator and the transitive
107   // closure of their dependencies.
108   TargetDependSet projectTargets;
109   TargetDependSet originalTargets;
110   this->GetTargetSets(projectTargets, originalTargets, root, generators);
111   OrderedTargetDependSet orderedProjectTargets(projectTargets);
112
113   this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
114
115   bool useFolderProperty = this->UseFolderProperty();
116   if (useFolderProperty)
117     {
118     this->WriteFolders(fout);
119     }
120
121   // Write out the configurations information for the solution
122   fout << "Global\n";
123   // Write out the configurations for the solution
124   this->WriteSolutionConfigurations(fout);
125   fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
126        << ") = postSolution\n";
127   // Write out the configurations for all the targets in the project
128   this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
129   fout << "\tEndGlobalSection\n";
130
131   if (useFolderProperty)
132     {
133     // Write out project folders
134     fout << "\tGlobalSection(NestedProjects) = preSolution\n";
135     this->WriteFoldersContent(fout);
136     fout << "\tEndGlobalSection\n";
137     }
138
139   // Write the footer for the SLN file
140   this->WriteSLNFooter(fout);
141 }
142
143 //----------------------------------------------------------------------------
144 void
145 cmGlobalVisualStudio71Generator
146 ::WriteSolutionConfigurations(std::ostream& fout)
147 {
148   fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
149   for(std::vector<std::string>::iterator i = this->Configurations.begin();
150       i != this->Configurations.end(); ++i)
151     {
152     fout << "\t\t" << *i << " = " << *i << "\n";
153     }
154   fout << "\tEndGlobalSection\n";
155 }
156
157 //----------------------------------------------------------------------------
158 // Write a dsp file into the SLN file,
159 // Note, that dependencies from executables to 
160 // the libraries it uses are also done here
161 void
162 cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
163                                               const char* dspname,
164                                               const char* dir,
165                                               cmTarget& t)
166 {
167   // check to see if this is a fortran build
168   const char* ext = ".vcproj";
169   const char* project = 
170     "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
171   if(this->TargetIsFortranOnly(t))
172     {
173     ext = ".vfproj"; 
174     project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
175     }
176   const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
177   if(targetExt)
178     {
179     ext = targetExt;
180     }
181
182   std::string guid = this->GetGUID(dspname);
183   fout << project
184        << dspname << "\", \""
185        << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
186        << dspname << ext << "\", \"{" << guid << "}\"\n";
187   fout << "\tProjectSection(ProjectDependencies) = postProject\n";
188   this->WriteProjectDepends(fout, dspname, dir, t);
189   fout << "\tEndProjectSection\n";
190   
191   fout <<"EndProject\n";
192
193   UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
194   if(ui != this->UtilityDepends.end())
195     {
196     const char* uname = ui->second.c_str();
197     fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
198          << uname << "\", \""
199          << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"")
200          << uname << ".vcproj" << "\", \"{"
201          << this->GetGUID(uname) << "}\"\n"
202          << "\tProjectSection(ProjectDependencies) = postProject\n"
203          << "\t\t{" << guid << "} = {" << guid << "}\n"
204          << "\tEndProjectSection\n"
205          << "EndProject\n";
206     }
207 }
208
209 //----------------------------------------------------------------------------
210 // Write a dsp file into the SLN file,
211 // Note, that dependencies from executables to 
212 // the libraries it uses are also done here
213 void
214 cmGlobalVisualStudio71Generator
215 ::WriteProjectDepends(std::ostream& fout,
216                       const char*,
217                       const char*, cmTarget& target)
218 {
219   VSDependSet const& depends = this->VSTargetDepends[&target];
220   for(VSDependSet::const_iterator di = depends.begin();
221       di != depends.end(); ++di)
222     {
223     const char* name = di->c_str();
224     std::string guid = this->GetGUID(name);
225     if(guid.size() == 0)
226       {
227       std::string m = "Target: ";
228       m += target.GetName();
229       m += " depends on unknown target: ";
230       m += name;
231       cmSystemTools::Error(m.c_str());
232       }
233     fout << "\t\t{" << guid << "} = {" << guid << "}\n";
234     }
235 }
236
237 //----------------------------------------------------------------------------
238 // Write a dsp file into the SLN file, Note, that dependencies from
239 // executables to the libraries it uses are also done here
240 void cmGlobalVisualStudio71Generator
241 ::WriteExternalProject(std::ostream& fout, 
242                        const char* name,
243                        const char* location,
244                        const char* typeGuid,
245                        const std::set<cmStdString>& depends)
246
247   fout << "Project(\"{"
248        << (typeGuid ? typeGuid : "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942")
249        << "}\") = \""
250        << name << "\", \""
251        << this->ConvertToSolutionPath(location) << "\", \"{"
252        << this->GetGUID(name)
253        << "}\"\n";
254   
255   // write out the dependencies here VS 7.1 includes dependencies with the
256   // project instead of in the global section
257   if(!depends.empty())
258     {
259     fout << "\tProjectSection(ProjectDependencies) = postProject\n";
260     std::set<cmStdString>::const_iterator it;
261     for(it = depends.begin(); it != depends.end(); ++it)
262       {
263       if(it->size() > 0)
264         {
265         fout << "\t\t{" 
266              << this->GetGUID(it->c_str()) 
267              << "} = {" 
268              << this->GetGUID(it->c_str()) 
269              << "}\n";
270         }
271       }
272     fout << "\tEndProjectSection\n";
273     }  
274
275   fout << "EndProject\n";
276   
277
278 }
279
280 //----------------------------------------------------------------------------
281 // Write a dsp file into the SLN file, Note, that dependencies from
282 // executables to the libraries it uses are also done here
283 void cmGlobalVisualStudio71Generator
284 ::WriteProjectConfigurations(std::ostream& fout, const char* name,
285                              bool partOfDefaultBuild,
286                              const char* platformMapping)
287 {
288   std::string guid = this->GetGUID(name);
289   for(std::vector<std::string>::iterator i = this->Configurations.begin();
290       i != this->Configurations.end(); ++i)
291     {
292     fout << "\t\t{" << guid << "}." << *i 
293          << ".ActiveCfg = " << *i << "|"
294          << (platformMapping ? platformMapping : "Win32") << std::endl;
295     if(partOfDefaultBuild)
296       {
297       fout << "\t\t{" << guid << "}." << *i
298            << ".Build.0 = " << *i << "|"
299            << (platformMapping ? platformMapping : "Win32") << std::endl;
300       }
301     }
302 }
303
304 //----------------------------------------------------------------------------
305 // Standard end of dsw file
306 void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
307 {
308   fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
309        << "\tEndGlobalSection\n"
310        << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
311        << "\tEndGlobalSection\n"
312        << "EndGlobal\n";
313 }
314
315 //----------------------------------------------------------------------------
316 // ouput standard header for dsw file
317 void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
318 {
319   fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
320 }
321
322 //----------------------------------------------------------------------------
323 void cmGlobalVisualStudio71Generator
324 ::GetDocumentation(cmDocumentationEntry& entry) const
325 {
326   entry.Name = this->GetName();
327   entry.Brief = "Generates Visual Studio .NET 2003 project files.";
328   entry.Full = "";
329 }