Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio11Generator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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 "cmGlobalVisualStudio11Generator.h"
13 #include "cmLocalVisualStudio10Generator.h"
14 #include "cmMakefile.h"
15
16 static const char vs11generatorName[] = "Visual Studio 11";
17
18 class cmGlobalVisualStudio11Generator::Factory
19   : public cmGlobalGeneratorFactory
20 {
21 public:
22   virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const {
23     if(strstr(name, vs11generatorName) != name)
24       {
25       return 0;
26       }
27
28     const char* p = name + sizeof(vs11generatorName) - 1;
29     if(p[0] == '\0')
30       {
31       return new cmGlobalVisualStudio11Generator(
32         name, NULL, NULL);
33       }
34
35     if(p[0] != ' ')
36       {
37       return 0;
38       }
39
40     ++p;
41
42     if(!strcmp(p, "ARM"))
43       {
44       return new cmGlobalVisualStudio11Generator(
45         name, "ARM", NULL);
46       }
47
48     if(!strcmp(p, "Win64"))
49       {
50       return new cmGlobalVisualStudio11Generator(
51         name, "x64", "CMAKE_FORCE_WIN64");
52       }
53
54     std::set<std::string> installedSDKs =
55       cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
56
57     if(installedSDKs.find(p) == installedSDKs.end())
58       {
59       return 0;
60       }
61
62     cmGlobalVisualStudio11Generator* ret =
63       new cmGlobalVisualStudio11Generator(name, p, NULL);
64     ret->WindowsCEVersion = "8.00";
65     return ret;
66   }
67
68   virtual void GetDocumentation(cmDocumentationEntry& entry) const {
69     entry.Name = "Visual Studio 11";
70     entry.Brief = "Generates Visual Studio 11 (2012) project files.";
71     entry.Full =
72       "It is possible to append a space followed by the platform name "
73       "to create project files for a specific target platform. E.g. "
74       "\"Visual Studio 11 Win64\" will create project files for "
75       "the x64 processor; \"Visual Studio 11 ARM\" for ARM.";
76   }
77
78   virtual void GetGenerators(std::vector<std::string>& names) const {
79     names.push_back(vs11generatorName);
80     names.push_back(vs11generatorName + std::string(" ARM"));
81     names.push_back(vs11generatorName + std::string(" Win64"));
82
83     std::set<std::string> installedSDKs =
84       cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
85     for(std::set<std::string>::const_iterator i =
86         installedSDKs.begin(); i != installedSDKs.end(); ++i)
87       {
88       names.push_back("Visual Studio 11 " + *i);
89       }
90   }
91 };
92
93 //----------------------------------------------------------------------------
94 cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
95 {
96   return new Factory;
97 }
98
99 //----------------------------------------------------------------------------
100 cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
101   const char* name, const char* platformName,
102   const char* additionalPlatformDefinition)
103   : cmGlobalVisualStudio10Generator(name, platformName,
104                                    additionalPlatformDefinition)
105 {
106   this->FindMakeProgramFile = "CMakeVS11FindMake.cmake";
107   std::string vc11Express;
108   this->ExpressEdition = cmSystemTools::ReadRegistryValue(
109     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
110     "ProductDir", vc11Express, cmSystemTools::KeyWOW64_32);
111   this->PlatformToolset = "v110";
112 }
113
114 //----------------------------------------------------------------------------
115 void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
116 {
117   fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
118   if (this->ExpressEdition)
119     {
120     fout << "# Visual Studio Express 2012 for Windows Desktop\n";
121     }
122   else
123     {
124     fout << "# Visual Studio 2012\n";
125     }
126 }
127
128 //----------------------------------------------------------------------------
129 cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
130 {
131   cmLocalVisualStudio10Generator* lg =
132     new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
133   lg->SetPlatformName(this->GetPlatformName());
134   lg->SetGlobalGenerator(this);
135   return lg;
136 }
137
138 //----------------------------------------------------------------------------
139 bool cmGlobalVisualStudio11Generator::UseFolderProperty()
140 {
141   // Intentionally skip over the parent class implementation and call the
142   // grand-parent class's implementation. Folders are not supported by the
143   // Express editions in VS10 and earlier, but they are in VS11 Express.
144   return cmGlobalVisualStudio8Generator::UseFolderProperty();
145 }
146
147 //----------------------------------------------------------------------------
148 std::set<std::string>
149 cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
150 {
151   const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
152                          "Windows CE Tools\\SDKs";
153
154   std::vector<std::string> subkeys;
155   cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
156                                     cmSystemTools::KeyWOW64_32);
157
158   std::set<std::string> ret;
159   for(std::vector<std::string>::const_iterator i =
160       subkeys.begin(); i != subkeys.end(); ++i)
161     {
162     std::string key = sdksKey;
163     key += '\\';
164     key += *i;
165     key += ';';
166
167     std::string path;
168     if(cmSystemTools::ReadRegistryValue(key.c_str(),
169                                         path,
170                                         cmSystemTools::KeyWOW64_32) &&
171         !path.empty())
172       {
173       ret.insert(*i);
174       }
175     }
176
177   return ret;
178 }