1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalVisualStudio8Generator.cxx,v $
6 Date: $Date: 2008-01-02 20:55:18 $
7 Version: $Revision: 1.33 $
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"
25 cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator()
27 this->FindMakeProgramFile
= "CMakeVS8FindMake.cmake";
28 this->ProjectConfigurationSectionName
= "ProjectConfigurationPlatforms";
29 this->PlatformName
= "Win32";
34 ///! Create a local generator appropriate to this Global Generator
35 cmLocalGenerator
*cmGlobalVisualStudio8Generator::CreateLocalGenerator()
37 cmLocalVisualStudio7Generator
*lg
= new cmLocalVisualStudio7Generator
;
39 lg
->SetExtraFlagTable(this->GetExtraFlagTableVS8());
40 lg
->SetGlobalGenerator(this);
45 // ouput standard header for dsw file
46 void cmGlobalVisualStudio8Generator::WriteSLNHeader(std::ostream
& fout
)
48 fout
<< "Microsoft Visual Studio Solution File, Format Version 9.00\n";
49 fout
<< "# Visual Studio 2005\n";
52 //----------------------------------------------------------------------------
53 void cmGlobalVisualStudio8Generator
54 ::GetDocumentation(cmDocumentationEntry
& entry
) const
56 entry
.Name
= this->GetName();
57 entry
.Brief
= "Generates Visual Studio .NET 2005 project files.";
61 //----------------------------------------------------------------------------
62 void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile
* mf
)
64 mf
->AddDefinition("MSVC80", "1");
67 //----------------------------------------------------------------------------
68 void cmGlobalVisualStudio8Generator::Configure()
70 this->cmGlobalVisualStudio7Generator::Configure();
71 this->CreateGUID(CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
74 //----------------------------------------------------------------------------
75 std::string
cmGlobalVisualStudio8Generator::GetUserMacrosDirectory()
77 // Some VS8 sp0 versions cannot run macros.
78 // See http://support.microsoft.com/kb/928209
79 const char* vc8sp1Registry
=
80 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
81 "InstalledProducts\\KB926601;";
82 const char* vc8exSP1Registry
=
83 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0\\"
84 "InstalledProducts\\KB926748;";
86 if (!cmSystemTools::ReadRegistryValue(vc8sp1Registry
, vc8sp1
) &&
87 !cmSystemTools::ReadRegistryValue(vc8exSP1Registry
, vc8sp1
))
95 // base begins with the VisualStudioProjectsLocation reg value...
96 if (cmSystemTools::ReadRegistryValue(
97 "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\8.0;"
98 "VisualStudioProjectsLocation",
101 cmSystemTools::ConvertToUnixSlashes(base
);
103 // 7.0 macros folder:
104 //path = base + "/VSMacros";
106 // 7.1 macros folder:
107 //path = base + "/VSMacros71";
109 // 8.0 macros folder:
110 path
= base
+ "/VSMacros80";
113 // path is (correctly) still empty if we did not read the base value from
114 // the Registry value
118 //----------------------------------------------------------------------------
119 void cmGlobalVisualStudio8Generator::Generate()
121 // Add a special target on which all other targets depend that
122 // checks the build system and optionally re-runs CMake.
123 const char* no_working_directory
= 0;
124 std::vector
<std::string
> no_depends
;
125 std::map
<cmStdString
, std::vector
<cmLocalGenerator
*> >::iterator it
;
126 for(it
= this->ProjectMap
.begin(); it
!= this->ProjectMap
.end(); ++it
)
128 std::vector
<cmLocalGenerator
*>& generators
= it
->second
;
129 if(!generators
.empty())
131 // Add the build-system check target to the first local
132 // generator of this project.
133 cmLocalVisualStudio7Generator
* lg
=
134 static_cast<cmLocalVisualStudio7Generator
*>(generators
[0]);
135 cmMakefile
* mf
= lg
->GetMakefile();
136 std::string cmake_command
= mf
->GetRequiredDefinition("CMAKE_COMMAND");
137 cmCustomCommandLines noCommandLines
;
138 mf
->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET
, false,
139 no_working_directory
, no_depends
,
141 cmTarget
* tgt
= mf
->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET
, false);
144 cmSystemTools::Error("Error adding target "
145 CMAKE_CHECK_BUILD_SYSTEM_TARGET
);
149 // Add a custom rule to re-run CMake if any input files changed.
150 const char* suppRegenRule
=
151 mf
->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
152 if(!cmSystemTools::IsOn(suppRegenRule
))
154 // Collect the input files used to generate all targets in this
156 std::vector
<std::string
> listFiles
;
157 for(unsigned int j
= 0; j
< generators
.size(); ++j
)
159 cmMakefile
* lmf
= generators
[j
]->GetMakefile();
160 listFiles
.insert(listFiles
.end(), lmf
->GetListFiles().begin(),
161 lmf
->GetListFiles().end());
163 // Sort the list of input files and remove duplicates.
164 std::sort(listFiles
.begin(), listFiles
.end(),
165 std::less
<std::string
>());
166 std::vector
<std::string
>::iterator new_end
=
167 std::unique(listFiles
.begin(), listFiles
.end());
168 listFiles
.erase(new_end
, listFiles
.end());
170 // Create a rule to re-run CMake.
171 std::string stampName
= cmake::GetCMakeFilesDirectoryPostSlash();
172 stampName
+= "generate.stamp";
173 const char* dsprule
= mf
->GetRequiredDefinition("CMAKE_COMMAND");
174 cmCustomCommandLine commandLine
;
175 commandLine
.push_back(dsprule
);
176 std::string argH
= "-H";
177 argH
+= lg
->Convert(mf
->GetHomeDirectory(),
178 cmLocalGenerator::START_OUTPUT
,
179 cmLocalGenerator::UNCHANGED
, true);
180 commandLine
.push_back(argH
);
181 std::string argB
= "-B";
182 argB
+= lg
->Convert(mf
->GetHomeOutputDirectory(),
183 cmLocalGenerator::START_OUTPUT
,
184 cmLocalGenerator::UNCHANGED
, true);
185 commandLine
.push_back(argB
);
186 commandLine
.push_back("--check-stamp-file");
187 commandLine
.push_back(stampName
.c_str());
188 commandLine
.push_back("--vs-solution-file");
189 commandLine
.push_back("\"$(SolutionPath)\"");
190 cmCustomCommandLines commandLines
;
191 commandLines
.push_back(commandLine
);
193 // Add the rule. Note that we cannot use the CMakeLists.txt
194 // file as the main dependency because it would get
195 // overwritten by the CreateVCProjBuildRule.
196 // (this could be avoided with per-target source files)
197 const char* no_main_dependency
= 0;
198 const char* no_working_directory
= 0;
199 mf
->AddCustomCommandToOutput(
200 stampName
.c_str(), listFiles
,
201 no_main_dependency
, commandLines
, "Checking Build System",
202 no_working_directory
, true);
203 std::string ruleName
= stampName
;
205 if(cmSourceFile
* file
= mf
->GetSource(ruleName
.c_str()))
207 tgt
->AddSourceFile(file
);
211 cmSystemTools::Error("Error adding rule for ", stampName
.c_str());
217 // Now perform the main generation.
218 this->cmGlobalVisualStudio7Generator::Generate();
221 //----------------------------------------------------------------------------
222 void cmGlobalVisualStudio8Generator::WriteSLNFile(
223 std::ostream
& fout
, cmLocalGenerator
* root
,
224 std::vector
<cmLocalGenerator
*>& generators
)
226 // Make all targets depend on their respective project's build
227 // system check target.
229 for(i
= 0; i
< generators
.size(); ++i
)
231 if(this->IsExcluded(root
, generators
[i
]))
235 cmMakefile
* mf
= generators
[i
]->GetMakefile();
236 cmTargets
& tgts
= mf
->GetTargets();
237 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); ++l
)
239 if(l
->first
== CMAKE_CHECK_BUILD_SYSTEM_TARGET
)
241 for(unsigned int j
= 0; j
< generators
.size(); ++j
)
243 // Every target in all generators should depend on this target.
244 cmMakefile
* lmf
= generators
[j
]->GetMakefile();
245 cmTargets
&atgts
= lmf
->GetTargets();
246 for(cmTargets::iterator al
= atgts
.begin(); al
!= atgts
.end(); ++al
)
248 al
->second
.AddUtility(l
->first
.c_str());
255 // Now write the solution file.
256 this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout
, root
, generators
);
259 //----------------------------------------------------------------------------
261 cmGlobalVisualStudio8Generator
262 ::WriteSolutionConfigurations(std::ostream
& fout
)
264 fout
<< "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
265 for(std::vector
<std::string
>::iterator i
= this->Configurations
.begin();
266 i
!= this->Configurations
.end(); ++i
)
268 fout
<< "\t\t" << *i
<< "|" << this->PlatformName
<< " = " << *i
<< "|"
269 << this->PlatformName
<< "\n";
271 fout
<< "\tEndGlobalSection\n";
274 //----------------------------------------------------------------------------
276 cmGlobalVisualStudio8Generator
277 ::WriteProjectConfigurations(std::ostream
& fout
, const char* name
,
278 bool partOfDefaultBuild
)
280 std::string guid
= this->GetGUID(name
);
281 for(std::vector
<std::string
>::iterator i
= this->Configurations
.begin();
282 i
!= this->Configurations
.end(); ++i
)
284 fout
<< "\t\t{" << guid
<< "}." << *i
285 << "|" << this->PlatformName
<< ".ActiveCfg = "
286 << *i
<< "|" << this->PlatformName
<< "\n";
287 if(partOfDefaultBuild
)
289 fout
<< "\t\t{" << guid
<< "}." << *i
290 << "|" << this->PlatformName
<< ".Build.0 = "
291 << *i
<< "|" << this->PlatformName
<< "\n";
296 //----------------------------------------------------------------------------
297 static cmVS7FlagTable cmVS8ExtraFlagTable
[] =
299 {"CallingConvention", "Gd", "cdecl", "0", 0 },
300 {"CallingConvention", "Gr", "fastcall", "1", 0 },
301 {"CallingConvention", "Gz", "stdcall", "2", 0 },
303 {"Detect64BitPortabilityProblems", "Wp64",
304 "Detect 64Bit Portability Problems", "true", 0 },
305 {"ErrorReporting", "errorReport:prompt", "Report immediately", "1", 0 },
306 {"ErrorReporting", "errorReport:queue", "Queue for next login", "2", 0 },
307 // Precompiled header and related options. Note that the
308 // UsePrecompiledHeader entries are marked as "Continue" so that the
309 // corresponding PrecompiledHeaderThrough entry can be found.
310 {"UsePrecompiledHeader", "Yu", "Use Precompiled Header", "2",
311 cmVS7FlagTable::UserValueIgnored
| cmVS7FlagTable::Continue
},
312 {"PrecompiledHeaderThrough", "Yu", "Precompiled Header Name", "",
313 cmVS7FlagTable::UserValueRequired
},
314 // There is no YX option in the VS8 IDE.
316 // Exception handling mode. If no entries match, it will be FALSE.
317 {"ExceptionHandling", "GX", "enable c++ exceptions", "1", 0},
318 {"ExceptionHandling", "EHsc", "enable c++ exceptions", "1", 0},
319 {"ExceptionHandling", "EHa", "enable SEH exceptions", "2", 0},
323 cmVS7FlagTable
const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
325 return cmVS8ExtraFlagTable
;