1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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"
18 //----------------------------------------------------------------------------
19 cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
21 this->FindMakeProgramFile = "CMakeVS71FindMake.cmake";
22 this->ProjectConfigurationSectionName = "ProjectConfiguration";
25 //----------------------------------------------------------------------------
26 ///! Create a local generator appropriate to this Global Generator
27 cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
29 cmLocalVisualStudio7Generator *lg =
30 new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS71);
31 lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
32 lg->SetGlobalGenerator(this);
36 //----------------------------------------------------------------------------
37 void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf)
39 this->cmGlobalVisualStudio7Generator::AddPlatformDefinitions(mf);
40 mf->RemoveDefinition("MSVC70");
41 mf->AddDefinition("MSVC71", "1");
44 //----------------------------------------------------------------------------
45 std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
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
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...
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...
65 // base begins with the VisualStudioProjectsLocation reg value...
66 if (cmSystemTools::ReadRegistryValue(
67 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
68 "VisualStudioProjectsLocation",
71 cmSystemTools::ConvertToUnixSlashes(base);
74 path = base + "/VSMacros71";
77 // path is (correctly) still empty if we did not read the base value from
83 //----------------------------------------------------------------------------
84 std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
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
93 return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
97 //----------------------------------------------------------------------------
98 void cmGlobalVisualStudio71Generator
99 ::WriteSLNFile(std::ostream& fout,
100 cmLocalGenerator* root,
101 std::vector<cmLocalGenerator*>& generators)
103 // Write out the header for a SLN file
104 this->WriteSLNHeader(fout);
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);
113 this->WriteTargetsToSolution(fout, root, orderedProjectTargets);
115 bool useFolderProperty = this->UseFolderProperty();
116 if (useFolderProperty)
118 this->WriteFolders(fout);
121 // Write out the configurations information for the solution
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";
131 if (useFolderProperty)
133 // Write out project folders
134 fout << "\tGlobalSection(NestedProjects) = preSolution\n";
135 this->WriteFoldersContent(fout);
136 fout << "\tEndGlobalSection\n";
139 // Write the footer for the SLN file
140 this->WriteSLNFooter(fout);
143 //----------------------------------------------------------------------------
145 cmGlobalVisualStudio71Generator
146 ::WriteSolutionConfigurations(std::ostream& fout)
148 fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
149 for(std::vector<std::string>::iterator i = this->Configurations.begin();
150 i != this->Configurations.end(); ++i)
152 fout << "\t\t" << *i << " = " << *i << "\n";
154 fout << "\tEndGlobalSection\n";
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
162 cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
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))
174 project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
176 const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
182 std::string guid = this->GetGUID(dspname);
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";
191 fout <<"EndProject\n";
193 UtilityDependsMap::iterator ui = this->UtilityDepends.find(&t);
194 if(ui != this->UtilityDepends.end())
196 const char* uname = ui->second.c_str();
197 fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
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"
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
214 cmGlobalVisualStudio71Generator
215 ::WriteProjectDepends(std::ostream& fout,
217 const char*, cmTarget& target)
219 VSDependSet const& depends = this->VSTargetDepends[&target];
220 for(VSDependSet::const_iterator di = depends.begin();
221 di != depends.end(); ++di)
223 const char* name = di->c_str();
224 std::string guid = this->GetGUID(name);
227 std::string m = "Target: ";
228 m += target.GetName();
229 m += " depends on unknown target: ";
231 cmSystemTools::Error(m.c_str());
233 fout << "\t\t{" << guid << "} = {" << guid << "}\n";
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,
243 const char* location,
244 const char* typeGuid,
245 const std::set<cmStdString>& depends)
247 fout << "Project(\"{"
248 << (typeGuid ? typeGuid : "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942")
251 << this->ConvertToSolutionPath(location) << "\", \"{"
252 << this->GetGUID(name)
255 // write out the dependencies here VS 7.1 includes dependencies with the
256 // project instead of in the global section
259 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
260 std::set<cmStdString>::const_iterator it;
261 for(it = depends.begin(); it != depends.end(); ++it)
266 << this->GetGUID(it->c_str())
268 << this->GetGUID(it->c_str())
272 fout << "\tEndProjectSection\n";
275 fout << "EndProject\n";
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)
288 std::string guid = this->GetGUID(name);
289 for(std::vector<std::string>::iterator i = this->Configurations.begin();
290 i != this->Configurations.end(); ++i)
292 fout << "\t\t{" << guid << "}." << *i
293 << ".ActiveCfg = " << *i << "|"
294 << (platformMapping ? platformMapping : "Win32") << std::endl;
295 if(partOfDefaultBuild)
297 fout << "\t\t{" << guid << "}." << *i
298 << ".Build.0 = " << *i << "|"
299 << (platformMapping ? platformMapping : "Win32") << std::endl;
304 //----------------------------------------------------------------------------
305 // Standard end of dsw file
306 void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
308 fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
309 << "\tEndGlobalSection\n"
310 << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
311 << "\tEndGlobalSection\n"
315 //----------------------------------------------------------------------------
316 // ouput standard header for dsw file
317 void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
319 fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
322 //----------------------------------------------------------------------------
323 void cmGlobalVisualStudio71Generator
324 ::GetDocumentation(cmDocumentationEntry& entry) const
326 entry.Name = this->GetName();
327 entry.Brief = "Generates Visual Studio .NET 2003 project files.";