resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio9Generator.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 "cmGlobalVisualStudio9Generator.h"
4
5 #include <cstring>
6 #include <utility>
7 #include <vector>
8
9 #include "cmDocumentationEntry.h"
10 #include "cmGlobalGenerator.h"
11 #include "cmGlobalGeneratorFactory.h"
12 #include "cmGlobalVisualStudioGenerator.h"
13 #include "cmSystemTools.h"
14 #include "cmVisualStudioWCEPlatformParser.h"
15
16 class cmake;
17
18 static const char vs9generatorName[] = "Visual Studio 9 2008";
19
20 class cmGlobalVisualStudio9Generator::Factory : public cmGlobalGeneratorFactory
21 {
22 public:
23   std::unique_ptr<cmGlobalGenerator> CreateGlobalGenerator(
24     const std::string& name, bool allowArch, cmake* cm) const override
25   {
26     if (strncmp(name.c_str(), vs9generatorName,
27                 sizeof(vs9generatorName) - 1) != 0) {
28       return std::unique_ptr<cmGlobalGenerator>();
29     }
30
31     const char* p = name.c_str() + sizeof(vs9generatorName) - 1;
32     if (p[0] == '\0') {
33       return std::unique_ptr<cmGlobalGenerator>(
34         new cmGlobalVisualStudio9Generator(cm, name, ""));
35     }
36
37     if (!allowArch || p[0] != ' ') {
38       return std::unique_ptr<cmGlobalGenerator>();
39     }
40
41     ++p;
42
43     if (!strcmp(p, "IA64")) {
44       return std::unique_ptr<cmGlobalGenerator>(
45         new cmGlobalVisualStudio9Generator(cm, name, "Itanium"));
46     }
47
48     if (!strcmp(p, "Win64")) {
49       return std::unique_ptr<cmGlobalGenerator>(
50         new cmGlobalVisualStudio9Generator(cm, name, "x64"));
51     }
52
53     cmVisualStudioWCEPlatformParser parser(p);
54     parser.ParseVersion("9.0");
55     if (!parser.Found()) {
56       return std::unique_ptr<cmGlobalGenerator>();
57     }
58
59     auto ret = std::unique_ptr<cmGlobalVisualStudio9Generator>(
60       new cmGlobalVisualStudio9Generator(cm, name, p));
61     ret->WindowsCEVersion = parser.GetOSVersion();
62     return std::unique_ptr<cmGlobalGenerator>(std::move(ret));
63   }
64
65   void GetDocumentation(cmDocumentationEntry& entry) const override
66   {
67     entry.Name = std::string(vs9generatorName) + " [arch]";
68     entry.Brief = "Generates Visual Studio 2008 project files.  "
69                   "Optional [arch] can be \"Win64\" or \"IA64\".";
70   }
71
72   std::vector<std::string> GetGeneratorNames() const override
73   {
74     std::vector<std::string> names;
75     names.push_back(vs9generatorName);
76     return names;
77   }
78
79   std::vector<std::string> GetGeneratorNamesWithPlatform() const override
80   {
81     std::vector<std::string> names;
82     names.push_back(vs9generatorName + std::string(" Win64"));
83     names.push_back(vs9generatorName + std::string(" IA64"));
84     cmVisualStudioWCEPlatformParser parser;
85     parser.ParseVersion("9.0");
86     const std::vector<std::string>& availablePlatforms =
87       parser.GetAvailablePlatforms();
88     for (std::string const& i : availablePlatforms) {
89       names.push_back("Visual Studio 9 2008 " + i);
90     }
91     return names;
92   }
93
94   bool SupportsToolset() const override { return false; }
95   bool SupportsPlatform() const override { return true; }
96
97   std::vector<std::string> GetKnownPlatforms() const override
98   {
99     std::vector<std::string> platforms;
100     platforms.emplace_back("x64");
101     platforms.emplace_back("Win32");
102     platforms.emplace_back("Itanium");
103     cmVisualStudioWCEPlatformParser parser;
104     parser.ParseVersion("9.0");
105     const std::vector<std::string>& availablePlatforms =
106       parser.GetAvailablePlatforms();
107     for (std::string const& i : availablePlatforms) {
108       platforms.emplace_back(i);
109     }
110     return platforms;
111   }
112
113   std::string GetDefaultPlatformName() const override { return "Win32"; }
114 };
115
116 std::unique_ptr<cmGlobalGeneratorFactory>
117 cmGlobalVisualStudio9Generator::NewFactory()
118 {
119   return std::unique_ptr<cmGlobalGeneratorFactory>(new Factory);
120 }
121
122 cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator(
123   cmake* cm, const std::string& name,
124   std::string const& platformInGeneratorName)
125   : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName)
126 {
127   this->Version = VSVersion::VS9;
128   std::string vc9Express;
129   this->ExpressEdition = cmSystemTools::ReadRegistryValue(
130     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\9.0\\Setup\\VC;"
131     "ProductDir",
132     vc9Express, cmSystemTools::KeyWOW64_32);
133 }
134
135 std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory()
136 {
137   std::string base;
138   std::string path;
139
140   // base begins with the VisualStudioProjectsLocation reg value...
141   if (cmSystemTools::ReadRegistryValue(
142         "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\9.0;"
143         "VisualStudioProjectsLocation",
144         base)) {
145     cmSystemTools::ConvertToUnixSlashes(base);
146
147     // 9.0 macros folder:
148     path = base + "/VSMacros80";
149     // *NOT* a typo; right now in Visual Studio 2008 beta the macros
150     // folder is VSMacros80... They may change it to 90 before final
151     // release of 2008 or they may not... we'll have to keep our eyes
152     // on it
153   }
154
155   // path is (correctly) still empty if we did not read the base value from
156   // the Registry value
157   return path;
158 }
159
160 std::string cmGlobalVisualStudio9Generator::GetUserMacrosRegKeyBase()
161 {
162   return "Software\\Microsoft\\VisualStudio\\9.0\\vsmacros";
163 }