~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/cmGlobalVisualStudio8Generator.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*=========================================================================
2
 
 
3
 
  Program:   CMake - Cross-Platform Makefile Generator
4
 
  Module:    $RCSfile: cmGlobalVisualStudio8Generator.cxx,v $
5
 
  Language:  C++
6
 
  Date:      $Date: 2008-04-02 13:16:04 $
7
 
  Version:   $Revision: 1.36.2.1 $
8
 
 
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.
11
 
 
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.
15
 
 
16
 
=========================================================================*/
 
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
============================================================================*/
17
12
#include "windows.h" // this must be first to define GetCurrentDirectory
18
13
#include "cmGlobalVisualStudio8Generator.h"
19
14
#include "cmLocalVisualStudio7Generator.h"
115
110
}
116
111
 
117
112
//----------------------------------------------------------------------------
118
 
void cmGlobalVisualStudio8Generator::Generate()
 
113
void cmGlobalVisualStudio8Generator::AddCheckTarget()
119
114
{
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)
126
 
    {
127
 
    std::vector<cmLocalGenerator*>& generators = it->second;
128
 
    if(!generators.empty())
129
 
      {
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();
135
 
 
136
 
      // Skip the target if no regeneration is to be done.
137
 
      if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
138
 
        {
139
 
        continue;
140
 
        }
141
 
 
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,
146
 
                            noCommandLines);
147
 
      cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
148
 
      if(!tgt)
149
 
        {
150
 
        cmSystemTools::Error("Error adding target " 
151
 
                             CMAKE_CHECK_BUILD_SYSTEM_TARGET);
152
 
        continue;
153
 
        }
154
 
 
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";
159
 
      {
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)
168
 
        {
169
 
        stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
170
 
        stampFile += "/";
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);
177
 
        }
178
 
      }
179
 
 
180
 
      // Add a custom rule to re-run CMake if any input files changed.
181
 
      {
182
 
      // Collect the input files used to generate all targets in this
183
 
      // project.
184
 
      std::vector<std::string> listFiles;
185
 
      for(unsigned int j = 0; j < generators.size(); ++j)
186
 
        {
187
 
        cmMakefile* lmf = generators[j]->GetMakefile();
188
 
        listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
189
 
                         lmf->GetListFiles().end());
190
 
        }
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());
197
 
 
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);
220
 
 
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(
228
 
        stamps, listFiles,
229
 
        no_main_dependency, commandLines, "Checking Build System",
230
 
        no_working_directory, true);
231
 
      std::string ruleName = stamps[0];
232
 
      ruleName += ".rule";
233
 
      if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
234
 
        {
235
 
        tgt->AddSourceFile(file);
236
 
        }
237
 
      else
238
 
        {
239
 
        cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
240
 
        }
241
 
      }
 
119
  std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
 
120
  cmLocalVisualStudio7Generator* lg =
 
121
    static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
 
122
  cmMakefile* mf = lg->GetMakefile();
 
123
 
 
124
  // Skip the target if no regeneration is to be done.
 
125
  if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
 
126
    {
 
127
    return;
 
128
    }
 
129
 
 
130
  std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
 
131
  cmCustomCommandLines noCommandLines;
 
132
  cmTarget* tgt =
 
133
    mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
 
134
                          no_working_directory, no_depends,
 
135
                          noCommandLines);
 
136
 
 
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";
 
141
  {
 
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)
 
150
    {
 
151
    stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
 
152
    stampFile += "/";
 
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);
 
159
    }
 
160
  }
 
161
 
 
162
  // Add a custom rule to re-run CMake if any input files changed.
 
163
  {
 
164
  // Collect the input files used to generate all targets in this
 
165
  // project.
 
166
  std::vector<std::string> listFiles;
 
167
  for(unsigned int j = 0; j < generators.size(); ++j)
 
168
    {
 
169
    cmMakefile* lmf = generators[j]->GetMakefile();
 
170
    listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
 
171
                     lmf->GetListFiles().end());
 
172
    }
 
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());
 
