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 "cmGlobalVisualStudio8Generator.h"
14 #include "cmLocalVisualStudio7Generator.h"
15 #include "cmMakefile.h"
16 #include "cmVisualStudioWCEPlatformParser.h"
18 #include "cmGeneratedFileStream.h"
20 static const char vs8generatorName[] = "Visual Studio 8 2005";
22 class cmGlobalVisualStudio8Generator::Factory
23 : public cmGlobalGeneratorFactory
26 virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const {
27 if(strstr(name, vs8generatorName) != name)
32 const char* p = name + sizeof(vs8generatorName) - 1;
35 return new cmGlobalVisualStudio8Generator(
46 if(!strcmp(p, "Win64"))
48 return new cmGlobalVisualStudio8Generator(
49 name, "x64", "CMAKE_FORCE_WIN64");
52 cmVisualStudioWCEPlatformParser parser(p);
53 parser.ParseVersion("8.0");
59 cmGlobalVisualStudio8Generator* ret = new cmGlobalVisualStudio8Generator(
61 ret->WindowsCEVersion = parser.GetOSVersion();
65 virtual void GetDocumentation(cmDocumentationEntry& entry) const {
66 entry.Name = vs8generatorName;
67 entry.Brief = "Generates Visual Studio 8 2005 project files.";
69 "It is possible to append a space followed by the platform name "
70 "to create project files for a specific target platform. E.g. "
71 "\"Visual Studio 8 2005 Win64\" will create project files for "
75 virtual void GetGenerators(std::vector<std::string>& names) const {
76 names.push_back(vs8generatorName);
77 names.push_back(vs8generatorName + std::string(" Win64"));
78 cmVisualStudioWCEPlatformParser parser;
79 parser.ParseVersion("8.0");
80 const std::vector<std::string>& availablePlatforms =
81 parser.GetAvailablePlatforms();
82 for(std::vector<std::string>::const_iterator i =
83 availablePlatforms.begin(); i != availablePlatforms.end(); ++i)
85 names.push_back("Visual Studio 8 2005 " + *i);
90 //----------------------------------------------------------------------------
91 cmGlobalGeneratorFactory* cmGlobalVisualStudio8Generator::NewFactory()
96 //----------------------------------------------------------------------------
97 cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator(
98 const char* name, const char* platformName,
99 const char* additionalPlatformDefinition)
100 : cmGlobalVisualStudio71Generator(platformName)
102 this->FindMakeProgramFile = "CMakeVS8FindMake.cmake";
103 this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
106 if (additionalPlatformDefinition)
108 this->AdditionalPlatformDefinition = additionalPlatformDefinition;
112 //----------------------------------------------------------------------------
113 ///! Create a local generator appropriate to this Global Generator
114 cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator()
116 cmLocalVisualStudio7Generator *lg =
117 new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS8);
118 lg->SetPlatformName(this->GetPlatformName());
119 lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
120 lg->SetGlobalGenerator(this);
124 //----------------------------------------------------------------------------
125 void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
127 cmGlobalVisualStudio71Generator::AddPlatformDefinitions(mf);
129 if(this->TargetsWindowsCE())
131 mf->AddDefinition("CMAKE_VS_WINCE_VERSION",
132 this->WindowsCEVersion.c_str());
136 //----------------------------------------------------------------------------
137 // ouput standard header for dsw file
138 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream& fout)
140 fout << "Microsoft Visual Studio Solution File, Format Version 9.00\n";
141 fout << "# Visual Studio 2005\n";
144 //----------------------------------------------------------------------------
145 void cmGlobalVisualStudio8Generator
146 ::GetDocumentation(cmDocumentationEntry& entry)
148 entry.Name = cmGlobalVisualStudio8Generator::GetActualName();
149 entry.Brief = "Generates Visual Studio 8 2005 project files.";
153 //----------------------------------------------------------------------------
154 void cmGlobalVisualStudio8Generator::Configure()
156 this->cmGlobalVisualStudio7Generator::Configure();
157 this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
160 //----------------------------------------------------------------------------
161 std::string cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
163 // Some VS8 sp0 versions cannot run macros.
164 // See http://support.microsoft.com/kb/928209
165 const char* vc8sp1Registry =
166 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
167 "InstalledProducts\\KB926601;";
168 const char* vc8exSP1Registry =
169 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
170 "InstalledProducts\\KB926748;";
172 if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry, vc8sp1) &&
173 !cmSystemTools::ReadRegistryValue(vc8exSP1Registry, vc8sp1))
181 // base begins with the VisualStudioProjectsLocation reg value...
182 if (cmSystemTools::ReadRegistryValue(
183 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
184 "VisualStudioProjectsLocation",
187 cmSystemTools::ConvertToUnixSlashes(base);
189 // 8.0 macros folder:
190 path = base + "/VSMacros80";
193 // path is (correctly) still empty if we did not read the base value from
194 // the Registry value
198 //----------------------------------------------------------------------------
199 std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
201 return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
204 //----------------------------------------------------------------------------
205 void cmGlobalVisualStudio8Generator::AddCheckTarget()
207 // Add a special target on which all other targets depend that
208 // checks the build system and optionally re-runs CMake.
209 const char* no_working_directory = 0;
210 std::vector<std::string> no_depends;
211 std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
212 cmLocalVisualStudio7Generator* lg =
213 static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
214 cmMakefile* mf = lg->GetMakefile();
216 // Skip the target if no regeneration is to be done.
217 if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
222 std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
223 cmCustomCommandLines noCommandLines;
225 mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
226 no_working_directory, no_depends,
229 // Organize in the "predefined targets" folder:
231 if (this->UseFolderProperty())
233 tgt->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
236 // Create a list of all stamp files for this project.
237 std::vector<std::string> stamps;
238 std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
239 stampList += "generate.stamp.list";
241 std::string stampListFile =
242 generators[0]->GetMakefile()->GetCurrentOutputDirectory();
243 stampListFile += "/";
244 stampListFile += stampList;
245 std::string stampFile;
246 cmGeneratedFileStream fout(stampListFile.c_str());
247 for(std::vector<cmLocalGenerator*>::const_iterator
248 gi = generators.begin(); gi != generators.end(); ++gi)
250 stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
252 stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
253 stampFile += "generate.stamp";
254 fout << stampFile << "\n";
255 stamps.push_back(stampFile);
259 // Add a custom rule to re-run CMake if any input files changed.
261 // Collect the input files used to generate all targets in this
263 std::vector<std::string> listFiles;
264 for(unsigned int j = 0; j < generators.size(); ++j)
266 cmMakefile* lmf = generators[j]->GetMakefile();
267 listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
268 lmf->GetListFiles().end());
270 // Sort the list of input files and remove duplicates.
271 std::sort(listFiles.begin(), listFiles.end(),
272 std::less<std::string>());
273 std::vector<std::string>::iterator new_end =
274 std::unique(listFiles.begin(), listFiles.end());
275 listFiles.erase(new_end, listFiles.end());
277 // Create a rule to re-run CMake.
278 std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
279 stampName += "generate.stamp";
280 const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
281 cmCustomCommandLine commandLine;
282 commandLine.push_back(dsprule);
283 std::string argH = "-H";
284 argH += lg->Convert(mf->GetHomeDirectory(),
285 cmLocalGenerator::START_OUTPUT,
286 cmLocalGenerator::UNCHANGED, true);
287 commandLine.push_back(argH);
288 std::string argB = "-B";
289 argB += lg->Convert(mf->GetHomeOutputDirectory(),
290 cmLocalGenerator::START_OUTPUT,
291 cmLocalGenerator::UNCHANGED, true);
292 commandLine.push_back(argB);
293 commandLine.push_back("--check-stamp-list");
294 commandLine.push_back(stampList.c_str());
295 commandLine.push_back("--vs-solution-file");
296 commandLine.push_back("\"$(SolutionPath)\"");
297 cmCustomCommandLines commandLines;
298 commandLines.push_back(commandLine);
300 // Add the rule. Note that we cannot use the CMakeLists.txt
301 // file as the main dependency because it would get
302 // overwritten by the CreateVCProjBuildRule.
303 // (this could be avoided with per-target source files)
304 const char* no_main_dependency = 0;
305 if(cmSourceFile* file =
306 mf->AddCustomCommandToOutput(
308 no_main_dependency, commandLines, "Checking Build System",
309 no_working_directory, true))
311 tgt->AddSourceFile(file);
315 cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
320 //----------------------------------------------------------------------------
321 void cmGlobalVisualStudio8Generator::Generate()
323 this->AddCheckTarget();
325 // All targets depend on the build-system check target.
326 for(std::map<cmStdString,cmTarget *>::const_iterator
327 ti = this->TotalTargets.begin();
328 ti != this->TotalTargets.end(); ++ti)
330 if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
332 ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
336 // Now perform the main generation.
337 this->cmGlobalVisualStudio7Generator::Generate();
340 //----------------------------------------------------------------------------
342 cmGlobalVisualStudio8Generator
343 ::WriteSolutionConfigurations(std::ostream& fout)
345 fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
346 for(std::vector<std::string>::iterator i = this->Configurations.begin();
347 i != this->Configurations.end(); ++i)
349 fout << "\t\t" << *i << "|" << this->GetPlatformName()
350 << " = " << *i << "|" << this->GetPlatformName() << "\n";
352 fout << "\tEndGlobalSection\n";
355 //----------------------------------------------------------------------------
357 cmGlobalVisualStudio8Generator
358 ::WriteProjectConfigurations(
359 std::ostream& fout, const char* name, cmTarget::TargetType type,
360 const std::set<std::string>& configsPartOfDefaultBuild,
361 const char* platformMapping)
363 std::string guid = this->GetGUID(name);
364 for(std::vector<std::string>::iterator i = this->Configurations.begin();
365 i != this->Configurations.end(); ++i)
367 fout << "\t\t{" << guid << "}." << *i
368 << "|" << this->GetPlatformName() << ".ActiveCfg = " << *i << "|"
369 << (platformMapping ? platformMapping : this->GetPlatformName())
371 std::set<std::string>::const_iterator
372 ci = configsPartOfDefaultBuild.find(*i);
373 if(!(ci == configsPartOfDefaultBuild.end()))
375 fout << "\t\t{" << guid << "}." << *i
376 << "|" << this->GetPlatformName() << ".Build.0 = " << *i << "|"
377 << (platformMapping ? platformMapping : this->GetPlatformName())
380 bool needsDeploy = (type == cmTarget::EXECUTABLE ||
381 type == cmTarget::SHARED_LIBRARY);
382 if(this->TargetsWindowsCE() && needsDeploy)
384 fout << "\t\t{" << guid << "}." << *i
385 << "|" << this->GetPlatformName() << ".Deploy.0 = " << *i << "|"
386 << (platformMapping ? platformMapping : this->GetPlatformName())
392 //----------------------------------------------------------------------------
393 bool cmGlobalVisualStudio8Generator::ComputeTargetDepends()
395 // Skip over the cmGlobalVisualStudioGenerator implementation!
396 // We do not need the support that VS <= 7.1 needs.
397 return this->cmGlobalGenerator::ComputeTargetDepends();
400 //----------------------------------------------------------------------------
401 void cmGlobalVisualStudio8Generator::WriteProjectDepends(
402 std::ostream& fout, const char*, const char*, cmTarget& t)
404 TargetDependSet const& unordered = this->GetTargetDirectDepends(t);
405 OrderedTargetDependSet depends(unordered);
406 for(OrderedTargetDependSet::const_iterator i = depends.begin();
407 i != depends.end(); ++i)
409 std::string guid = this->GetGUID((*i)->GetName());
410 fout << "\t\t{" << guid << "} = {" << guid << "}\n";
414 //----------------------------------------------------------------------------
415 bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
418 // Look for utility dependencies that magically link.
419 for(std::set<cmStdString>::const_iterator ui =
420 target.GetUtilities().begin();
421 ui != target.GetUtilities().end(); ++ui)
423 if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
425 if(depTarget->GetProperty("EXTERNAL_MSPROJECT"))
427 // This utility dependency names an external .vcproj target.
428 // We use LinkLibraryDependencies="true" to link to it without
429 // predicting the .lib file location or name.
437 //----------------------------------------------------------------------------
438 static cmVS7FlagTable cmVS8ExtraFlagTable[] =
440 {"CallingConvention", "Gd", "cdecl", "0", 0 },
441 {"CallingConvention", "Gr", "fastcall", "1", 0 },
442 {"CallingConvention", "Gz", "stdcall", "2", 0 },
444 {"Detect64BitPortabilityProblems", "Wp64",
445 "Detect 64Bit Portability Problems", "true", 0 },
446 {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
447 {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
448 // Precompiled header and related options. Note that the
449 // UsePrecompiledHeader entries are marked as "Continue" so that the
450 // corresponding PrecompiledHeaderThrough entry can be found.
451 {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
452 cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue},
453 {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
454 cmVS7FlagTable::UserValueRequired},
455 // There is no YX option in the VS8 IDE.
457 // Exception handling mode. If no entries match, it will be FALSE.
458 {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
459 {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
460 {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
462 {"EnablePREfast", "analyze", "", "true", 0},
463 {"EnablePREfast", "analyze-", "", "false", 0},
466 {"TreatWChar_tAsBuiltInType", "Zc:wchar_t",
467 "wchar_t is a built-in type", "true", 0},
468 {"TreatWChar_tAsBuiltInType", "Zc:wchar_t-",
469 "wchar_t is not a built-in type", "false", 0},
473 cmIDEFlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
475 return cmVS8ExtraFlagTable;