Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGlobalVisualStudio9Generator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 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 "windows.h" // this must be first to define GetCurrentDirectory
13 #include "cmGlobalVisualStudio9Generator.h"
14 #include "cmLocalVisualStudio7Generator.h"
15 #include "cmMakefile.h"
16 #include "cmVisualStudioWCEPlatformParser.h"
17 #include "cmake.h"
18
19 static const char vs9generatorName[] = "Visual Studio 9 2008";
20
21 class cmGlobalVisualStudio9Generator::Factory
22   : public cmGlobalGeneratorFactory
23 {
24 public:
25   virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const {
26     if(strstr(name, vs9generatorName) != name)
27       {
28       return 0;
29       }
30
31     const char* p = name + sizeof(vs9generatorName) - 1;
32     if(p[0] == '\0')
33       {
34       return new cmGlobalVisualStudio9Generator(
35         name, NULL, NULL);
36       }
37
38     if(p[0] != ' ')
39       {
40       return 0;
41       }
42
43     ++p;
44
45     if(!strcmp(p, "IA64"))
46       {
47       return new cmGlobalVisualStudio9Generator(
48         name, "Itanium", "CMAKE_FORCE_IA64");
49       }
50
51     if(!strcmp(p, "Win64"))
52       {
53       return new cmGlobalVisualStudio9Generator(
54         name, "x64", "CMAKE_FORCE_WIN64");
55       }
56
57     cmVisualStudioWCEPlatformParser parser(p);
58     parser.ParseVersion("9.0");
59     if (!parser.Found())
60       {
61       return 0;
62       }
63
64     cmGlobalVisualStudio9Generator* ret = new cmGlobalVisualStudio9Generator(
65       name, p, NULL);
66     ret->WindowsCEVersion = parser.GetOSVersion();
67     return ret;
68   }
69
70   virtual void GetDocumentation(cmDocumentationEntry& entry) const {
71     entry.Name = vs9generatorName;
72     entry.Brief = "Generates Visual Studio 9 2008 project files.";
73     entry.Full =
74       "It is possible to append a space followed by the platform name "
75       "to create project files for a specific target platform. E.g. "
76       "\"Visual Studio 9 2008 Win64\" will create project files for "
77       "the x64 processor; \"Visual Studio 9 2008 IA64\" for Itanium.";
78   }
79
80   virtual void GetGenerators(std::vector<std::string>& names) const {
81     names.push_back(vs9generatorName);
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::vector<std::string>::const_iterator i =
89         availablePlatforms.begin(); i != availablePlatforms.end(); ++i)
90       {
91       names.push_back("Visual Studio 9 2008 " + *i);
92       }
93   }
94 };
95
96 //----------------------------------------------------------------------------
97 cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory()
98 {
99   return new Factory;
100 }
101
102 //----------------------------------------------------------------------------
103 cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator(
104   const char* name, const char* platformName,
105   const char* additionalPlatformDefinition)
106   : cmGlobalVisualStudio8Generator(name, platformName,
107                                    additionalPlatformDefinition)
108 {
109   this->FindMakeProgramFile = "CMakeVS9FindMake.cmake";
110 }
111
112 //----------------------------------------------------------------------------
113 void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout)
114 {
115   fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
116   fout << "# Visual Studio 2008\n";
117 }
118
119 ///! Create a local generator appropriate to this Global Generator
120 cmLocalGenerator *cmGlobalVisualStudio9Generator::CreateLocalGenerator()
121 {
122   cmLocalVisualStudio7Generator *lg
123     = new cmLocalVisualStudio7Generator(cmLocalVisualStudioGenerator::VS9);
124   lg->SetPlatformName(this->GetPlatformName());
125   lg->SetExtraFlagTable(this->GetExtraFlagTableVS8());
126   lg->SetGlobalGenerator(this);
127   return lg;
128 }
129
130 //----------------------------------------------------------------------------
131 void cmGlobalVisualStudio9Generator
132 ::EnableLanguage(std::vector<std::string>const &  lang,
133                  cmMakefile *mf, bool optional)
134 {
135   cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
136 }
137
138 //----------------------------------------------------------------------------
139 std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory()
140 {
141   std::string base;
142   std::string path;
143
144   // base begins with the VisualStudioProjectsLocation reg value...
145   if (cmSystemTools::ReadRegistryValue(
146     "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\9.0;"
147     "VisualStudioProjectsLocation",
148     base))
149     {
150     cmSystemTools::ConvertToUnixSlashes(base);
151
152     // 9.0 macros folder:
153     path = base + "/VSMacros80";
154       // *NOT* a typo; right now in Visual Studio 2008 beta the macros
155       // folder is VSMacros80... They may change it to 90 before final
156       // release of 2008 or they may not... we'll have to keep our eyes
157       // on it
158     }
159
160   // path is (correctly) still empty if we did not read the base value from
161   // the Registry value
162   return path;
163 }
164
165 //----------------------------------------------------------------------------
166 std::string cmGlobalVisualStudio9Generator::GetUserMacrosRegKeyBase()
167 {
168   return "Software\\Microsoft\\VisualStudio\\9.0\\vsmacros";
169 }