179
 
 
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);
 
202
 
 
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(
 
210
    stamps, listFiles,
 
211
    no_main_dependency, commandLines, "Checking Build System",
 
212
    no_working_directory, true);
 
213
  std::string ruleName = stamps[0];
 
214
  ruleName += ".rule";
 
215
  if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
 
216
    {
 
217
    tgt->AddSourceFile(file);
 
218
    }
 
219
  else
 
220
    {
 
221
    cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
 
222
    }
 
223
  }
 
224
}
 
225
 
 
226
//----------------------------------------------------------------------------
 
227
void cmGlobalVisualStudio8Generator::Generate()
 
228
{
 
229
  this->AddCheckTarget();
 
230
 
 
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)
 
235
    {
 
236
    if(ti->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET)
 
237
      {
 
238
      ti->second->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
242
239
      }
243
240
    }
244
241
 
247
244
}
248
245
 
249
246
//----------------------------------------------------------------------------
250
 
void cmGlobalVisualStudio8Generator::WriteSLNFile(
251
 
  std::ostream& fout, cmLocalGenerator* root,
252
 
  std::vector<cmLocalGenerator*>& generators)
253
 
{
254
 
  // Make all targets depend on their respective project's build
255
 
  // system check target.
256
 
  unsigned int i;
257
 
  for(i = 0; i < generators.size(); ++i)
258
 
    {
259
 
    if(this->IsExcluded(root, generators[i]))
260
 
      {
261
 
      continue;
262
 
      }
263
 
    cmMakefile* mf = generators[i]->GetMakefile();
264
 
    cmTargets& tgts = mf->GetTargets();
265
 
    for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
266
 
      {
267
 
      if(l->first == CMAKE_CHECK_BUILD_SYSTEM_TARGET)
268
 
        {
269
 
        for(unsigned int j = 0; j < generators.size(); ++j)
270
 
          {
271
 
          // Every target in all generators should depend on this target.
272
 
          cmMakefile* lmf = generators[j]->GetMakefile();
273
 
          cmTargets &atgts = lmf->GetTargets();
274
 
          for(cmTargets::iterator al = atgts.begin(); al != atgts.end(); ++al)
275
 
            {
276
 
            al->second.AddUtility(l->first.c_str());
277
 
            }
278
 
          }
279
 
        }
280
 
      }
281
 
    }
282
 
 
283
 
  // Now write the solution file.
284
 
  this->cmGlobalVisualStudio71Generator::WriteSLNFile(fout, root, generators);
285
 
}
286
 
 
287
 
//----------------------------------------------------------------------------
288
247
void
289
248
cmGlobalVisualStudio8Generator
290
249
::WriteSolutionConfigurations(std::ostream& fout)
322
281
}
323
282
 
324
283
//----------------------------------------------------------------------------
 
284
bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
 
285
  cmTarget& target)
 
286
{
 
287
  // Look for utility dependencies that magically link.
 
288
  for(std::set<cmStdString>::const_iterator ui =
 
289
        target.GetUtilities().begin();
 
290
      ui != target.GetUtilities().end(); ++ui)
 
291
    {
 
292
    if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
 
293
      {
 
294
      if(depTarget->GetProperty("EXTERNAL_MSPROJECT"))
 
295
        {
 
296
        // This utility dependency names an external .vcproj target.
 
297
        // We use LinkLibraryDependencies="true" to link to it without
 
298
        // predicting the .lib file location or name.
 
299
        return true;
 
300
        }
 
301
      }
 
302
    }
 
303
  return false;
 
304
}
 
305
 
 
306
//----------------------------------------------------------------------------
325
307
static cmVS7FlagTable cmVS8ExtraFlagTable[] =
326
308
327
309
  {"CallingConvention", "Gd", "cdecl", "0", 0 },
348
330
 
349
331
  {0,0,0,0,0}
350
332
};
351
 
cmVS7FlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
 
333
cmIDEFlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
352
334
{
353
335
  return cmVS8ExtraFlagTable;
354
336
}