Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmGlobalVisualStudio71Generator.cxx
blobbc29cb66e916a9475a2837ad50c36af84a0de457
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio71Generator.cxx,v $
5 Language: C++
6 Date: $Date: 2009-07-14 18:16:46 $
7 Version: $Revision: 1.54 $
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 // Write out the configurations information for the solution
121 fout << "Global\n";
122 // Write out the configurations for the solution
123 this->WriteSolutionConfigurations(fout);
124 fout << "\tGlobalSection(" << this->ProjectConfigurationSectionName
125 << ") = postSolution\n";
126 // Write out the configurations for all the targets in the project
127 this->WriteTargetConfigurations(fout, root, orderedProjectTargets);
128 fout << "\tEndGlobalSection\n";
129 // Write the footer for the SLN file
130 this->WriteSLNFooter(fout);
133 //----------------------------------------------------------------------------
134 void
135 cmGlobalVisualStudio71Generator
136 ::WriteSolutionConfigurations(std::ostream& fout)
138 fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
139 for(std::vector<std::string>::iterator i = this->Configurations.begin();
140 i != this->Configurations.end(); ++i)
142 fout << "\t\t" << *i << " = " << *i << "\n";
144 fout << "\tEndGlobalSection\n";
147 //----------------------------------------------------------------------------
148 // Write a dsp file into the SLN file,
149 // Note, that dependencies from executables to
150 // the libraries it uses are also done here
151 void
152 cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
153 const char* dspname,
154 const char* dir,
155 cmTarget& t)
157 // check to see if this is a fortran build
158 const char* ext = ".vcproj";
159 const char* project =
160 "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"";
161 if(this->TargetIsFortranOnly(t))
163 ext = ".vfproj";
164 project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
166 const char* targetExt = t.GetProperty("GENERATOR_FILE_NAME_EXT");
167 if(targetExt)
169 ext = targetExt;
172 fout << project
173 << dspname << "\", \""
174 << this->ConvertToSolutionPath(dir)
175 << "\\" << dspname << ext << "\", \"{"
176 << this->GetGUID(dspname) << "}\"\n";
177 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
178 this->WriteProjectDepends(fout, dspname, dir, t);
179 fout << "\tEndProjectSection\n";
181 fout <<"EndProject\n";
184 //----------------------------------------------------------------------------
185 // Write a dsp file into the SLN file,
186 // Note, that dependencies from executables to
187 // the libraries it uses are also done here
188 void
189 cmGlobalVisualStudio71Generator
190 ::WriteProjectDepends(std::ostream& fout,
191 const char* dspname,
192 const char*, cmTarget& target)
194 #if 0
195 // Create inter-target dependencies in the solution file. For VS
196 // 7.1 and below we cannot let static libraries depend directly on
197 // targets to which they "link" because the librarian tool will copy
198 // the targets into the static library. See
199 // cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget for a
200 // work-around. VS 8 and above do not have this problem.
201 if (!this->VSLinksDependencies() ||
202 target.GetType() != cmTarget::STATIC_LIBRARY);
203 #else
204 if (target.GetType() != cmTarget::STATIC_LIBRARY)
205 #endif
207 cmTarget::LinkLibraryVectorType::const_iterator j, jend;
208 j = target.GetLinkLibraries().begin();
209 jend = target.GetLinkLibraries().end();
210 for(;j!= jend; ++j)
212 if(j->first != dspname)
214 // is the library part of this SLN ? If so add dependency
215 // find target anywhere because all depend libraries are
216 // brought in as well
217 if(this->FindTarget(0, j->first.c_str()))
219 fout << "\t\t{" << this->GetGUID(j->first.c_str()) << "} = {"
220 << this->GetGUID(j->first.c_str()) << "}\n";
226 std::set<cmStdString>::const_iterator i, end;
227 // write utility dependencies.
228 i = target.GetUtilities().begin();
229 end = target.GetUtilities().end();
230 for(;i!= end; ++i)
232 if(*i != dspname)
234 std::string name = this->GetUtilityForTarget(target, i->c_str());
235 std::string guid = this->GetGUID(name.c_str());
236 if(guid.size() == 0)
238 std::string m = "Target: ";
239 m += target.GetName();
240 m += " depends on unknown target: ";
241 m += name;
242 cmSystemTools::Error(m.c_str());
245 fout << "\t\t{" << guid << "} = {" << guid << "}\n";
250 //----------------------------------------------------------------------------
251 // Write a dsp file into the SLN file, Note, that dependencies from
252 // executables to the libraries it uses are also done here
253 void cmGlobalVisualStudio71Generator
254 ::WriteExternalProject(std::ostream& fout,
255 const char* name,
256 const char* location,
257 const std::set<cmStdString>& depends)
259 fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
260 << name << "\", \""
261 << this->ConvertToSolutionPath(location) << "\", \"{"
262 << this->GetGUID(name)
263 << "}\"\n";
265 // write out the dependencies here VS 7.1 includes dependencies with the
266 // project instead of in the global section
267 if(!depends.empty())
269 fout << "\tProjectSection(ProjectDependencies) = postProject\n";
270 std::set<cmStdString>::const_iterator it;
271 for(it = depends.begin(); it != depends.end(); ++it)
273 if(it->size() > 0)
275 fout << "\t\t{"
276 << this->GetGUID(it->c_str())
277 << "} = {"
278 << this->GetGUID(it->c_str())
279 << "}\n";
282 fout << "\tEndProjectSection\n";
285 fout << "EndProject\n";
290 //----------------------------------------------------------------------------
291 // Write a dsp file into the SLN file, Note, that dependencies from
292 // executables to the libraries it uses are also done here
293 void cmGlobalVisualStudio71Generator
294 ::WriteProjectConfigurations(std::ostream& fout, const char* name,
295 bool partOfDefaultBuild)
297 std::string guid = this->GetGUID(name);
298 for(std::vector<std::string>::iterator i = this->Configurations.begin();
299 i != this->Configurations.end(); ++i)
301 fout << "\t\t{" << guid << "}." << *i
302 << ".ActiveCfg = " << *i << "|Win32\n";
303 if(partOfDefaultBuild)
305 fout << "\t\t{" << guid << "}." << *i
306 << ".Build.0 = " << *i << "|Win32\n";
311 //----------------------------------------------------------------------------
312 // Standard end of dsw file
313 void cmGlobalVisualStudio71Generator::WriteSLNFooter(std::ostream& fout)
315 fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
316 << "\tEndGlobalSection\n"
317 << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
318 << "\tEndGlobalSection\n"
319 << "EndGlobal\n";
322 //----------------------------------------------------------------------------
323 // ouput standard header for dsw file
324 void cmGlobalVisualStudio71Generator::WriteSLNHeader(std::ostream& fout)
326 fout << "Microsoft Visual Studio Solution File, Format Version 8.00\n";
329 //----------------------------------------------------------------------------
330 void cmGlobalVisualStudio71Generator
331 ::GetDocumentation(cmDocumentationEntry& entry) const
333 entry.Name = this->GetName();
334 entry.Brief = "Generates Visual Studio .NET 2003 project files.";
335 entry.Full = "";