1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio8Generator.cxx,v $
6 Date: $Date: 2009-09-04 16:37:51 $
7 Version: $Revision: 1.39 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "windows.h" // this must be first to define GetCurrentDirectory
18 #include "cmGlobalVisualStudio8Generator.h"
19 #include "cmLocalVisualStudio7Generator.h"
20 #include "cmMakefile.h"
22 #include "cmGeneratedFileStream.h"
24 //----------------------------------------------------------------------------
25 cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
27 this->FindMakeProgramFile
= "CMakeVS8FindMake.cmake";
28 this->ProjectConfigurationSectionName
= "ProjectConfigurationPlatforms";
29 this->PlatformName
= "Win32";
32 //----------------------------------------------------------------------------
33 ///! Create a local generator appropriate to this Global Generator
34 cmLocalGenerator
*cmGlobalVisualStudio8Generator::CreateLocalGenerator()
36 cmLocalVisualStudio7Generator
*lg
= new cmLocalVisualStudio7Generator
;
38 lg
->SetExtraFlagTable(this->GetExtraFlagTableVS8());
39 lg
->SetGlobalGenerator(this);
43 //----------------------------------------------------------------------------
44 // ouput standard header for dsw file
45 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream
& fout
)
47 fout
<< "Microsoft Visual Studio Solution File, Format Version 9.00\n";
48 fout
<< "# Visual Studio 2005\n";
51 //----------------------------------------------------------------------------
52 void cmGlobalVisualStudio8Generator
53 ::GetDocumentation(cmDocumentationEntry
& entry
) const
55 entry
.Name
= this->GetName();
56 entry
.Brief
= "Generates Visual Studio .NET 2005 project files.";
60 //----------------------------------------------------------------------------
61 void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile
* mf
)
63 mf
->AddDefinition("MSVC80", "1");
66 //----------------------------------------------------------------------------
67 void cmGlobalVisualStudio8Generator::Configure()
69 this->cmGlobalVisualStudio7Generator::Configure();
70 this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
73 //----------------------------------------------------------------------------
74 std::string
cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
76 // Some VS8 sp0 versions cannot run macros.
77 // See http://support.microsoft.com/kb/928209
78 const char* vc8sp1Registry
=
79 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
80 "InstalledProducts\\KB926601;";
81 const char* vc8exSP1Registry
=
82 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
83 "InstalledProducts\\KB926748;";
85 if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry
, vc8sp1
) &&
86 !cmSystemTools::ReadRegistryValue(vc8exSP1Registry
, vc8sp1
))
94 // base begins with the VisualStudioProjectsLocation reg value...
95 if (cmSystemTools::ReadRegistryValue(
96 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
97 "VisualStudioProjectsLocation",
100 cmSystemTools::ConvertToUnixSlashes(base
);
102 // 8.0 macros folder:
103 path
= base
+ "/VSMacros80";
106 // path is (correctly) still empty if we did not read the base value from
107 // the Registry value
111 //----------------------------------------------------------------------------
112 std::string
cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
114 return "Software\\Microsoft\\VisualStudio\\8.0\\vsmacros";
117 //----------------------------------------------------------------------------
118 void cmGlobalVisualStudio8Generator::Generate()
120 // Add a special target on which all other targets depend that
121 // checks the build system and optionally re-runs CMake.
122 const char* no_working_directory
= 0;
123 std::vector
<std::string
> no_depends
;
124 std::map
<cmStdString
, std::vector
<cmLocalGenerator
*> >::iterator it
;
125 for(it
= this->ProjectMap
.begin(); it
!= this->ProjectMap
.end(); ++it
)
127 std::vector
<cmLocalGenerator
*>& generators
= it
->second
;
128 if(!generators
.empty())
130 // Add the build-system check target to the first local
131 // generator of this project.
132 cmLocalVisualStudio7Generator
* lg
=
133 static_cast<cmLocalVisualStudio7Generator
*>(generators
[0]);
134 cmMakefile
* mf
= lg
->GetMakefile();
136 // Skip the target if no regeneration is to be done.
137 if(mf
->IsOn("CMAKE_SUPPRESS_REGENERATION"))
142 std::string cmake_command
= mf
->GetRequiredDefinition("CMAKE_COMMAND");
143 cmCustomCommandLines noCommandLines
;
144 mf
->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET
, false,
145 no_working_directory
, no_depends
,
147 cmTarget
* tgt
= mf
->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
150 cmSystemTools::Error("Error adding target "
151 CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
155 // Create a list of all stamp files for this project.
156 std::vector
<std::string
> stamps
;
157 std::string stampList
= cmake::GetCMakeFilesDirectoryPostSlash();
158 stampList
+= "generate.stamp.list";
160 std::string stampListFile
=
161 generators
[0]->GetMakefile()->GetCurrentOutputDirectory();
162 stampListFile
+= "/";
163 stampListFile
+= stampList
;
164 std::string stampFile
;
165 cmGeneratedFileStream
fout(stampListFile
.c_str());
166 for(std::vector
<cmLocalGenerator
*>::const_iterator
167 gi
= generators
.begin(); gi
!= generators
.end(); ++gi
)
169 stampFile
= (*gi
)->GetMakefile()->GetCurrentOutputDirectory();
171 stampFile
+= cmake::GetCMakeFilesDirectoryPostSlash();
172 stampFile
+= "generate.stamp";
173 stampFile
= generators
[0]->Convert(stampFile
.c_str(),
174 cmLocalGenerator::START_OUTPUT
);
175 fout
<< stampFile
<< "\n";
176 stamps
.push_back(stampFile
);
180 // Add a custom rule to re-run CMake if any input files changed.
182 // Collect the input files used to generate all targets in this
184 std::vector
<std::string
> listFiles
;
185 for(unsigned int j
= 0; j
< generators
.size(); ++j
)
187 cmMakefile
* lmf
= generators
[j
]->GetMakefile();
188 listFiles
.insert(listFiles
.end(), lmf
->GetListFiles().begin(),
189 lmf
->GetListFiles().end());
191 // Sort the list of input files and remove duplicates.
192 std::sort(listFiles
.begin(), listFiles
.end(),
193 std::less
<std::string
>());
194 std::vector
<std::string
>::iterator new_end
=
195 std::unique(listFiles
.begin(), listFiles
.end());
196 listFiles
.erase(new_end
, listFiles
.end());
198 // Create a rule to re-run CMake.
199 std::string stampName
= cmake::GetCMakeFilesDirectoryPostSlash();
200 stampName
+= "generate.stamp";
201 const char* dsprule
= mf
->GetRequiredDefinition("CMAKE_COMMAND");
202 cmCustomCommandLine commandLine
;
203 commandLine
.push_back(dsprule
);
204 std::string argH
= "-H";
205 argH
+= lg
->Convert(mf
->GetHomeDirectory(),
206 cmLocalGenerator::START_OUTPUT
,
207 cmLocalGenerator::UNCHANGED
, true);
208 commandLine
.push_back(argH
);
209 std::string argB
= "-B";
210 argB
+= lg
->Convert(mf
->GetHomeOutputDirectory(),
211 cmLocalGenerator::START_OUTPUT
,
212 cmLocalGenerator::UNCHANGED
, true);
213 commandLine
.push_back(argB
);
214 commandLine
.push_back("--check-stamp-list");
215 commandLine
.push_back(stampList
.c_str());
216 commandLine
.push_back("--vs-solution-file");
217 commandLine
.push_back("\"$(SolutionPath)\"");
218 cmCustomCommandLines commandLines
;
219 commandLines
.push_back(commandLine
);
221 // Add the rule. Note that we cannot use the CMakeLists.txt
222 // file as the main dependency because it would get
223 // overwritten by the CreateVCProjBuildRule.
224 // (this could be avoided with per-target source files)
225 const char* no_main_dependency
= 0;
226 const char* no_working_directory
= 0;
227 mf
->AddCustomCommandToOutput(
229 no_main_dependency
, commandLines
, "Checking Build System",
230 no_working_directory
, true);
231 std::string ruleName
= stamps
[0];
233 if(cmSourceFile
* file
= mf
->GetSource(ruleName
.c_str()))
235 tgt
->AddSourceFile(file
);
239 cmSystemTools::Error("Error adding rule for ", stamps
[0].c_str());
245 // All targets depend on the build-system check target.
246 for(std::map
<cmStdString
,cmTarget
*>::const_iterator
247 ti
= this->TotalTargets
.begin();
248 ti
!= this->TotalTargets
.end(); ++ti
)
250 if(ti
->first
!= CMAKE_CHECK_BUILD_SYSTEM_TARGET
)
252 ti
->second
->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
256 // Now perform the main generation.
257 this->cmGlobalVisualStudio7Generator::Generate();
260 //----------------------------------------------------------------------------
262 cmGlobalVisualStudio8Generator
263 ::WriteSolutionConfigurations(std::ostream
& fout
)
265 fout
<< "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
266 for(std::vector
<std::string
>::iterator i
= this->Configurations
.begin();
267 i
!= this->Configurations
.end(); ++i
)
269 fout
<< "\t\t" << *i
<< "|" << this->PlatformName
<< " = " << *i
<< "|"
270 << this->PlatformName
<< "\n";
272 fout
<< "\tEndGlobalSection\n";
275 //----------------------------------------------------------------------------
277 cmGlobalVisualStudio8Generator
278 ::WriteProjectConfigurations(std::ostream
& fout
, const char* name
,
279 bool partOfDefaultBuild
)
281 std::string guid
= this->GetGUID(name
);
282 for(std::vector
<std::string
>::iterator i
= this->Configurations
.begin();
283 i
!= this->Configurations
.end(); ++i
)
285 fout
<< "\t\t{" << guid
<< "}." << *i
286 << "|" << this->PlatformName
<< ".ActiveCfg = "
287 << *i
<< "|" << this->PlatformName
<< "\n";
288 if(partOfDefaultBuild
)
290 fout
<< "\t\t{" << guid
<< "}." << *i
291 << "|" << this->PlatformName
<< ".Build.0 = "
292 << *i
<< "|" << this->PlatformName
<< "\n";
297 //----------------------------------------------------------------------------
298 static cmVS7FlagTable cmVS8ExtraFlagTable
[] =
300 {"CallingConvention", "Gd", "cdecl", "0", 0 },
301 {"CallingConvention", "Gr", "fastcall", "1", 0 },
302 {"CallingConvention", "Gz", "stdcall", "2", 0 },
304 {"Detect64BitPortabilityProblems", "Wp64",
305 "Detect 64Bit Portability Problems", "true", 0 },
306 {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
307 {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
308 // Precompiled header and related options. Note that the
309 // UsePrecompiledHeader entries are marked as "Continue" so that the
310 // corresponding PrecompiledHeaderThrough entry can be found.
311 {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
312 cmVS7FlagTable::UserValueIgnored
| cmVS7FlagTable::Continue
},
313 {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
314 cmVS7FlagTable::UserValueRequired
},
315 // There is no YX option in the VS8 IDE.
317 // Exception handling mode. If no entries match, it will be FALSE.
318 {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
319 {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
320 {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
324 cmIDEFlagTable
const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
326 return cmVS8ExtraFlagTable
;