117
112
//----------------------------------------------------------------------------
118
void cmGlobalVisualStudio8Generator::Generate()
113
void cmGlobalVisualStudio8Generator::AddCheckTarget()
120
115
// Add a special target on which all other targets depend that
121
116
// checks the build system and optionally re-runs CMake.
122
117
const char* no_working_directory = 0;
123
118
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());
119
std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
120
cmLocalVisualStudio7Generator* lg =
121
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
122
cmMakefile* mf = lg->GetMakefile();
124
// Skip the target if no regeneration is to be done.
125
if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
130
std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
131
cmCustomCommandLines noCommandLines;
133
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
134
no_working_directory, no_depends,
137
// Create a list of all stamp files for this project.
138
std::vector<std::string> stamps;
139
std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
140
stampList += "generate.stamp.list";
142
std::string stampListFile =
143
generators[0]->GetMakefile()->GetCurrentOutputDirectory();
144
stampListFile += "/";
145
stampListFile += stampList;
146
std::string stampFile;
147
cmGeneratedFileStream fout(stampListFile.c_str());
148
for(std::vector<cmLocalGenerator*>::const_iterator
149
gi = generators.begin(); gi != generators.end(); ++gi)
151
stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
153
stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
154
stampFile += "generate.stamp";
155
stampFile = generators[0]->Convert(stampFile.c_str(),
156
cmLocalGenerator::START_OUTPUT);
157
fout << stampFile << "\n";
158
stamps.push_back(stampFile);
162
// Add a custom rule to re-run CMake if any input files changed.
164
// Collect the input files used to generate all targets in this
166
std::vector<std::string> listFiles;
167
for(unsigned int j = 0; j < generators.size(); ++j)
169
cmMakefile* lmf = generators[j]->GetMakefile();
170
listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
171
lmf->GetListFiles().end());
173
// Sort the list of input files and remove duplicates.
174
std::sort(listFiles.begin(), listFiles.end(),
175
std::less<std::string>());
176
std::vector<std::string>::iterator new_end =
177
std::unique(listFiles.begin(), listFiles.end());
178
listFiles.erase(new_end, listFiles.end());
180
// Create a rule to re-run CMake.
181
std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
182
stampName += "generate.stamp";
183
const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
184
cmCustomCommandLine commandLine;
185
commandLine.push_back(dsprule);
186
std::string argH = "-H";
187
argH += lg->Convert(mf->GetHomeDirectory(),
188
cmLocalGenerator::START_OUTPUT,
189
cmLocalGenerator::UNCHANGED, true);
190
commandLine.push_back(argH);
191
std::string argB = "-B";
192
argB += lg->Convert(mf->GetHomeOutputDirectory(),
193
cmLocalGenerator::START_OUTPUT,
194
cmLocalGenerator::UNCHANGED, true);
195
commandLine.push_back(argB);
196
commandLine.push_back("--check-stamp-list");
197
commandLine.push_back(stampList.c_str());
198
commandLine.push_back("--vs-solution-file");
199
commandLine.push_back("\"$(SolutionPath)\"");
200
cmCustomCommandLines commandLines;
201
commandLines.push_back(commandLine);
203
// Add the rule. Note that we cannot use the CMakeLists.txt
204
// file as the main dependency because it would get
205
// overwritten by the CreateVCProjBuildRule.
206
// (this could be avoided with per-target source files)
207
const char* no_main_dependency = 0;
208
const char* no_working_directory = 0;
209
mf->AddCustomCommandToOutput(
211
no_main_dependency, commandLines, "Checking Build System",
212
no_working_directory, true);
213
std::string ruleName = stamps[0];
215
if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
217
tgt->AddSourceFile(file);
221
cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
226
//----------------------------------------------------------------------------
227
void cmGlobalVisualStudio8Generator::Generate()
229
this->AddCheckTarget();
231
// All targets depend on the build-system check target.
232
for(std::map<cmStdString,cmTarget *>::const_iterator
233
ti = this->TotalTargets.begin();
234
ti != this->TotalTargets.end(); ++ti)
236
if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
238
ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);