f7f7317cdb9f0037d0cd379e1f539e9f9d532580
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio7Generator.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #include "cmGlobalVisualStudio7Generator.h"
4
5 #include <algorithm>
6 #include <cstdio>
7 #include <ostream>
8 #include <utility>
9 #include <vector>
10
11 #include <cm/memory>
12 #include <cm/string_view>
13
14 #include <windows.h>
15
16 #include "cmGeneratedFileStream.h"
17 #include "cmGeneratorExpression.h"
18 #include "cmGeneratorTarget.h"
19 #include "cmGlobalGenerator.h"
20 #include "cmLocalGenerator.h"
21 #include "cmLocalVisualStudio7Generator.h"
22 #include "cmMakefile.h"
23 #include "cmMessageType.h"
24 #include "cmState.h"
25 #include "cmStateTypes.h"
26 #include "cmStringAlgorithms.h"
27 #include "cmSystemTools.h"
28 #include "cmTarget.h"
29 #include "cmTargetDepend.h"
30 #include "cmUuid.h"
31 #include "cmVisualStudioGeneratorOptions.h"
32 #include "cmake.h"
33
34 static cmVS7FlagTable cmVS7ExtraFlagTable[] = {
35   // Precompiled header and related options.  Note that the
36   // UsePrecompiledHeader entries are marked as "Continue" so that the
37   // corresponding PrecompiledHeaderThrough entry can be found.
38   { "UsePrecompiledHeader", "YX", "Automatically Generate", "2",
39     cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
40   { "PrecompiledHeaderThrough", "YX", "Precompiled Header Name", "",
41     cmVS7FlagTable::UserValueRequired },
42   { "UsePrecompiledHeader", "Yu", "Use Precompiled Header", "3",
43     cmVS7FlagTable::UserValueIgnored | cmVS7FlagTable::Continue },
44   { "PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
45     cmVS7FlagTable::UserValueRequired },
46   { "UsePrecompiledHeader", "Y-", "Don't use precompiled header", "0", 0 },
47   { "WholeProgramOptimization", "LTCG", "WholeProgramOptimization", "true",
48     0 },
49
50   // Exception handling mode.  If no entries match, it will be FALSE.
51   { "ExceptionHandling", "GX", "enable c++ exceptions", "true", 0 },
52   { "ExceptionHandling", "EHsc", "enable c++ exceptions", "true", 0 },
53   // The EHa option does not have an IDE setting.  Let it go to false,
54   // and have EHa passed on the command line by leaving out the table
55   // entry.
56
57   { "", "", "", "", 0 }
58 };
59
60 namespace {
61 std::string GetSLNFile(cmLocalGenerator* root)
62 {
63   return cmStrCat(root->GetCurrentBinaryDirectory(), '/',
64                   root->GetProjectName(), ".sln");
65 }
66 }
67
68 cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(
69   cmake* cm, std::string const& platformInGeneratorName)
70   : cmGlobalVisualStudioGenerator(cm, platformInGeneratorName)
71 {
72   this->DevEnvCommandInitialized = false;
73   this->MasmEnabled = false;
74   this->NasmEnabled = false;
75   this->ExtraFlagTable = cmVS7ExtraFlagTable;
76 }
77
78 cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator()
79 {
80 }
81
82 // Package GUID of Intel Visual Fortran plugin to VS IDE
83 #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}"
84
85 const std::string& cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
86 {
87   if (this->IntelProjectVersion.empty()) {
88     // Compute the version of the Intel plugin to the VS IDE.
89     // If the key does not exist then use a default guess.
90     std::string intelVersion;
91     std::string vskey =
92       cmStrCat(this->GetRegistryBase(),
93                "\\Packages\\" CM_INTEL_PLUGIN_GUID ";ProductVersion");
94     cmSystemTools::ReadRegistryValue(vskey, intelVersion,
95                                      cmSystemTools::KeyWOW64_32);
96     unsigned int intelVersionNumber = ~0u;
97     sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
98     if (intelVersionNumber >= 11) {
99       // Default to latest known project file version.
100       intelVersion = "11.0";
101     } else if (intelVersionNumber == 10) {
102       // Version 10.x actually uses 9.10 in project files!
103       intelVersion = "9.10";
104     } else {
105       // Version <= 9: use ProductVersion from registry.
106     }
107     this->IntelProjectVersion = intelVersion;
108   }
109   return this->IntelProjectVersion;
110 }
111
112 void cmGlobalVisualStudio7Generator::EnableLanguage(
113   std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
114 {
115   mf->AddDefinition("CMAKE_GENERATOR_RC", "rc");
116   mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
117   mf->InitCMAKE_CONFIGURATION_TYPES("Debug;Release;MinSizeRel;RelWithDebInfo");
118
119   // Create list of configurations requested by user's cache, if any.
120   this->cmGlobalVisualStudioGenerator::EnableLanguage(lang, mf, optional);
121
122   // if this environment variable is set, then copy it to
123   // a static cache entry.  It will be used by
124   // cmLocalGenerator::ConstructScript, to add an extra PATH
125   // to all custom commands.   This is because the VS IDE
126   // does not use the environment it is run in, and this allows
127   // for running commands and using dll's that the IDE environment
128   // does not know about.
129   std::string extraPath;
130   if (cmSystemTools::GetEnv("CMAKE_MSVCIDE_RUN_PATH", extraPath)) {
131     mf->AddCacheDefinition("CMAKE_MSVCIDE_RUN_PATH", extraPath,
132                            "Saved environment variable CMAKE_MSVCIDE_RUN_PATH",
133                            cmStateEnums::STATIC);
134   }
135 }
136
137 bool cmGlobalVisualStudio7Generator::FindMakeProgram(cmMakefile* mf)
138 {
139   if (!this->cmGlobalVisualStudioGenerator::FindMakeProgram(mf)) {
140     return false;
141   }
142   mf->AddDefinition("CMAKE_VS_DEVENV_COMMAND", this->GetDevEnvCommand());
143   return true;
144 }
145
146 std::string const& cmGlobalVisualStudio7Generator::GetDevEnvCommand()
147 {
148   if (!this->DevEnvCommandInitialized) {
149     this->DevEnvCommandInitialized = true;
150     this->DevEnvCommand = this->FindDevEnvCommand();
151   }
152   return this->DevEnvCommand;
153 }
154
155 std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand()
156 {
157   std::string vscmd;
158   std::string vskey;
159
160   // Search in standard location.
161   vskey = this->GetRegistryBase() + ";InstallDir";
162   if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
163                                        cmSystemTools::KeyWOW64_32)) {
164     cmSystemTools::ConvertToUnixSlashes(vscmd);
165     vscmd += "/devenv.com";
166     if (cmSystemTools::FileExists(vscmd, true)) {
167       return vscmd;
168     }
169   }
170
171   // Search where VS15Preview places it.
172   vskey = cmStrCat(
173     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;",
174     this->GetIDEVersion());
175   if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd,
176                                        cmSystemTools::KeyWOW64_32)) {
177     cmSystemTools::ConvertToUnixSlashes(vscmd);
178     vscmd += "/Common7/IDE/devenv.com";
179     if (cmSystemTools::FileExists(vscmd, true)) {
180       return vscmd;
181     }
182   }
183
184   vscmd = "devenv.com";
185   return vscmd;
186 }
187
188 const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
189   const std::string& location)
190 {
191   std::string extension = cmSystemTools::GetFilenameLastExtension(location);
192   if (extension == ".vbproj") {
193     return "F184B08F-C81C-45F6-A57F-5ABD9991F28F";
194   } else if (extension == ".csproj") {
195     return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
196   } else if (extension == ".fsproj") {
197     return "F2A71F9B-5D33-465A-A702-920D77279786";
198   } else if (extension == ".vdproj") {
199     return "54435603-DBB4-11D2-8724-00A0C9A8B90C";
200   } else if (extension == ".dbproj") {
201     return "C8D11400-126E-41CD-887F-60BD40844F9E";
202   } else if (extension == ".wixproj") {
203     return "930C7802-8A8C-48F9-8165-68863BCCD9DD";
204   } else if (extension == ".pyproj") {
205     return "888888A0-9F3D-457C-B088-3A5042F75D52";
206   }
207   return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
208 }
209
210 std::vector<cmGlobalGenerator::GeneratedMakeCommand>
211 cmGlobalVisualStudio7Generator::GenerateBuildCommand(
212   const std::string& makeProgram, const std::string& projectName,
213   const std::string& /*projectDir*/,
214   std::vector<std::string> const& targetNames, const std::string& config,
215   int /*jobs*/, bool /*verbose*/, const cmBuildOptions& /*buildOptions*/,
216   std::vector<std::string> const& makeOptions)
217 {
218   // Select the caller- or user-preferred make program, else devenv.
219   std::string makeProgramSelected =
220     this->SelectMakeProgram(makeProgram, this->GetDevEnvCommand());
221
222   // Ignore the above preference if it is msbuild.
223   // Assume any other value is either a devenv or
224   // command-line compatible with devenv.
225   std::string makeProgramLower = makeProgramSelected;
226   cmSystemTools::LowerCase(makeProgramLower);
227   if (makeProgramLower.find("msbuild") != std::string::npos) {
228     makeProgramSelected = this->GetDevEnvCommand();
229   }
230
231   // Workaround to convince VCExpress.exe to produce output.
232   const bool requiresOutputForward =
233     (makeProgramLower.find("vcexpress") != std::string::npos);
234   std::vector<GeneratedMakeCommand> makeCommands;
235
236   std::vector<std::string> realTargetNames = targetNames;
237   if (targetNames.empty() ||
238       ((targetNames.size() == 1) && targetNames.front().empty())) {
239     realTargetNames = { "ALL_BUILD" };
240   }
241   for (const auto& tname : realTargetNames) {
242     std::string realTarget;
243     if (!tname.empty()) {
244       realTarget = tname;
245     } else {
246       continue;
247     }
248     bool clean = false;
249     if (realTarget == "clean") {
250       clean = true;
251       realTarget = "ALL_BUILD";
252     }
253     GeneratedMakeCommand makeCommand;
254     makeCommand.RequiresOutputForward = requiresOutputForward;
255     makeCommand.Add(makeProgramSelected);
256     makeCommand.Add(projectName + ".sln");
257     makeCommand.Add((clean ? "/clean" : "/build"));
258     makeCommand.Add((config.empty() ? "Debug" : config));
259     makeCommand.Add("/project");
260     makeCommand.Add(realTarget);
261     makeCommand.Add(makeOptions.begin(), makeOptions.end());
262     makeCommands.emplace_back(std::move(makeCommand));
263   }
264   return makeCommands;
265 }
266
267 //! Create a local generator appropriate to this Global Generator
268 std::unique_ptr<cmLocalGenerator>
269 cmGlobalVisualStudio7Generator::CreateLocalGenerator(cmMakefile* mf)
270 {
271   auto lg = cm::make_unique<cmLocalVisualStudio7Generator>(this, mf);
272   return std::unique_ptr<cmLocalGenerator>(std::move(lg));
273 }
274
275 #if !defined(CMAKE_BOOTSTRAP)
276 Json::Value cmGlobalVisualStudio7Generator::GetJson() const
277 {
278   Json::Value generator = this->cmGlobalVisualStudioGenerator::GetJson();
279   generator["platform"] = this->GetPlatformName();
280   return generator;
281 }
282 #endif
283
284 bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
285                                                    cmMakefile* mf)
286 {
287   mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
288                     this->GetIntelProjectVersion());
289   return this->cmGlobalVisualStudioGenerator::SetSystemName(s, mf);
290 }
291
292 void cmGlobalVisualStudio7Generator::Generate()
293 {
294   // first do the superclass method
295   this->cmGlobalVisualStudioGenerator::Generate();
296
297   // Now write out the DSW
298   this->OutputSLNFile();
299   // If any solution or project files changed during the generation,
300   // tell Visual Studio to reload them...
301   if (!cmSystemTools::GetErrorOccurredFlag() &&
302       !this->LocalGenerators.empty()) {
303     this->CallVisualStudioMacro(MacroReload,
304                                 GetSLNFile(this->LocalGenerators[0].get()));
305   }
306
307   if (this->Version == VSVersion::VS10 &&
308       !this->CMakeInstance->GetIsInTryCompile()) {
309     std::string cmakeWarnVS10;
310     if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue(
311           "CMAKE_WARN_VS10")) {
312       this->CMakeInstance->MarkCliAsUsed("CMAKE_WARN_VS10");
313       cmakeWarnVS10 = *cached;
314     } else {
315       cmSystemTools::GetEnv("CMAKE_WARN_VS10", cmakeWarnVS10);
316     }
317     if (cmakeWarnVS10.empty() || !cmIsOff(cmakeWarnVS10)) {
318       this->CMakeInstance->IssueMessage(
319         MessageType::WARNING,
320         "The \"Visual Studio 10 2010\" generator is deprecated "
321         "and will be removed in a future version of CMake."
322         "\n"
323         "Add CMAKE_WARN_VS10=OFF to the cache to disable this warning.");
324     }
325   }
326 }
327
328 void cmGlobalVisualStudio7Generator::OutputSLNFile(
329   cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
330 {
331   if (generators.empty()) {
332     return;
333   }
334   this->CurrentProject = root->GetProjectName();
335   std::string fname = GetSLNFile(root);
336   cmGeneratedFileStream fout(fname.c_str());
337   fout.SetCopyIfDifferent(true);
338   if (!fout) {
339     return;
340   }
341   this->WriteSLNFile(fout, root, generators);
342   if (fout.Close()) {
343     this->FileReplacedDuringGenerate(fname);
344   }
345 }
346
347 // output the SLN file
348 void cmGlobalVisualStudio7Generator::OutputSLNFile()
349 {
350   for (auto& it : this->ProjectMap) {
351     this->OutputSLNFile(it.second[0], it.second);
352   }
353 }
354
355 void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
356   std::ostream& fout, std::vector<std::string> const& configs,
357   OrderedTargetDependSet const& projectTargets)
358 {
359   // loop over again and write out configurations for each target
360   // in the solution
361   for (cmGeneratorTarget const* target : projectTargets) {
362     if (!this->IsInSolution(target)) {
363       continue;
364     }
365     cmValue expath = target->GetProperty("EXTERNAL_MSPROJECT");
366     if (expath) {
367       std::set<std::string> allConfigurations(configs.begin(), configs.end());
368       cmValue mapping = target->GetProperty("VS_PLATFORM_MAPPING");
369       this->WriteProjectConfigurations(fout, target->GetName(), *target,
370                                        configs, allConfigurations,
371                                        mapping ? *mapping : "");
372     } else {
373       const std::set<std::string>& configsPartOfDefaultBuild =
374         this->IsPartOfDefaultBuild(configs, projectTargets, target);
375       cmValue vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
376       if (vcprojName) {
377         std::string mapping;
378
379         // On VS 19 and above, always map .NET SDK projects to "Any CPU".
380         if (target->IsDotNetSdkTarget() &&
381             this->GetVersion() >= VSVersion::VS16 &&
382             !this->IsReservedTarget(target->GetName())) {
383           mapping = "Any CPU";
384         }
385         this->WriteProjectConfigurations(fout, *vcprojName, *target, configs,
386                                          configsPartOfDefaultBuild, mapping);
387       }
388     }
389   }
390 }
391
392 void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
393   std::ostream& fout, cmLocalGenerator* root,
394   OrderedTargetDependSet const& projectTargets)
395 {
396   VisualStudioFolders.clear();
397
398   for (cmGeneratorTarget const* target : projectTargets) {
399     if (!this->IsInSolution(target)) {
400       continue;
401     }
402     bool written = false;
403
404     // handle external vc project files
405     cmValue expath = target->GetProperty("EXTERNAL_MSPROJECT");
406     if (expath) {
407       std::string project = target->GetName();
408       std::string location = *expath;
409
410       this->WriteExternalProject(fout, project, location,
411                                  target->GetProperty("VS_PROJECT_TYPE"),
412                                  target->GetUtilities());
413       written = true;
414     } else {
415       cmValue vcprojName = target->GetProperty("GENERATOR_FILE_NAME");
416       if (vcprojName) {
417         cmLocalGenerator* lg = target->GetLocalGenerator();
418         std::string dir = lg->GetCurrentBinaryDirectory();
419         dir = root->MaybeRelativeToCurBinDir(dir);
420         if (dir == ".") {
421           dir.clear(); // msbuild cannot handle ".\" prefix
422         }
423         this->WriteProject(fout, *vcprojName, dir, target);
424         written = true;
425       }
426     }
427
428     // Create "solution folder" information from FOLDER target property
429     //
430     if (written && this->UseFolderProperty()) {
431       const std::string targetFolder = target->GetEffectiveFolderName();
432       if (!targetFolder.empty()) {
433         std::vector<std::string> tokens =
434           cmSystemTools::SplitString(targetFolder, '/', false);
435
436         std::string cumulativePath;
437
438         for (std::string const& iter : tokens) {
439           if (!iter.size()) {
440             continue;
441           }
442
443           if (cumulativePath.empty()) {
444             cumulativePath = "CMAKE_FOLDER_GUID_" + iter;
445           } else {
446             VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
447                                                        iter);
448
449             cumulativePath = cumulativePath + "/" + iter;
450           }
451         }
452
453         if (!cumulativePath.empty()) {
454           VisualStudioFolders[cumulativePath].insert(target->GetName());
455         }
456       }
457     }
458   }
459 }
460
461 void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
462 {
463   cm::string_view const prefix = "CMAKE_FOLDER_GUID_";
464   std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8";
465   for (auto const& iter : VisualStudioFolders) {
466     std::string fullName = iter.first;
467     std::string guid = this->GetGUID(fullName);
468
469     std::replace(fullName.begin(), fullName.end(), '/', '\\');
470     if (cmHasPrefix(fullName, prefix)) {
471       fullName = fullName.substr(prefix.size());
472     }
473
474     std::string nameOnly = cmSystemTools::GetFilenameName(fullName);
475
476     fout << "Project(\"{" << guidProjectTypeFolder << "}\") = \"" << nameOnly
477          << "\", \"" << fullName << "\", \"{" << guid << "}\"\nEndProject\n";
478   }
479 }
480
481 void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout)
482 {
483   for (auto const& iter : VisualStudioFolders) {
484     std::string key(iter.first);
485     std::string guidParent(this->GetGUID(key));
486
487     for (std::string const& it : iter.second) {
488       std::string value(it);
489       std::string guid(this->GetGUID(value));
490
491       fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
492     }
493   }
494 }
495
496 std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(
497   const std::string& path)
498 {
499   // Convert to backslashes.  Do not use ConvertToOutputPath because
500   // we will add quoting ourselves, and we know these projects always
501   // use windows slashes.
502   std::string d = path;
503   std::string::size_type pos = 0;
504   while ((pos = d.find('/', pos)) != d.npos) {
505     d[pos++] = '\\';
506   }
507   return d;
508 }
509
510 void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
511   std::ostream& fout, cmLocalGenerator* root)
512 {
513   std::string const guid = this->GetGUID(root->GetProjectName() + ".sln");
514   bool extensibilityGlobalsOverridden = false;
515   bool extensibilityAddInsOverridden = false;
516   const std::vector<std::string> propKeys =
517     root->GetMakefile()->GetPropertyKeys();
518   for (std::string const& it : propKeys) {
519     if (cmHasLiteralPrefix(it, "VS_GLOBAL_SECTION_")) {
520       std::string sectionType;
521       std::string name = it.substr(18);
522       if (cmHasLiteralPrefix(name, "PRE_")) {
523         name = name.substr(4);
524         sectionType = "preSolution";
525       } else if (cmHasLiteralPrefix(name, "POST_")) {
526         name = name.substr(5);
527         sectionType = "postSolution";
528       } else
529         continue;
530       if (!name.empty()) {
531         bool addGuid = false;
532         if (name == "ExtensibilityGlobals" && sectionType == "postSolution") {
533           addGuid = true;
534           extensibilityGlobalsOverridden = true;
535         } else if (name == "ExtensibilityAddIns" &&
536                    sectionType == "postSolution") {
537           extensibilityAddInsOverridden = true;
538         }
539         fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
540         cmValue p = root->GetMakefile()->GetProperty(it);
541         std::vector<std::string> keyValuePairs = cmExpandedList(p ? *p : "");
542         for (std::string const& itPair : keyValuePairs) {
543           const std::string::size_type posEqual = itPair.find('=');
544           if (posEqual != std::string::npos) {
545             const std::string key =
546               cmTrimWhitespace(itPair.substr(0, posEqual));
547             const std::string value =
548               cmTrimWhitespace(itPair.substr(posEqual + 1));
549             fout << "\t\t" << key << " = " << value << "\n";
550             if (key == "SolutionGuid") {
551               addGuid = false;
552             }
553           }
554         }
555         if (addGuid) {
556           fout << "\t\tSolutionGuid = {" << guid << "}\n";
557         }
558         fout << "\tEndGlobalSection\n";
559       }
560     }
561   }
562   if (!extensibilityGlobalsOverridden) {
563     fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n"
564          << "\t\tSolutionGuid = {" << guid << "}\n"
565          << "\tEndGlobalSection\n";
566   }
567   if (!extensibilityAddInsOverridden)
568     fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n"
569          << "\tEndGlobalSection\n";
570 }
571
572 // Standard end of dsw file
573 void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout)
574 {
575   fout << "EndGlobal\n";
576 }
577
578 std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
579   cmGeneratorTarget const* target)
580 {
581   std::vector<std::string> configs =
582     target->Target->GetMakefile()->GetGeneratorConfigs(
583       cmMakefile::ExcludeEmptyConfig);
584   std::string pname = cmStrCat(target->GetName(), "_UTILITY");
585   std::string fname =
586     cmStrCat(target->GetLocalGenerator()->GetCurrentBinaryDirectory(), '/',
587              pname, ".vcproj");
588   cmGeneratedFileStream fout(fname.c_str());
589   fout.SetCopyIfDifferent(true);
590   std::string guid = this->GetGUID(pname.c_str());
591
592   /* clang-format off */
593   fout <<
594     "<?xml version=\"1.0\" encoding = \""
595     << this->Encoding() << "\"?>\n"
596     "<VisualStudioProject\n"
597     "\tProjectType=\"Visual C++\"\n"
598     "\tVersion=\"" << this->GetIDEVersion() << "0\"\n"
599     "\tName=\"" << pname << "\"\n"
600     "\tProjectGUID=\"{" << guid << "}\"\n"
601     "\tKeyword=\"Win32Proj\">\n"
602     "\t<Platforms><Platform Name=\"Win32\"/></Platforms>\n"
603     "\t<Configurations>\n"
604     ;
605   /* clang-format on */
606   for (std::string const& i : configs) {
607     /* clang-format off */
608     fout <<
609       "\t\t<Configuration\n"
610       "\t\t\tName=\"" << i << "|Win32\"\n"
611       "\t\t\tOutputDirectory=\"" << i << "\"\n"
612       "\t\t\tIntermediateDirectory=\"" << pname << ".dir\\" << i << "\"\n"
613       "\t\t\tConfigurationType=\"10\"\n"
614       "\t\t\tUseOfMFC=\"0\"\n"
615       "\t\t\tATLMinimizesCRunTimeLibraryUsage=\"FALSE\"\n"
616       "\t\t\tCharacterSet=\"2\">\n"
617       "\t\t</Configuration>\n"
618       ;
619     /* clang-format on */
620   }
621   /* clang-format off */
622   fout <<
623     "\t</Configurations>\n"
624     "\t<Files></Files>\n"
625     "\t<Globals></Globals>\n"
626     "</VisualStudioProject>\n"
627     ;
628   /* clang-format on */
629
630   if (fout.Close()) {
631     this->FileReplacedDuringGenerate(fname);
632   }
633   return pname;
634 }
635
636 std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
637 {
638   std::string const& guidStoreName = name + "_GUID_CMAKE";
639   if (cmValue storedGUID =
640         this->CMakeInstance->GetCacheDefinition(guidStoreName)) {
641     return *storedGUID;
642   }
643   // Compute a GUID that is deterministic but unique to the build tree.
644   std::string input =
645     cmStrCat(this->CMakeInstance->GetState()->GetBinaryDirectory(), '|', name);
646
647   cmUuid uuidGenerator;
648
649   std::vector<unsigned char> uuidNamespace;
650   uuidGenerator.StringToBinary("ee30c4be-5192-4fb0-b335-722a2dffe760",
651                                uuidNamespace);
652
653   std::string guid = uuidGenerator.FromMd5(uuidNamespace, input);
654
655   return cmSystemTools::UpperCase(guid);
656 }
657
658 void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig(
659   const std::string& prefix, const std::string& config,
660   const std::string& suffix, std::string& dir)
661 {
662   if (!config.empty()) {
663     dir += prefix;
664     dir += config;
665     dir += suffix;
666   }
667 }
668
669 std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
670   std::vector<std::string> const& configs,
671   OrderedTargetDependSet const& projectTargets,
672   cmGeneratorTarget const* target)
673 {
674   std::set<std::string> activeConfigs;
675   // if it is a utilitiy target then only make it part of the
676   // default build if another target depends on it
677   int type = target->GetType();
678   if (type == cmStateEnums::GLOBAL_TARGET) {
679     std::vector<std::string> targetNames;
680     targetNames.push_back("INSTALL");
681     targetNames.push_back("PACKAGE");
682     for (std::string const& t : targetNames) {
683       // check if target <t> is part of default build
684       if (target->GetName() == t) {
685         const std::string propertyName =
686           "CMAKE_VS_INCLUDE_" + t + "_TO_DEFAULT_BUILD";
687         // inspect CMAKE_VS_INCLUDE_<t>_TO_DEFAULT_BUILD properties
688         for (std::string const& i : configs) {
689           cmValue propertyValue =
690             target->Target->GetMakefile()->GetDefinition(propertyName);
691           if (propertyValue &&
692               cmIsOn(cmGeneratorExpression::Evaluate(
693                 *propertyValue, target->GetLocalGenerator(), i))) {
694             activeConfigs.insert(i);
695           }
696         }
697       }
698     }
699     return activeConfigs;
700   }
701   if (type == cmStateEnums::UTILITY &&
702       !this->IsDependedOn(projectTargets, target)) {
703     return activeConfigs;
704   }
705   // inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
706   for (std::string const& i : configs) {
707     if (cmIsOff(target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i))) {
708       activeConfigs.insert(i);
709     }
710   }
711   return activeConfigs;
712 }
713
714 bool cmGlobalVisualStudio7Generator::IsDependedOn(
715   OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn)
716 {
717   for (cmTargetDepend const& l : projectTargets) {
718     TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(l);
719     if (tgtdeps.count(gtIn)) {
720       return true;
721     }
722   }
723   return false;
724 }
725
726 std::string cmGlobalVisualStudio7Generator::Encoding()
727 {
728   return "UTF-8";
729 }