1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio71Generator.cxx,v $
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"
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
;
36 lg
->SetExtraFlagTable(this->GetExtraFlagTableVS7());
37 lg
->SetGlobalGenerator(this);
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
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...
68 // base begins with the VisualStudioProjectsLocation reg value...
69 if (cmSystemTools::ReadRegistryValue(
70 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\7.1;"
71 "VisualStudioProjectsLocation",
74 cmSystemTools::ConvertToUnixSlashes(base
);
77 path
= base
+ "/VSMacros71";
80 // path is (correctly) still empty if we did not read the base value from
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
96 return "Software\\Microsoft\\VisualStudio\\7.1\\vsmacros";
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
113 cmGlobalGenerator::TargetDependSet projectTargets
;
114 cmGlobalGenerator::TargetDependSet originalTargets
;
115 this->GetTargetSets(projectTargets
,
118 OrderedTargetDependSet
orderedProjectTargets(projectTargets
);
119 this->WriteTargetsToSolution(fout
, root
, orderedProjectTargets
,
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";
130 // Write the footer for the SLN file
131 this->WriteSLNFooter(fout
);
134 //----------------------------------------------------------------------------
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
153 cmGlobalVisualStudio71Generator::WriteProject(std::ostream
& fout
,
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
))
165 project
= "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
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
185 cmGlobalVisualStudio71Generator
186 ::WriteProjectDepends(std::ostream
& fout
,
188 const char*, cmTarget
& target
)
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
);
200 if (target
.GetType() != cmTarget::STATIC_LIBRARY
)
203 cmTarget::LinkLibraryVectorType::const_iterator j
, jend
;
204 j
= target
.GetLinkLibraries().begin();
205 jend
= target
.GetLinkLibraries().end();
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();
230 std::string name
= this->GetUtilityForTarget(target
, i
->c_str());
231 std::string guid
= this->GetGUID(name
.c_str());
234 std::string m
= "Target: ";
235 m
+= target
.GetName();
236 m
+= " depends on unknown target: ";
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
,
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}\") = \""
258 << this->ConvertToSolutionPath(location
) << "\", \"{"
259 << this->GetGUID(name
)
262 // write out the dependencies here VS 7.1 includes dependencies with the
263 // project instead of in the global section
266 fout
<< "\tProjectSection(ProjectDependencies) = postProject\n";
267 std::vector
<std::string
>::const_iterator it
;
268 for(it
= depends
.begin(); it
!= depends
.end(); ++it
)
273 << this->GetGUID(it
->c_str())
275 << this->GetGUID(it
->c_str())
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"
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.";