Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmGlobalVisualStudio71Generator.cxx
blobeaf2c8770c71b28feb1f3b503610d14cd24b12ab
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio71Generator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-01-21 21:39:42 $
7 Version: $Revision: 1.51 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "windows.h" // this must be first to define GetCurrentDirectory
18 #include "cmGlobalVisualStudio71Generator.h"
19 #include "cmLocalVisualStudio7Generator.h"
20 #include "cmMakefile.h"
21 #include "cmake.h"
23 //----------------------------------------------------------------------------
24 cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator()
26 this->FindMakeProgramFile = "CMakeVS71FindMake.cmake";
27 this->ProjectConfigurationSectionName = "ProjectConfiguration";
30 //----------------------------------------------------------------------------
31 ///! Create a local generator appropriate to this Global Generator
32 cmLocalGenerator *cmGlobalVisualStudio71Generator::CreateLocalGenerator()
34 cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
35 lg->SetVersion71();
36 lg->SetExtraFlagTable(this->GetExtraFlagTableVS7());
37 lg->SetGlobalGenerator(this);
38 return lg;
41 //----------------------------------------------------------------------------
42 void cmGlobalVisualStudio71Generator::AddPlatformDefinitions(cmMakefile* mf)
44 mf->AddDefinition("MSVC71", "1");
47 //----------------------------------------------------------------------------
48 std::string cmGlobalVisualStudio71Generator::GetUserMacrosDirectory()
50 // Macros not supported on Visual Studio 7.1 and earlier because
51 // they do not appear to work *during* a build when called by an
52 // outside agent...
54 return "";
56 #if 0
58 // The COM result from calling a Visual Studio macro with 7.1 indicates
59 // that the call succeeds, but the macro does not appear to execute...
61 // So, I am leaving this code here to show how to do it, but have not
62 // yet figured out what the issue is in terms of why the macro does not
63 // appear to execute...
65 std::string base;
66 std::string path;
68 // base begins with the VisualStudioProjectsLocation reg value...
69 if (cmSystemTools::ReadRegistryValue(
70 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
71 "VisualStudioProjectsLocation",
72 base))
74 cmSystemTools::ConvertToUnixSlashes(base);
76 // 7.1 macros folder:
77 path = base + "/VSMacros71";
80 // path is (correctly) still empty if we did not read the base value from
81 // the Registry value
82 return path;
83 #endif
86 //----------------------------------------------------------------------------
87 std::string cmGlobalVisualStudio71Generator::GetUserMacrosRegKeyBase()
89 // Macros not supported on Visual Studio 7.1 and earlier because
90 // they do not appear to work *during* a build when called by an
91 // outside agent...
93 return "";
95 #if 0
96 return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
97 #endif
100 //----------------------------------------------------------------------------
101 void cmGlobalVisualStudio71Generator
102 ::WriteSLNFile(std::ostream& fout,
103 cmLocalGenerator* root,
104 std::vector<cmLocalGenerator*>& generators)
106 // Write out the header for a SLN file
107 this->WriteSLNHeader(fout);
109 // collect the set of targets for this project by
110 // tracing depends of all targets.
111 // also collect the set of targets that are explicitly
112 // in this project.
113 cmGlobalGenerator::TargetDependSet projectTargets;
114 cmGlobalGenerator::TargetDependSet originalTargets;
115 this->GetTargetSets(projectTargets,
116 originalTargets,
117 root, generators);
118 OrderedTargetDependSet orderedProjectTargets(projectTargets);
119 this->WriteTargetsToSolution(fout, root, orderedProjectTargets,
120 originalTargets);
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 // Write the footer for the SLN file
131 this->WriteSLNFooter(fout);
134 //----------------------------------------------------------------------------
135 void
136 cmGlobalVisualStudio71Generator
137 ::WriteSolutionConfigurations(std::ostream& fout)
139 fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
140 for(std::vector<std::string>::iterator i = this->Configurations.begin();
141 i != this->Configurations.end(); ++i)
143 fout << "\t\t" << *i << " = " << *i << "\n";
145 fout << "\tEndGlobalSection\n";
148 //----------------------------------------------------------------------------
149 // Write a dsp file into the SLN file,
150 // Note, that dependencies from executables to
151 // the libraries it uses are also done here
152 void
153 cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
154 const char* dspname,
155 const char* dir,
156 cmTarget& t)
158 // check to see if this is a fortran build
159 const char* ext = ".vcproj";
160 const char* project =
161 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
162 if(this->TargetIsFortranOnly(t))
164 ext = ".vfproj";
165 project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
168 fout << project
169 << dspname << "\", \""
170 << this->ConvertToSolutionPath(dir)
171 << "\\" << dspname << ext << "\", \"{"
172 << this->GetGUID(dspname) << "}\"\n";
173 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
174 this->WriteProjectDepends(fout, dspname, dir, t);
175 fout << "\tEndProjectSection\n";
177 fout <<"EndProject\n";
180 //----------------------------------------------------------------------------
181 // Write a dsp file into the SLN file,
182 // Note, that dependencies from executables to
183 // the libraries it uses are also done here
184 void
185 cmGlobalVisualStudio71Generator
186 ::WriteProjectDepends(std::ostream& fout,
187 const char* dspname,
188 const char*, cmTarget& target)
190 #if 0
191 // Create inter-target dependencies in the solution file. For VS
192 // 7.1 and below we cannot let static libraries depend directly on
193 // targets to which they "link" because the librarian tool will copy
194 // the targets into the static library. See
195 // cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
196 // work-around. VS 8 and above do not have this problem.
197 if (!this->VSLinksDependencies() ||
198 target.GetType() != cmTarget::STATIC_LIBRARY);
199 #else
200 if (target.GetType() != cmTarget::STATIC_LIBRARY)
201 #endif
203 cmTarget::LinkLibraryVectorType::const_iterator j, jend;
204 j = target.GetLinkLibraries().begin();
205 jend = target.GetLinkLibraries().end();
206 for(;j!= jend; ++j)
208 if(j->first != dspname)
210 // is the library part of this SLN ? If so add dependency
211 // find target anywhere because all depend libraries are
212 // brought in as well
213 if(this->FindTarget(0, j->first.c_str()))
215 fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
216 << this->GetGUID(j->first.c_str()) << "}\n";
222 std::set<cmStdString>::const_iterator i, end;
223 // write utility dependencies.
224 i = target.GetUtilities().begin();
225 end = target.GetUtilities().end();
226 for(;i!= end; ++i)
228 if(*i != dspname)
230 std::string name = this->GetUtilityForTarget(target, i->c_str());
231 std::string guid = this->GetGUID(name.c_str());
232 if(guid.size() == 0)
234 std::string m = "Target: ";
235 m += target.GetName();
236 m += " depends on unknown target: ";
237 m += name;
238 cmSystemTools::Error(m.c_str());
241 fout << "\t\t{" << guid << "} = {" << guid << "}\n";
246 //----------------------------------------------------------------------------
247 // Write a dsp file into the SLN file, Note, that dependencies from
248 // executables to the libraries it uses are also done here
249 void cmGlobalVisualStudio71Generator
250 ::WriteExternalProject(std::ostream& fout,
251 const char* name,
252 const char* location,
253 const std::vector<std::string>& depends)
255 std::cout << "WriteExternalProject vs71\n";
256 fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
257 << name << "\", \""
258 << this->ConvertToSolutionPath(location) << "\", \"{"
259 << this->GetGUID(name)
260 << "}\"\n";
262 // write out the dependencies here VS 7.1 includes dependencies with the
263 // project instead of in the global section
264 if(!depends.empty())
266 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
267 std::vector<std::string>::const_iterator it;
268 for(it = depends.begin(); it != depends.end(); ++it)
270 if(it->size() > 0)
272 fout << "\t\t{"
273 << this->GetGUID(it->c_str())
274 << "} = {"
275 << this->GetGUID(it->c_str())
276 << "}\n";
279 fout << "\tEndProjectSection\n";
282 fout << "EndProject\n";
287 //----------------------------------------------------------------------------
288 // Write a dsp file into the SLN file, Note, that dependencies from
289 // executables to the libraries it uses are also done here
290 void cmGlobalVisualStudio71Generator
291 ::WriteProjectConfigurations(std::ostream& fout, const char* name,
292 bool partOfDefaultBuild)
294 std::string guid = this->GetGUID(name);
295 for(std::vector<std::string>::iterator i = this->Configurations.begin();
296 i != this->Configurations.end(); ++i)
298 fout << "\t\t{" << guid << "}." << *i
299 << ".ActiveCfg = " << *i << "|Win32\n";
300 if(partOfDefaultBuild)
302 fout << "\t\t{" << guid << "}." << *i
303 << ".Build.0 = " << *i << "|Win32\n";
308 //----------------------------------------------------------------------------
309 // Standard end of dsw file
310 void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
312 fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
313 << "\tEndGlobalSection\n"
314 << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
315 << "\tEndGlobalSection\n"
316 << "EndGlobal\n";
319 //----------------------------------------------------------------------------
320 // ouput standard header for dsw file
321 void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
323 fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
326 //----------------------------------------------------------------------------
327 void cmGlobalVisualStudio71Generator
328 ::GetDocumentation(cmDocumentationEntry& entry) const
330 entry.Name = this->GetName();
331 entry.Brief = "Generates Visual Studio .NET 2003 project files.";
332 entry.Full = "";