Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmGlobalVisualStudio8Generator.cxx
bloba6a46b88c98cce269bc7f42c8bf66cee731fe648
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio8Generator.cxx,v $
5 Language: C++
6 Date: $Date: 2008-04-01 21:39:04 $
7 Version: $Revision: 1.37 $
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 "cmGlobalVisualStudio8Generator.h"
19 #include "cmLocalVisualStudio7Generator.h"
20 #include "cmMakefile.h"
21 #include "cmake.h"
22 #include "cmGeneratedFileStream.h"
24 //----------------------------------------------------------------------------
25 cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
27 this->FindMakeProgramFile = "CMakeVS8FindMake.cmake";
28 this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
29 this->PlatformName = "Win32";
32 //----------------------------------------------------------------------------
33 ///! Create a local generator appropriate to this Global Generator
34 cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
36 cmLocalVisualStudio7Generator *lg = new cmLocalVisualStudio7Generator;
37 lg->SetVersion8();
38 lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
39 lg->SetGlobalGenerator(this);
40 return lg;
43 //----------------------------------------------------------------------------
44 // ouput standard header for dsw file
45 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
47 fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
48 fout << "# Visual Studio 2005\n";
51 //----------------------------------------------------------------------------
52 void cmGlobalVisualStudio8Generator
53 ::GetDocumentation(cmDocumentationEntry& entry) const
55 entry.Name = this->GetName();
56 entry.Brief = "Generates Visual Studio .NET 2005 project files.";
57 entry.Full = "";
60 //----------------------------------------------------------------------------
61 void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
63 mf->AddDefinition("MSVC80", "1");
66 //----------------------------------------------------------------------------
67 void cmGlobalVisualStudio8Generator::Configure()
69 this->cmGlobalVisualStudio7Generator::Configure();
70 this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
73 //----------------------------------------------------------------------------
74 std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
76 // Some VS8 sp0 versions cannot run macros.
77 // See http://support.microsoft.com/kb/928209
78 const char* vc8sp1Registry =
79 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
80 "InstalledProducts\\KB926601;";
81 const char* vc8exSP1Registry =
82 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
83 "InstalledProducts\\KB926748;";
84 std::string vc8sp1;
85 if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry, vc8sp1) &&
86 !cmSystemTools::ReadRegistryValue(vc8exSP1Registry, vc8sp1))
88 return "";
91 std::string base;
92 std::string path;
94 // base begins with the VisualStudioProjectsLocation reg value...
95 if (cmSystemTools::ReadRegistryValue(
96 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
97 "VisualStudioProjectsLocation",
98 base))
100 cmSystemTools::ConvertToUnixSlashes(base);
102 // 8.0 macros folder:
103 path = base + "/VSMacros80";
106 // path is (correctly) still empty if we did not read the base value from
107 // the Registry value
108 return path;
111 //----------------------------------------------------------------------------
112 std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
114 return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
117 //----------------------------------------------------------------------------
118 void cmGlobalVisualStudio8Generator::Generate()
120 // Add a special target on which all other targets depend that
121 // checks the build system and optionally re-runs CMake.
122 const char* no_working_directory = 0;
123 std::vector<std::string> no_depends;
124 std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
125 for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
127 std::vector<cmLocalGenerator*>& generators = it->second;
128 if(!generators.empty())
130 // Add the build-system check target to the first local
131 // generator of this project.
132 cmLocalVisualStudio7Generator* lg =
133 static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
134 cmMakefile* mf = lg->GetMakefile();
136 // Skip the target if no regeneration is to be done.
137 if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
139 continue;
142 std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
143 cmCustomCommandLines noCommandLines;
144 mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
145 no_working_directory, no_depends,
146 noCommandLines);
147 cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
148 if(!tgt)
150 cmSystemTools::Error("Error adding target "
151 CMAKE_CHECK_BUILD_SYSTEM_TARGET);
152 continue;
155 // Create a list of all stamp files for this project.
156 std::vector<std::string> stamps;
157 std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
158 stampList += "generate.stamp.list";
160 std::string stampListFile =
161 generators[0]->GetMakefile()->GetCurrentOutputDirectory();
162 stampListFile += "/";
163 stampListFile += stampList;
164 std::string stampFile;
165 cmGeneratedFileStream fout(stampListFile.c_str());
166 for(std::vector<cmLocalGenerator*>::const_iterator
167 gi = generators.begin(); gi != generators.end(); ++gi)
169 stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
170 stampFile += "/";
171 stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
172 stampFile += "generate.stamp";
173 stampFile = generators[0]->Convert(stampFile.c_str(),
174 cmLocalGenerator::START_OUTPUT);
175 fout << stampFile << "\n";
176 stamps.push_back(stampFile);
180 // Add a custom rule to re-run CMake if any input files changed.
182 // Collect the input files used to generate all targets in this
183 // project.
184 std::vector<std::string> listFiles;
185 for(unsigned int j = 0; j < generators.size(); ++j)
187 cmMakefile* lmf = generators[j]->GetMakefile();
188 listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
189 lmf->GetListFiles().end());
191 // Sort the list of input files and remove duplicates.
192 std::sort(listFiles.begin(), listFiles.end(),
193 std::less<std::string>());
194 std::vector<std::string>::iterator new_end =
195 std::unique(listFiles.begin(), listFiles.end());
196 listFiles.erase(new_end, listFiles.end());
198 // Create a rule to re-run CMake.
199 std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
200 stampName += "generate.stamp";
201 const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
202 cmCustomCommandLine commandLine;
203 commandLine.push_back(dsprule);
204 std::string argH = "-H";
205 argH += lg->Convert(mf->GetHomeDirectory(),
206 cmLocalGenerator::START_OUTPUT,
207 cmLocalGenerator::UNCHANGED, true);
208 commandLine.push_back(argH);
209 std::string argB = "-B";
210 argB += lg->Convert(mf->GetHomeOutputDirectory(),
211 cmLocalGenerator::START_OUTPUT,
212 cmLocalGenerator::UNCHANGED, true);
213 commandLine.push_back(argB);
214 commandLine.push_back("--check-stamp-list");
215 commandLine.push_back(stampList.c_str());
216 commandLine.push_back("--vs-solution-file");
217 commandLine.push_back("\"$(SolutionPath)\"");
218 cmCustomCommandLines commandLines;
219 commandLines.push_back(commandLine);
221 // Add the rule. Note that we cannot use the CMakeLists.txt
222 // file as the main dependency because it would get
223 // overwritten by the CreateVCProjBuildRule.
224 // (this could be avoided with per-target source files)
225 const char* no_main_dependency = 0;
226 const char* no_working_directory = 0;
227 mf->AddCustomCommandToOutput(
228 stamps, listFiles,
229 no_main_dependency, commandLines, "Checking Build System",
230 no_working_directory, true);
231 std::string ruleName = stamps[0];
232 ruleName += ".rule";
233 if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
235 tgt->AddSourceFile(file);
237 else
239 cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
245 // Now perform the main generation.
246 this->cmGlobalVisualStudio7Generator::Generate();
249 //----------------------------------------------------------------------------
250 void cmGlobalVisualStudio8Generator::WriteSLNFile(
251 std::ostream& fout, cmLocalGenerator* root,
252 std::vector<cmLocalGenerator*>& generators)
254 // Make all targets depend on their respective project's build
255 // system check target.
256 unsigned int i;
257 for(i = 0; i < generators.size(); ++i)
259 if(this->IsExcluded(root, generators[i]))
261 continue;
263 cmMakefile* mf = generators[i]->GetMakefile();
264 cmTargets& tgts = mf->GetTargets();
265 for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
267 if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
269 for(unsigned int j = 0; j < generators.size(); ++j)
271 // Every target in all generators should depend on this target.
272 cmMakefile* lmf = generators[j]->GetMakefile();
273 cmTargets &atgts = lmf->GetTargets();
274 for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al)
276 al->second.AddUtility(l->first.c_str());
283 // Now write the solution file.
284 this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators);
287 //----------------------------------------------------------------------------
288 void
289 cmGlobalVisualStudio8Generator
290 ::WriteSolutionConfigurations(std::ostream& fout)
292 fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
293 for(std::vector<std::string>::iterator i = this->Configurations.begin();
294 i != this->Configurations.end(); ++i)
296 fout << "\t\t" << *i << "|" << this->PlatformName << " = " << *i << "|"
297 << this->PlatformName << "\n";
299 fout << "\tEndGlobalSection\n";
302 //----------------------------------------------------------------------------
303 void
304 cmGlobalVisualStudio8Generator
305 ::WriteProjectConfigurations(std::ostream& fout, const char* name,
306 bool partOfDefaultBuild)
308 std::string guid = this->GetGUID(name);
309 for(std::vector<std::string>::iterator i = this->Configurations.begin();
310 i != this->Configurations.end(); ++i)
312 fout << "\t\t{" << guid << "}." << *i
313 << "|" << this->PlatformName << ".ActiveCfg = "
314 << *i << "|" << this->PlatformName << "\n";
315 if(partOfDefaultBuild)
317 fout << "\t\t{" << guid << "}." << *i
318 << "|" << this->PlatformName << ".Build.0 = "
319 << *i << "|" << this->PlatformName << "\n";
324 //----------------------------------------------------------------------------
325 static cmVS7FlagTable cmVS8ExtraFlagTable[] =
327 {"CallingConvention", "Gd", "cdecl", "0", 0 },
328 {"CallingConvention", "Gr", "fastcall", "1", 0 },
329 {"CallingConvention", "Gz", "stdcall", "2", 0 },
331 {"Detect64BitPortabilityProblems", "Wp64",
332 "Detect 64Bit Portability Problems", "true", 0 },
333 {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
334 {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
335 // Precompiled header and related options. Note that the
336 // UsePrecompiledHeader entries are marked as "Continue" so that the
337 // corresponding PrecompiledHeaderThrough entry can be found.
338 {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
339 cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
340 {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
341 cmVS7FlagTable::UserValueRequired},
342 // There is no YX option in the VS8 IDE.
344 // Exception handling mode. If no entries match, it will be FALSE.
345 {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
346 {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
347 {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
349 {0,0,0,0,0}
351 cmVS7FlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
353 return cmVS8ExtraFlagTable;