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 "cmGlobalVisualStudio10Generator.h"
14 #include "cmLocalVisualStudio10Generator.h"
15 #include "cmMakefile.h"
16 #include "cmSourceFile.h"
20 cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator()
22 this->FindMakeProgramFile = "CMakeVS10FindMake.cmake";
23 std::string vc10Express;
24 this->ExpressEdition = cmSystemTools::ReadRegistryValue(
25 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;"
26 "ProductDir", vc10Express, cmSystemTools::KeyWOW64_32);
29 //----------------------------------------------------------------------------
30 void cmGlobalVisualStudio10Generator::AddPlatformDefinitions(cmMakefile* mf)
32 mf->AddDefinition("MSVC10", "1");
33 mf->AddDefinition("MSVC_C_ARCHITECTURE_ID", "X86");
34 mf->AddDefinition("MSVC_CXX_ARCHITECTURE_ID", "X86");
37 //----------------------------------------------------------------------------
38 void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
40 fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
41 fout << "# Visual Studio 2010\n";
44 ///! Create a local generator appropriate to this Global Generator
45 cmLocalGenerator *cmGlobalVisualStudio10Generator::CreateLocalGenerator()
47 cmLocalVisualStudio10Generator* lg =
48 new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS10);
49 lg->SetPlatformName(this->GetPlatformName());
50 lg->SetGlobalGenerator(this);
54 //----------------------------------------------------------------------------
55 void cmGlobalVisualStudio10Generator::Generate()
57 this->LongestSource = LongestSourcePath();
58 this->cmGlobalVisualStudio8Generator::Generate();
59 if(this->LongestSource.Length > 0)
61 cmMakefile* mf = this->LongestSource.Target->GetMakefile();
64 "The binary and/or source directory paths may be too long to generate "
65 "Visual Studio 10 files for this project. "
66 "Consider choosing shorter directory names to build this project with "
68 "A more detailed explanation follows."
70 "There is a bug in the VS 10 IDE that renders property dialog fields "
71 "blank for files referenced by full path in the project file. "
72 "However, CMake must reference at least one file by full path:\n"
73 " " << this->LongestSource.SourceFile->GetFullPath() << "\n"
74 "This is because some Visual Studio tools would append the relative "
75 "path to the end of the referencing directory path, as in:\n"
76 " " << mf->GetCurrentOutputDirectory() << "/"
77 << this->LongestSource.SourceRel << "\n"
78 "and then incorrectly complain that the file does not exist because "
79 "the path length is too long for some internal buffer or API. "
80 "To avoid this problem CMake must use a full path for this file "
81 "which then triggers the VS 10 property dialog bug.";
82 mf->IssueMessage(cmake::WARNING, e.str().c_str());
86 //----------------------------------------------------------------------------
87 void cmGlobalVisualStudio10Generator
88 ::GetDocumentation(cmDocumentationEntry& entry) const
90 entry.Name = this->GetName();
91 entry.Brief = "Generates Visual Studio 10 project files.";
95 //----------------------------------------------------------------------------
96 void cmGlobalVisualStudio10Generator
97 ::EnableLanguage(std::vector<std::string>const & lang,
98 cmMakefile *mf, bool optional)
100 cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
103 //----------------------------------------------------------------------------
104 const char* cmGlobalVisualStudio10Generator::GetPlatformToolset()
106 if(!this->PlatformToolset.empty())
108 return this->PlatformToolset.c_str();
113 //----------------------------------------------------------------------------
114 std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
119 // base begins with the VisualStudioProjectsLocation reg value...
120 if (cmSystemTools::ReadRegistryValue(
121 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0;"
122 "VisualStudioProjectsLocation",
125 cmSystemTools::ConvertToUnixSlashes(base);
127 // 9.0 macros folder:
128 path = base + "/VSMacros80";
129 // *NOT* a typo; right now in Visual Studio 2008 beta the macros
130 // folder is VSMacros80... They may change it to 90 before final
131 // release of 2008 or they may not... we'll have to keep our eyes
135 // path is (correctly) still empty if we did not read the base value from
136 // the Registry value
140 //----------------------------------------------------------------------------
141 std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase()
143 return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros";
147 std::string cmGlobalVisualStudio10Generator
148 ::GenerateBuildCommand(const char* makeProgram,
149 const char *projectName,
150 const char* additionalOptions, const char *targetName,
151 const char* config, bool ignoreErrors, bool fast)
153 // now build the test
154 std::string makeCommand
155 = cmSystemTools::ConvertToOutputPath(makeProgram);
156 std::string lowerCaseCommand = makeCommand;
157 cmSystemTools::LowerCase(lowerCaseCommand);
159 // If makeProgram is devenv, parent class knows how to generate command:
160 if (lowerCaseCommand.find("devenv") != std::string::npos ||
161 lowerCaseCommand.find("VCExpress") != std::string::npos)
163 return cmGlobalVisualStudio7Generator::GenerateBuildCommand(makeProgram,
164 projectName, additionalOptions, targetName, config, ignoreErrors, fast);
167 // Otherwise, assume MSBuild command line, and construct accordingly.
169 // if there are spaces in the makeCommand, assume a full path
170 // and convert it to a path with no spaces in it as the
171 // RunSingleCommand does not like spaces
172 if(makeCommand.find(' ') != std::string::npos)
174 cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
176 // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
177 if(!targetName || strlen(targetName) == 0)
179 targetName = "ALL_BUILD";
182 if ( targetName && strcmp(targetName, "clean") == 0 )
186 makeCommand += projectName;
187 makeCommand += ".sln ";
188 makeCommand += "/t:Clean ";
193 makeCommand += targetName;
194 makeCommand += ".vcxproj ";
196 makeCommand += "/p:Configuration=";
197 if(config && strlen(config))
199 makeCommand += config;
203 makeCommand += "Debug";
205 if ( additionalOptions )
208 makeCommand += additionalOptions;
213 //----------------------------------------------------------------------------
214 bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
216 if(!this->PlatformToolset.empty())
220 // This edition does not come with 64-bit tools. Look for them.
222 // TODO: Detect available tools? x64\v100 exists but does not work?
223 // KHLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0;VCTargetsPath
224 // c:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/Platforms/
225 // {Itanium,Win32,x64}/PlatformToolsets/{v100,v90,Windows7.1SDK}
226 std::string winSDK_7_1;
227 if(cmSystemTools::ReadRegistryValue(
228 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\"
229 "Windows\\v7.1;InstallationFolder", winSDK_7_1))
232 m << "Found Windows SDK v7.1: " << winSDK_7_1;
233 mf->DisplayStatus(m.str().c_str(), -1);
234 this->PlatformToolset = "Windows7.1SDK";
240 e << "Cannot enable 64-bit tools with Visual Studio 2010 Express.\n"
241 << "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
242 << " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
243 mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
244 cmSystemTools::SetFatalErrorOccured();
249 //----------------------------------------------------------------------------
251 cmGlobalVisualStudio10Generator
252 ::GenerateRuleFile(std::string const& output) const
254 // The VS 10 generator needs to create the .rule files on disk.
255 // Hide them away under the CMakeFiles directory.
256 std::string ruleDir = this->GetCMakeInstance()->GetHomeOutputDirectory();
257 ruleDir += cmake::GetCMakeFilesDirectory();
259 ruleDir += cmSystemTools::ComputeStringMD5(
260 cmSystemTools::GetFilenamePath(output).c_str());
261 std::string ruleFile = ruleDir + "/";
262 ruleFile += cmSystemTools::GetFilenameName(output);
267 //----------------------------------------------------------------------------
268 void cmGlobalVisualStudio10Generator::PathTooLong(
269 cmTarget* target, cmSourceFile* sf, std::string const& sfRel)
271 size_t len = (strlen(target->GetMakefile()->GetCurrentOutputDirectory()) +
273 if(len > this->LongestSource.Length)
275 this->LongestSource.Length = len;
276 this->LongestSource.Target = target;
277 this->LongestSource.SourceFile = sf;
278 this->LongestSource.SourceRel = sfRel;
282 //----------------------------------------------------------------------------
283 bool cmGlobalVisualStudio10Generator::UseFolderProperty()
285 return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty();