cmLocalVisualStudio6Generator.cxx 53.2 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
/*=========================================================================

3
  Program:   CMake - Cross-Platform Makefile Generator
Ken Martin's avatar
Ken Martin committed
4
5
6
7
8
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

9
10
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
Ken Martin's avatar
Ken Martin committed
11
12
13
14
15
16
17
18
19
20
21
22

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "cmGlobalGenerator.h"
#include "cmLocalVisualStudio6Generator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmSourceFile.h"
#include "cmCacheManager.h"
23
#include "cmake.h"
Ken Martin's avatar
Ken Martin committed
24

25
26
#include <cmsys/RegularExpression.hxx>

Ken Martin's avatar
Ken Martin committed
27
28
29
30
31
32
33
34
cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator()
{
}

cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
{
}

Alexander Neundorf's avatar
   
Alexander Neundorf committed
35
36
void cmLocalVisualStudio6Generator::AddHelperCommands()
{
37
38
39
40
  std::set<cmStdString> lang;
  lang.insert("C");
  lang.insert("CXX");
  this->CreateCustomTargetsAndCommands(lang);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
41
42
43
44
}

void cmLocalVisualStudio6Generator::Generate()
{
Ken Martin's avatar
Ken Martin committed
45
46
47
48
49
50
  this->OutputDSPFile();
}

void cmLocalVisualStudio6Generator::OutputDSPFile()
{ 
  // If not an in source build, then create the output directory
Ken Martin's avatar
Ken Martin committed
51
52
  if(strcmp(this->Makefile->GetStartOutputDirectory(),
            this->Makefile->GetHomeDirectory()) != 0)
Ken Martin's avatar
Ken Martin committed
53
    {
Ken Martin's avatar
Ken Martin committed
54
55
    if(!cmSystemTools::MakeDirectory
       (this->Makefile->GetStartOutputDirectory()))
Ken Martin's avatar
Ken Martin committed
56
57
      {
      cmSystemTools::Error("Error creating directory ",
Ken Martin's avatar
Ken Martin committed
58
                           this->Makefile->GetStartOutputDirectory());
Ken Martin's avatar
Ken Martin committed
59
60
61
      }
    }

62
63
64
65
66
67
  // Setup /I and /LIBPATH options for the resulting DSP file.  VS 6
  // truncates long include paths so make it as short as possible if
  // the length threatents this problem.
  unsigned int maxIncludeLength = 3000;
  bool useShortPath = false;
  for(int j=0; j < 2; ++j)
Ken Martin's avatar
Ken Martin committed
68
    {
69
70
71
72
73
    std::vector<std::string> includes;
    this->GetIncludeDirectories(includes);
    std::vector<std::string>::iterator i;
    for(i = includes.begin(); i != includes.end(); ++i)
      {
Ken Martin's avatar
Ken Martin committed
74
75
      std::string tmp = 
        this->ConvertToOptionallyRelativeOutputPath(i->c_str());
76
77
78
79
      if(useShortPath)
        {
        cmSystemTools::GetShortPath(tmp.c_str(), tmp);
        }
Ken Martin's avatar
Ken Martin committed
80
      this->IncludeOptions +=  " /I ";
Ken Martin's avatar
Ken Martin committed
81

82
83
84
      // quote if not already quoted
      if (tmp[0] != '"')
        {
Ken Martin's avatar
Ken Martin committed
85
86
87
        this->IncludeOptions += "\"";
        this->IncludeOptions += tmp;
        this->IncludeOptions += "\"";
88
89
90
        }
      else
        {
Ken Martin's avatar
Ken Martin committed
91
        this->IncludeOptions += tmp;
92
93
        }
      }
Ken Martin's avatar
Ken Martin committed
94
    if(j == 0 && this->IncludeOptions.size() > maxIncludeLength)
Ken Martin's avatar
Ken Martin committed
95
      {
Ken Martin's avatar
Ken Martin committed
96
      this->IncludeOptions = "";
97
      useShortPath = true;
Ken Martin's avatar
Ken Martin committed
98
99
100
      }
    else
      {
101
      break;
Ken Martin's avatar
Ken Martin committed
102
103
104
105
106
107
      }
    }
  
  // Create the DSP or set of DSP's for libraries and executables

  // clear project names
Ken Martin's avatar
Ken Martin committed
108
109
  this->CreatedProjectNames.clear();
  cmTargets &tgts = this->Makefile->GetTargets(); 
110
111
112
  for(cmTargets::iterator l = tgts.begin(); 
      l != tgts.end(); l++)
    {
113
114
115
    // Add a rule to regenerate the build system when the target
    // specification source changes.
    const char* suppRegenRule =
Ken Martin's avatar
Ken Martin committed
116
      this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
117
118
119
120
    if (!cmSystemTools::IsOn(suppRegenRule))
      {
      this->AddDSPBuildRule(l->second);
      }
121
    }
122

Ken Martin's avatar
Ken Martin committed
123
124
125
126
127
128
129
  // build any targets
  for(cmTargets::iterator l = tgts.begin(); 
      l != tgts.end(); l++)
    {
    switch(l->second.GetType())
      {
      case cmTarget::STATIC_LIBRARY:
Brad King's avatar
Brad King committed
130
        this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
131
132
        break;
      case cmTarget::SHARED_LIBRARY:
Ken Martin's avatar
Ken Martin committed
133
      case cmTarget::MODULE_LIBRARY:
Brad King's avatar
Brad King committed
134
        this->SetBuildType(DLL, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
135
136
        break;
      case cmTarget::EXECUTABLE:
Brad King's avatar
Brad King committed
137
        this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
138
139
        break;
      case cmTarget::UTILITY:
140
      case cmTarget::GLOBAL_TARGET:
Brad King's avatar
Brad King committed
141
        this->SetBuildType(UTILITY, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
142
143
        break;
      default:
144
145
        cmSystemTools::Error("Bad target type", l->first.c_str());
        break;
Ken Martin's avatar
Ken Martin committed
146
147
148
      }
    // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
    // so don't build a projectfile for it
149
    if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
Ken Martin's avatar
Ken Martin committed
150
151
152
153
154
      {
      // check to see if the dsp is going into a sub-directory
      std::string::size_type pos = l->first.rfind('/');
      if(pos != std::string::npos)
        {
Ken Martin's avatar
Ken Martin committed
155
        std::string dir = this->Makefile->GetStartOutputDirectory();
Ken Martin's avatar
Ken Martin committed
156
157
158
159
160
161
162
163
164
165
166
167
        dir += "/";
        dir += l->first.substr(0, pos);
        if(!cmSystemTools::MakeDirectory(dir.c_str()))
          {
          cmSystemTools::Error("Error creating directory ", dir.c_str());
          }
        }
      this->CreateSingleDSP(l->first.c_str(),l->second);
      }
    }
}

Ken Martin's avatar
Ken Martin committed
168
169
void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, 
                                                    cmTarget &target)
Ken Martin's avatar
Ken Martin committed
170
171
172
{
  // add to the list of projects
  std::string pname = lname;
Ken Martin's avatar
Ken Martin committed
173
  this->CreatedProjectNames.push_back(pname);
Ken Martin's avatar
Ken Martin committed
174
175
  // create the dsp.cmake file
  std::string fname;
Ken Martin's avatar
Ken Martin committed
176
  fname = this->Makefile->GetStartOutputDirectory();
Ken Martin's avatar
Ken Martin committed
177
178
179
180
181
182
183
184
185
186
  fname += "/";
  fname += lname;
  fname += ".dsp";
  // save the name of the real dsp file
  std::string realDSP = fname;
  fname += ".cmake";
  std::ofstream fout(fname.c_str());
  if(!fout)
    {
    cmSystemTools::Error("Error Writing ", fname.c_str());
187
    cmSystemTools::ReportLastSystemError("");
Ken Martin's avatar
Ken Martin committed
188
189
190
191
192
193
194
195
    }
  this->WriteDSPFile(fout,lname,target);
  fout.close();
  // if the dsp file has changed, then write it.
  cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
}


196
void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
Ken Martin's avatar
Ken Martin committed
197
{
198
  std::string dspname = tgt.GetName();
Ken Martin's avatar
Ken Martin committed
199
  dspname += ".dsp.cmake";
Ken Martin's avatar
Ken Martin committed
200
201
  const char* dsprule = 
    this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
202
203
  cmCustomCommandLine commandLine;
  commandLine.push_back(dsprule);
Ken Martin's avatar
Ken Martin committed
204
  std::string makefileIn = this->Makefile->GetStartDirectory();
205
206
  makefileIn += "/";
  makefileIn += "CMakeLists.txt";
207
208
  std::string comment = "Building Custom Rule ";
  comment += makefileIn;
209
210
  std::string args;
  args = "-H";
Ken Martin's avatar
Ken Martin committed
211
  args += this->Convert(this->Makefile->GetHomeDirectory(),
212
                        START_OUTPUT, UNCHANGED, true);
213
  commandLine.push_back(args);
214
  args = "-B";
Ken Martin's avatar
Ken Martin committed
215
  args += 
Ken Martin's avatar
Ken Martin committed
216
    this->Convert(this->Makefile->GetHomeOutputDirectory(), 
217
                  START_OUTPUT, UNCHANGED, true);
218
  commandLine.push_back(args);
Ken Martin's avatar
Ken Martin committed
219
220

  std::string configFile = 
Ken Martin's avatar
Ken Martin committed
221
    this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
Ken Martin's avatar
Ken Martin committed
222
  configFile += "/Templates/CMakeWindowsSystemConfig.cmake";
Ken Martin's avatar
Ken Martin committed
223
  std::vector<std::string> listFiles = this->Makefile->GetListFiles();
Ken Martin's avatar
Ken Martin committed
224
225
226
227
228
229
230
231
232
233
234
235
236
  bool found = false;
  for(std::vector<std::string>::iterator i = listFiles.begin();
      i != listFiles.end(); ++i)
    {
    if(*i == configFile)
      {
      found  = true;
      }
    }
  if(!found)
    {
    listFiles.push_back(configFile);
    }
237
238
239

  cmCustomCommandLines commandLines;
  commandLines.push_back(commandLine);
240
  const char* no_working_directory = 0;
241
242
243
244
  this->Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles,
                                           makefileIn.c_str(), commandLines,
                                           comment.c_str(),
                                           no_working_directory, true);
Ken Martin's avatar
Ken Martin committed
245
  if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
246
    {
247
    tgt.AddSourceFile(file);
248
249
250
251
252
    }
  else
    {
    cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
    }
Ken Martin's avatar
Ken Martin committed
253
254
255
256
}


void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, 
Bill Hoffman's avatar
Bill Hoffman committed
257
258
                                                 const char *libName,
                                                 cmTarget &target)
Ken Martin's avatar
Ken Martin committed
259
{
260
261
262
263
264
265
  // For utility targets need custom command since pre- and post-
  // build does not do anything in Visual Studio 6.  In order for the
  // rules to run in the correct order as custom commands, we need
  // special care for dependencies.  The first rule must depend on all
  // the dependencies of all the rules.  The later rules must each
  // depend only on the previous rule.
266
267
  if ((target.GetType() == cmTarget::UTILITY ||
      target.GetType() == cmTarget::GLOBAL_TARGET) &&
268
269
      (!target.GetPreBuildCommands().empty() ||
       !target.GetPostBuildCommands().empty()))
270
    {
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    // Accumulate the dependencies of all the commands.
    std::vector<std::string> depends;
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPreBuildCommands().begin();
         cr != target.GetPreBuildCommands().end(); ++cr)
      {
      depends.insert(depends.end(),
                     cr->GetDepends().begin(), cr->GetDepends().end());
      }
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPostBuildCommands().begin();
         cr != target.GetPostBuildCommands().end(); ++cr)
      {
      depends.insert(depends.end(),
                     cr->GetDepends().begin(), cr->GetDepends().end());
      }

    // Add the pre- and post-build commands in order.
289
    int count = 1;
290
291
292
293
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPreBuildCommands().begin();
         cr != target.GetPreBuildCommands().end(); ++cr)
      {
294
      this->AddUtilityCommandHack(target, count++, depends, *cr);
295
296
297
      }
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPostBuildCommands().begin();
298
299
         cr != target.GetPostBuildCommands().end(); ++cr)
      {
300
      this->AddUtilityCommandHack(target, count++, depends, *cr);
301
302
      }
    }
Ken Martin's avatar
Ken Martin committed
303
304
305
306
  
  // trace the visual studio dependencies
  std::string name = libName;
  name += ".dsp.cmake";
307

Ken Martin's avatar
Ken Martin committed
308
  // We may be modifying the source groups temporarily, so make a copy.
Ken Martin's avatar
Ken Martin committed
309
  std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
Ken Martin's avatar
Ken Martin committed
310
  
Ken Martin's avatar
Ken Martin committed
311
  // get the classes from the source lists then add them to the groups
312
  std::vector<cmSourceFile*> const & classes = target.GetSourceFiles();
313

Ken Martin's avatar
Ken Martin committed
314
315
  // now all of the source files have been properly assigned to the target
  // now stick them into source groups using the reg expressions
316
  for(std::vector<cmSourceFile*>::const_iterator i = classes.begin(); 
Ken Martin's avatar
Ken Martin committed
317
318
319
320
      i != classes.end(); i++)
    {
    // Add the file to the list of sources.
    std::string source = (*i)->GetFullPath();
Ken Martin's avatar
Ken Martin committed
321
322
    cmSourceGroup& sourceGroup = 
      this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
323
    sourceGroup.AssignSource(*i);
Ken Martin's avatar
Ken Martin committed
324
325
    // while we are at it, if it is a .rule file then for visual studio 6 we
    // must generate it
326
    if ((*i)->GetExtension() == "rule")
Ken Martin's avatar
Ken Martin committed
327
328
329
      {
      if(!cmSystemTools::FileExists(source.c_str()))
        {
330
        cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
Ken Martin's avatar
Ken Martin committed
331
332
#if defined(_WIN32) || defined(__CYGWIN__)
        std::ofstream fout(source.c_str(), 
Ken Martin's avatar
Ken Martin committed
333
334
                           std::ios::binary | std::ios::out 
                           | std::ios::trunc);
Ken Martin's avatar
Ken Martin committed
335
336
337
338
339
340
341
342
343
344
345
346
#else
        std::ofstream fout(source.c_str(), 
                           std::ios::out | std::ios::trunc);
#endif
        if(fout)
          {
          fout.write("# generated from CMake",22);
          fout.flush();
          fout.close();
          }
        }
      }
Ken Martin's avatar
Ken Martin committed
347
    }
348
349
350

  // Compute which sources need unique object computation.
  this->ComputeObjectNameRequirements(sourceGroups);
Ken Martin's avatar
Ken Martin committed
351
352
353
354
  
  // Write the DSP file's header.
  this->WriteDSPHeader(fout, libName, target, sourceGroups);
  
355

Ken Martin's avatar
Ken Martin committed
356
357
358
359
  // Loop through every source group.
  for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
      sg != sourceGroups.end(); ++sg)
    {
Bill Hoffman's avatar
Bill Hoffman committed
360
361
362
363
364
365
366
    this->WriteGroup(&(*sg), target, fout, libName);
    }  

  // Write the DSP file's footer.
  this->WriteDSPFooter(fout);
}

Ken Martin's avatar
Ken Martin committed
367
368
369
void cmLocalVisualStudio6Generator
::WriteGroup(const cmSourceGroup *sg, cmTarget target, 
             std::ostream &fout, const char *libName)
Bill Hoffman's avatar
Bill Hoffman committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{
  const std::vector<const cmSourceFile *> &sourceFiles = 
    sg->GetSourceFiles();
  // If the group is empty, don't write it at all.
        
  if(sourceFiles.empty())
    { 
    return; 
    }
    
  // If the group has a name, write the header.
  std::string name = sg->GetName();
  if(name != "")
    {
    this->WriteDSPBeginGroup(fout, name.c_str(), "");
    }
386
387
388
389
390
391
392

  // Compute the maximum length of a configuration name.
  std::string::size_type config_len_max = 0;
  for(std::vector<std::string>::iterator i = this->Configurations.begin();
      i != this->Configurations.end(); ++i)
    {
    // Strip the subdirectory name out of the configuration name.
393
    std::string config = this->GetConfigName(*i);
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
    if(config.size() > config_len_max)
      {
      config_len_max = config.size();
      }
    }

  // Compute the maximum length of the full path to the intermediate
  // files directory for any configuration.  This is used to construct
  // object file names that do not produce paths that are too long.
  std::string::size_type dir_len = 0;
  dir_len += strlen(this->Makefile->GetCurrentOutputDirectory());
  dir_len += 1;
  dir_len += config_len_max;
  dir_len += 1;

Bill Hoffman's avatar
Bill Hoffman committed
409
410
411
412
413
414
415
416
417
  // Loop through each source in the source group.
  for(std::vector<const cmSourceFile *>::const_iterator sf =
        sourceFiles.begin(); sf != sourceFiles.end(); ++sf)
    {
    std::string source = (*sf)->GetFullPath();
    const cmCustomCommand *command = 
      (*sf)->GetCustomCommand();
    std::string compileFlags;
    std::vector<std::string> depends;
418
419
420
421
422
    std::string objectNameDir;
    if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
      {
      objectNameDir =
        cmSystemTools::GetFilenamePath(
423
          this->GetObjectFileNameWithoutTarget(*(*sf), dir_len));
424
      }
425
426
427

    // Add per-source file flags.
    if(const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS"))
428
      {
429
      compileFlags += cflags;
430
431
      }

432
    const char* lang = this->GetSourceFileLanguage(*(*sf));
Bill Hoffman's avatar
Bill Hoffman committed
433
    if(lang)
Ken Martin's avatar
Ken Martin committed
434
      {
Bill Hoffman's avatar
Bill Hoffman committed
435
436
437
438
439
440
441
442
443
444
      if(strcmp(lang, "CXX") == 0)
        {
        // force a C++ file type
        compileFlags += " /TP ";
        } 
      else if(strcmp(lang, "C") == 0)
        {
        // force to c file type
        compileFlags += " /TC ";
        }
Bill Hoffman's avatar
Bill Hoffman committed
445
446
447
448
449
450
451
452
      }
      
    // Check for extra object-file dependencies.
    const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
    if(dependsValue)
      {
      cmSystemTools::ExpandListArgument(dependsValue, depends);
      }
453
454
    if (source != libName || target.GetType() == cmTarget::UTILITY ||
      target.GetType() == cmTarget::GLOBAL_TARGET)
Bill Hoffman's avatar
Bill Hoffman committed
455
456
457
458
459
460
461
462
      {
      fout << "# Begin Source File\n\n";
        
      // Tell MS-Dev what the source is.  If the compiler knows how to
      // build it, then it will.
      fout << "SOURCE=" << 
        this->ConvertToOptionallyRelativeOutputPath(source.c_str()) << "\n\n";
      if(!depends.empty())
463
        {
Bill Hoffman's avatar
Bill Hoffman committed
464
465
466
467
468
469
470
471
472
        // Write out the dependencies for the rule.
        fout << "USERDEP__HACK=";
        for(std::vector<std::string>::const_iterator d = depends.begin();
            d != depends.end(); ++d)
          { 
          fout << "\\\n\t" << 
            this->ConvertToOptionallyRelativeOutputPath(d->c_str());
          }
        fout << "\n";
473
        }
Bill Hoffman's avatar
Bill Hoffman committed
474
      if (command)
475
        {
Bill Hoffman's avatar
Bill Hoffman committed
476
        const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
477
        this->WriteCustomRule(fout, source.c_str(), *command, flags);
Ken Martin's avatar
Ken Martin committed
478
        }
479
      else if(!compileFlags.empty() || !objectNameDir.empty())
Ken Martin's avatar
Ken Martin committed
480
        {
Bill Hoffman's avatar
Bill Hoffman committed
481
        for(std::vector<std::string>::iterator i
Ken Martin's avatar
Ken Martin committed
482
483
              = this->Configurations.begin(); 
            i != this->Configurations.end(); ++i)
Bill Hoffman's avatar
Bill Hoffman committed
484
          { 
Ken Martin's avatar
Ken Martin committed
485
          if (i == this->Configurations.begin())
Bill Hoffman's avatar
Bill Hoffman committed
486
487
            {
            fout << "!IF  \"$(CFG)\" == " << i->c_str() << std::endl;
488
            }
Bill Hoffman's avatar
Bill Hoffman committed
489
490
491
492
          else 
            {
            fout << "!ELSEIF  \"$(CFG)\" == " << i->c_str() << std::endl;
            }
493
494
495
496
497
498
499
          if(!compileFlags.empty())
            {
            fout << "\n# ADD CPP " << compileFlags << "\n\n";
            }
          if(!objectNameDir.empty())
            {
            // Strip the subdirectory name out of the configuration name.
500
            std::string config = this->GetConfigName(*i);
501
502
503
504
505

            // Setup an alternate object file directory.
            fout << "\n# PROP Intermediate_Dir \""
                 << config << "/" << objectNameDir << "\"\n\n";
            }
Bill Hoffman's avatar
Bill Hoffman committed
506
507
          } 
        fout << "!ENDIF\n\n";
Ken Martin's avatar
Ken Martin committed
508
        }
Bill Hoffman's avatar
Bill Hoffman committed
509
      fout << "# End Source File\n";
Ken Martin's avatar
Ken Martin committed
510
      }
Bill Hoffman's avatar
Bill Hoffman committed
511
512
513
514
515
516
517
518
519
520
521
    }

  std::vector<cmSourceGroup> children  = sg->GetGroupChildren();

  for(unsigned int i=0;i<children.size();++i)
    {
    this->WriteGroup(&children[i], target, fout, libName);
    }



Ken Martin's avatar
Ken Martin committed
522
    
Bill Hoffman's avatar
Bill Hoffman committed
523
524
525
526
527
  // If the group has a name, write the footer.
  if(name != "")
    {
    this->WriteDSPEndGroup(fout);
    }
Ken Martin's avatar
Ken Martin committed
528
529
530
531

}


532
533
534
535
void
cmLocalVisualStudio6Generator
::AddUtilityCommandHack(cmTarget& target, int count,
                        std::vector<std::string>& depends,
536
                        const cmCustomCommand& origCommand)
537
538
{
  // Create a fake output that forces the rule to run.
Ken Martin's avatar
Ken Martin committed
539
  char* output = new char[(strlen(this->Makefile->GetStartOutputDirectory()) +
540
                           strlen(target.GetName()) + 30)];
Ken Martin's avatar
Ken Martin committed
541
  sprintf(output,"%s/%s_force_%i", this->Makefile->GetStartOutputDirectory(),
542
          target.GetName(), count);
543
  std::string comment = this->ConstructComment(origCommand, "<hack>");
544
545
546

  // Add the rule with the given dependencies and commands.
  const char* no_main_dependency = 0;
Ken Martin's avatar
Ken Martin committed
547
  this->Makefile->AddCustomCommandToOutput(output,
548
549
                                       depends,
                                       no_main_dependency,
550
                                       origCommand.GetCommandLines(),
551
                                       comment.c_str(),
552
                                       origCommand.GetWorkingDirectory());
553
554
555
556
557
558
559

  // Replace the dependencies with the output of this rule so that the
  // next rule added will run after this one.
  depends.clear();
  depends.push_back(output);

  // Add a source file representing this output to the project.
Ken Martin's avatar
Ken Martin committed
560
  cmSourceFile* outsf = this->Makefile->GetSourceFileWithOutput(output);
561
  target.AddSourceFile(outsf);
562
563
564
565
566

  // Free the fake output name.
  delete [] output;
}

567
568
569
570
void
cmLocalVisualStudio6Generator
::WriteCustomRule(std::ostream& fout,
                  const char* source,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
571
                  const cmCustomCommand& command,
572
                  const char* flags)
Ken Martin's avatar
Ken Martin committed
573
{
Alexander Neundorf's avatar
   
Alexander Neundorf committed
574
575
576
577
578
579
580
  std::string comment =
    this->ConstructComment(command, "Building Custom Rule $(InputPath)");
  if(comment == "<hack>")
    {
    comment = "";
    }
  
581
  // Write the rule for each configuration.
Ken Martin's avatar
Ken Martin committed
582
  std::vector<std::string>::iterator i;
Ken Martin's avatar
Ken Martin committed
583
  for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
Ken Martin's avatar
Ken Martin committed
584
    {
585
    std::string config = this->GetConfigName(*i);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
586
587
588
    std::string script =
      this->ConstructScript(command.GetCommandLines(), 
                            command.GetWorkingDirectory(),
589
                            config.c_str(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
590
591
592
593
                            command.GetEscapeOldStyle(),
                            command.GetEscapeAllowMakeVars(),
                            "\\\n\t");
      
Ken Martin's avatar
Ken Martin committed
594
    if (i == this->Configurations.begin())
Ken Martin's avatar
Ken Martin committed
595
596
597
598
599
600
601
602
603
604
605
606
607
      {
      fout << "!IF  \"$(CFG)\" == " << i->c_str() << std::endl;
      }
    else 
      {
      fout << "!ELSEIF  \"$(CFG)\" == " << i->c_str() << std::endl;
      }
    if(flags)
      {
      fout << "\n# ADD CPP " << flags << "\n\n";
      }
    // Write out the dependencies for the rule.
    fout << "USERDEP__HACK=";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
608
609
    for(std::vector<std::string>::const_iterator d = 
          command.GetDepends().begin();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
610
611
        d != command.GetDepends().end(); 
        ++d)
Ken Martin's avatar
Ken Martin committed
612
      {
613
      // Lookup the real name of the dependency in case it is a CMake target.
614
615
      std::string dep = this->GetRealDependency(d->c_str(),
                                                config.c_str());
616
617
      fout << "\\\n\t" <<
        this->ConvertToOptionallyRelativeOutputPath(dep.c_str());
Ken Martin's avatar
Ken Martin committed
618
619
620
621
      }
    fout << "\n";

    fout << "# PROP Ignore_Default_Tool 1\n";
622
    fout << "# Begin Custom Build -";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
623
    if(!comment.empty())
624
      {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
625
      fout << " " << comment.c_str();
626
627
      }
    fout << "\n\n";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
628
    if(command.GetOutputs().empty())
Ken Martin's avatar
Ken Martin committed
629
      {
Ken Martin's avatar
Ken Martin committed
630
631
      fout << source 
           << "_force :  \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
632
      fout << script.c_str() << "\n\n";
Ken Martin's avatar
Ken Martin committed
633
      }
634
635
    else
      {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
636
637
638
639
      for(std::vector<std::string>::const_iterator o = 
          command.GetOutputs().begin();
          o != command.GetOutputs().end(); 
          ++o)
640
641
642
643
        {
        // Write a rule for every output generated by this command.
        fout << this->ConvertToOptionallyRelativeOutputPath(o->c_str())
             << " :  \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
644
        fout << script.c_str() << "\n\n";
645
646
        }
      }
Ken Martin's avatar
Ken Martin committed
647
648
649
650
651
652
653
654
    fout << "# End Custom Build\n\n";
    }
  
  fout << "!ENDIF\n\n";
}


void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout, 
Bill Hoffman's avatar
Bill Hoffman committed
655
656
                                                       const char* group,
                                                       const char* filter)
Ken Martin's avatar
Ken Martin committed
657
658
659
660
661
662
663
664
665
666
667
668
669
670
{
  fout << "# Begin Group \"" << group << "\"\n"
    "# PROP Default_Filter \"" << filter << "\"\n";
}


void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout)
{
  fout << "# End Group\n";
}




Brad King's avatar
Brad King committed
671
672
void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
                                                 const char* libName,
673
                                                 cmTarget& target)
Ken Martin's avatar
Ken Martin committed
674
{
Ken Martin's avatar
Ken Martin committed
675
  std::string root= this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
Ken Martin's avatar
Ken Martin committed
676
677
  const char *def= 
    this->Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
Ken Martin's avatar
Ken Martin committed
678
679
680
681
682
683
684
685
686
687
688
689
690

  if( def)
    {
    root = def;
    }
  else
    {
    root += "/Templates";
    }
  
  switch(b)
    {
    case STATIC_LIBRARY:
Ken Martin's avatar
Ken Martin committed
691
692
693
694
      this->DSPHeaderTemplate = root;
      this->DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
      this->DSPFooterTemplate = root;
      this->DSPFooterTemplate += "/staticLibFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
695
696
      break;
    case DLL:
Ken Martin's avatar
Ken Martin committed
697
698
699
700
      this->DSPHeaderTemplate =  root;
      this->DSPHeaderTemplate += "/DLLHeader.dsptemplate";
      this->DSPFooterTemplate =  root;
      this->DSPFooterTemplate += "/DLLFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
701
702
      break;
    case EXECUTABLE:
703
704
      if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
        {
Ken Martin's avatar
Ken Martin committed
705
706
707
708
        this->DSPHeaderTemplate = root;
        this->DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
        this->DSPFooterTemplate = root;
        this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
709
710
711
        }
      else
        {
Ken Martin's avatar
Ken Martin committed
712
713
714
715
        this->DSPHeaderTemplate = root;
        this->DSPHeaderTemplate += "/EXEHeader.dsptemplate";
        this->DSPFooterTemplate = root;
        this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
716
        }
Ken Martin's avatar
Ken Martin committed
717
718
      break;
    case UTILITY:
Ken Martin's avatar
Ken Martin committed
719
720
721
722
      this->DSPHeaderTemplate = root;
      this->DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
      this->DSPFooterTemplate = root;
      this->DSPFooterTemplate += "/UtilityFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
723
724
725
726
727
      break;
    }

  // once the build type is set, determine what configurations are
  // possible
Ken Martin's avatar
Ken Martin committed
728
  std::ifstream fin(this->DSPHeaderTemplate.c_str());
Ken Martin's avatar
Ken Martin committed
729

730
  cmsys::RegularExpression reg("# Name ");
Ken Martin's avatar
Ken Martin committed
731
732
  if(!fin)
    {
Ken Martin's avatar
Ken Martin committed
733
    cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
Ken Martin's avatar
Ken Martin committed
734
735
    }

Ken Martin's avatar
Ken Martin committed
736
  // reset this->Configurations
Ken Martin's avatar
Ken Martin committed
737
738
  this->Configurations.erase(this->Configurations.begin(), 
                             this->Configurations.end());
Ken Martin's avatar
Ken Martin committed
739
  // now add all the configurations possible
740
741
  std::string line;
  while(cmSystemTools::GetLineFromStream(fin, line))
Ken Martin's avatar
Ken Martin committed
742
743
744
745
    {
    cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName);
    if (reg.find(line))
      {
Ken Martin's avatar
Ken Martin committed
746
      this->Configurations.push_back(line.substr(reg.end()));
Ken Martin's avatar
Ken Martin committed
747
748
749
750
751
752
      }
    }
}

// look for custom rules on a target and collect them together
std::string 
753
cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, 
Alexander Neundorf's avatar
   
Alexander Neundorf committed
754
                                                 const char* configName, 
Ken Martin's avatar
Ken Martin committed
755
                                                 const char * /* libName */)
Ken Martin's avatar
Ken Martin committed
756
757
758
{
  std::string customRuleCode = "";

759
  if (target.GetType() >= cmTarget::UTILITY )
Ken Martin's avatar
Ken Martin committed
760
761
762
    {
    return customRuleCode;
    }
763
764
765
766
767
768
769
770
771
772

  // are there any rules?
  if (target.GetPreBuildCommands().size() + 
      target.GetPreLinkCommands().size() + 
      target.GetPostBuildCommands().size() == 0)
    {
    return customRuleCode;
    }
    
  customRuleCode = "# Begin Special Build Tool\n";
773
774
775
776
777
778
779
780
781
782
783
784
785
786

  // Write the pre-build and pre-link together (VS6 does not support
  // both).  Make sure no continuation character is put on the last
  // line.
  int prelink_total = (static_cast<int>(target.GetPreBuildCommands().size())+
                       static_cast<int>(target.GetPreLinkCommands().size()));
  int prelink_count = 0;
  if(prelink_total > 0)
    {
    // header stuff
    customRuleCode += "PreLink_Cmds=";
    }
  for (std::vector<cmCustomCommand>::const_iterator cr =
         target.GetPreBuildCommands().begin();
787
       cr != target.GetPreBuildCommands().end(); ++cr)
Ken Martin's avatar
Ken Martin committed
788
    {
789
    if(prelink_count++ > 0)
Ken Martin's avatar
Ken Martin committed
790
      {
791
      customRuleCode += "\\\n\t";
792
      }
793
    customRuleCode += this->ConstructScript(cr->GetCommandLines(),
794
                                            cr->GetWorkingDirectory(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
795
                                            configName, 
796
797
                                            cr->GetEscapeOldStyle(),
                                            cr->GetEscapeAllowMakeVars(),
798
                                            "\\\n\t");
Ken Martin's avatar
Ken Martin committed
799
    }
800
801
  for (std::vector<cmCustomCommand>::const_iterator cr =
         target.GetPreLinkCommands().begin();
802
       cr != target.GetPreLinkCommands().end(); ++cr)
Ken Martin's avatar
Ken Martin committed
803
    {
804
    if(prelink_count++ > 0)
805
      {
806
      customRuleCode += "\\\n\t";
807
      }
808
    customRuleCode += this->ConstructScript(cr->GetCommandLines(),
809
                                            cr->GetWorkingDirectory(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
810
                                            configName,
811
812
                                            cr->GetEscapeOldStyle(),
                                            cr->GetEscapeAllowMakeVars(),
813
                                            "\\\n\t");
Ken Martin's avatar
Ken Martin committed
814
    }
815
  if(prelink_total > 0)
Ken Martin's avatar
Ken Martin committed
816
817
818
    {
    customRuleCode += "\n";
    }
819
820
821

  // Write the post-build rules.  Make sure no continuation character
  // is put on the last line.
Ken Martin's avatar
Ken Martin committed
822
823
  int postbuild_total = 
    static_cast<int>(target.GetPostBuildCommands().size());
824
825
826
827
828
829
830
  int postbuild_count = 0;
  if(postbuild_total > 0)
    {
    customRuleCode += "PostBuild_Cmds=";
    }
  for (std::vector<cmCustomCommand>::const_iterator cr =
         target.GetPostBuildCommands().begin();
831
832
       cr != target.GetPostBuildCommands().end(); ++cr)
    {
833
    if(postbuild_count++ > 0)
834
      {
835
      customRuleCode += "\\\n\t";
836
      }
837
    customRuleCode += this->ConstructScript(cr->GetCommandLines(),
838
                                            cr->GetWorkingDirectory(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
839
                                            configName,
840
841
                                            cr->GetEscapeOldStyle(),
                                            cr->GetEscapeAllowMakeVars(),
842
                                            "\\\n\t");
843
844
845
846
    }
  if(postbuild_total > 0)
    {
    customRuleCode += "\n";
847
848
    }

849
  customRuleCode += "# End Special Build Tool\n";
Ken Martin's avatar
Ken Martin committed
850
851
852
853
854
855
856
857
858
859
860
861
862
  return customRuleCode;
}


inline std::string removeQuotes(const std::string& s)
{
  if(s[0] == '\"' && s[s.size()-1] == '\"')
    {
    return s.substr(1, s.size()-2);
    }
  return s;
}

863
864
865
// Code in blocks surrounded by a test for this definition is needed
// only for compatibility with user project's replacement DSP
// templates.  The CMake templates no longer use them.
866
#define CM_USE_OLD_VS6
867

868
869
void cmLocalVisualStudio6Generator
::WriteDSPHeader(std::ostream& fout, 
870
                 const char *libName, cmTarget &target, 
871
                 std::vector<cmSourceGroup> &)
Ken Martin's avatar
Ken Martin committed
872
{
873
874
875
876
  // Lookup the output directory for the target.
  std::string outPath = target.GetDirectory();

#ifdef CM_USE_OLD_VS6
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
  // Lookup the library and executable output directories.
  std::string libPath;
  if(this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
    {
    libPath = this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
    }
  std::string exePath;
  if(this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
    {
    exePath = this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
    }

  // Make sure there are trailing slashes.
  if(!libPath.empty())
    {
    if(libPath[libPath.size()-1] != '/')
      {
      libPath += "/";
      }
    }
  if(!exePath.empty())
    {
    if(exePath[exePath.size()-1] != '/')
      {
      exePath += "/";
      }
    }

Ken Martin's avatar
Ken Martin committed
905
906
907
908
909
910
911
912
  std::set<std::string> pathEmitted;
  
  // determine the link directories
  std::string libOptions;
  std::string libDebugOptions;
  std::string libOptimizedOptions;

  std::string libMultiLineOptions;
913
  std::string libMultiLineOptionsForDebug;
Ken Martin's avatar
Ken Martin committed
914
915
916
917
918
919
  std::string libMultiLineDebugOptions;
  std::string libMultiLineOptimizedOptions;

  if(libPath.size())
    {
    std::string lpath = 
920
      this->ConvertToOptionallyRelativeOutputPath(libPath.c_str());
921
922
923
924
    if(lpath.size() == 0)
      {
      lpath = ".";
      }
Ken Martin's avatar
Ken Martin committed
925
    std::string lpathIntDir = libPath + "$(INTDIR)";
Ken Martin's avatar
Ken Martin committed
926
927
    lpathIntDir =  
      this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
Ken Martin's avatar
Ken Martin committed
928
929
930
931
932
933
934
935
936
937
938
939
940
941
    if(pathEmitted.insert(lpath).second)
      {
      libOptions += " /LIBPATH:";
      libOptions += lpathIntDir;
      libOptions += " ";
      libOptions += " /LIBPATH:";
      libOptions += lpath;
      libOptions += " ";
      libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptions += lpathIntDir;
      libMultiLineOptions += " ";
      libMultiLineOptions += " /LIBPATH:";
      libMultiLineOptions += lpath;
      libMultiLineOptions += " \n";
942
943
944
945
946
947
      libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptionsForDebug += lpathIntDir;
      libMultiLineOptionsForDebug += " ";
      libMultiLineOptionsForDebug += " /LIBPATH:";
      libMultiLineOptionsForDebug += lpath;
      libMultiLineOptionsForDebug += " \n";
Ken Martin's avatar
Ken Martin committed
948
949
950
951
952
      }
    }
  if(exePath.size())
    {
    std::string lpath = 
953
      this->ConvertToOptionallyRelativeOutputPath(exePath.c_str());
954
955
956
957
    if(lpath.size() == 0)
      {
      lpath = ".";
      }
Ken Martin's avatar
Ken Martin committed
958
    std::string lpathIntDir = exePath + "$(INTDIR)";
Ken Martin's avatar
Ken Martin committed
959
960
    lpathIntDir =
      this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
Ken Martin's avatar
Ken Martin committed
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
    
    if(pathEmitted.insert(lpath).second)
      {
      libOptions += " /LIBPATH:";
      libOptions += lpathIntDir;
      libOptions += " ";
      libOptions += " /LIBPATH:";
      libOptions += lpath;
      libOptions += " ";
      libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptions += lpathIntDir;
      libMultiLineOptions += " ";
      libMultiLineOptions += " /LIBPATH:";
      libMultiLineOptions += lpath;
      libMultiLineOptions += " \n";
976
977
978
979
980
981
      libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptionsForDebug += lpathIntDir;
      libMultiLineOptionsForDebug += " ";
      libMultiLineOptionsForDebug += " /LIBPATH:";
      libMultiLineOptionsForDebug += lpath;
      libMultiLineOptionsForDebug += " \n";
Ken Martin's avatar
Ken Martin committed
982
983
984
985
986
987
988
989
990
991
992
993
      }
    }
  std::vector<std::string>::const_iterator i;
  const std::vector<std::string>& libdirs = target.GetLinkDirectories();
  for(i = libdirs.begin(); i != libdirs.end(); ++i)
    {
    std::string path = *i;
    if(path[path.size()-1] != '/')
      {
      path += "/";
      }
    std::string lpath = 
994
      this->ConvertToOptionallyRelativeOutputPath(path.c_str());
995
996
997
998
    if(lpath.size() == 0)
      {
      lpath = ".";
      }
Ken Martin's avatar
Ken Martin committed
999
    std::string lpathIntDir = path + "$(INTDIR)";
Ken Martin's avatar
Ken Martin committed
1000
1001
    lpathIntDir =
      this->ConvertToOptionallyRelativeOutputPath(lpathIntDir.c_str());
Ken Martin's avatar
Ken Martin committed
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
    if(pathEmitted.insert(lpath).second)
      {
      libOptions += " /LIBPATH:";
      libOptions += lpathIntDir;
      libOptions += " ";
      libOptions += " /LIBPATH:";
      libOptions += lpath;
      libOptions += " ";
      
      libMultiLineOptions += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptions += lpathIntDir;
      libMultiLineOptions += " ";
      libMultiLineOptions += " /LIBPATH:";
      libMultiLineOptions += lpath;
      libMultiLineOptions += " \n";
1017
1018
1019
1020
1021
1022
      libMultiLineOptionsForDebug += "# ADD LINK32 /LIBPATH:";
      libMultiLineOptionsForDebug += lpathIntDir;
      libMultiLineOptionsForDebug += " ";
      libMultiLineOptionsForDebug += " /LIBPATH:";
      libMultiLineOptionsForDebug += lpath;
      libMultiLineOptionsForDebug += " \n";
Ken Martin's avatar
Ken Martin committed
1023
1024
1025
      }
    }
  // find link libraries
Ken Martin's avatar
Ken Martin committed
1026
1027
  const cmTarget::LinkLibraryVectorType& libs = target.GetLinkLibraries();
  cmTarget::LinkLibraryVectorType::const_iterator j;
Ken Martin's avatar
Ken Martin committed
1028
1029
1030
1031
  for(j = libs.begin(); j != libs.end(); ++j)
    {
    // add libraries to executables and dlls (but never include
    // a library in a library, bad recursion)
1032
    // NEVER LINK STATIC LIBRARIES TO OTHER STATIC LIBRARIES
Ken Martin's avatar
Ken Martin committed
1033
    if ((target.GetType() != cmTarget::SHARED_LIBRARY
Ken Martin's avatar
Ken Martin committed
1034
1035
1036
1037
         && target.GetType() != cmTarget::STATIC_LIBRARY 
         && target.GetType() != cmTarget::MODULE_LIBRARY) || 
        (target.GetType()==cmTarget::SHARED_LIBRARY && libName != j->first) ||
        (target.GetType()==cmTarget::MODULE_LIBRARY && libName != j->first))
Ken Martin's avatar
Ken Martin committed
1038
      {
1039
1040
1041
      // Compute the proper name to use to link this library.
      std::string lib;
      std::string libDebug;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
1042
      cmTarget* tgt = this->GlobalGenerator->FindTarget(0, j->first.c_str(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
1043
                                                        false);
1044
      if(tgt)
Ken Martin's avatar
Ken Martin committed
1045
        {
Ken Martin's avatar
Ken Martin committed
1046
1047
1048
1049
        lib = cmSystemTools::GetFilenameWithoutExtension
          (tgt->GetFullName().c_str());
        libDebug = cmSystemTools::GetFilenameWithoutExtension
          (tgt->GetFullName("Debug").c_str());
Ken Martin's avatar
Ken Martin committed
1050
        lib += ".lib";
1051
        libDebug += ".lib";
Ken Martin's avatar
Ken Martin committed
1052
        }
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
      else
        {
        lib = j->first.c_str();
        libDebug = j->first.c_str();
        if(j->first.find(".lib") == std::string::npos)
          {
          lib += ".lib";
          libDebug += ".lib";
          }
        }
1063
      lib = this->ConvertToOptionallyRelativeOutputPath(lib.c_str());
Ken Martin's avatar
Ken Martin committed
1064
1065
      libDebug = 
        this->ConvertToOptionallyRelativeOutputPath(libDebug.c_str());
1066

Ken Martin's avatar
Ken Martin committed
1067
1068
1069
1070
1071
1072
1073
      if (j->second == cmTarget::GENERAL)
        {
        libOptions += " ";
        libOptions += lib;
        libMultiLineOptions += "# ADD LINK32 ";
        libMultiLineOptions +=  lib;
        libMultiLineOptions += "\n";
1074
1075
1076
        libMultiLineOptionsForDebug += "# ADD LINK32 ";
        libMultiLineOptionsForDebug +=  libDebug;
        libMultiLineOptionsForDebug += "\n";
Ken Martin's avatar
Ken Martin committed
1077
1078
1079
1080
1081
1082
1083
        }
      if (j->second == cmTarget::DEBUG)
        {
        libDebugOptions += " ";
        libDebugOptions += lib;

        libMultiLineDebugOptions += "# ADD LINK32 ";
1084
        libMultiLineDebugOptions += libDebug;
Ken Martin's avatar
Ken Martin committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
        libMultiLineDebugOptions += "\n";
        }
      if (j->second == cmTarget::OPTIMIZED)
        {
        libOptimizedOptions += " ";
        libOptimizedOptions += lib;

        libMultiLineOptimizedOptions += "# ADD LINK32 ";
        libMultiLineOptimizedOptions += lib;
        libMultiLineOptimizedOptions += "\n";
        }      
      }
    }
1098
#endif
1099
1100

  // Get extra linker options for this target type.
1101
1102
1103
  std::string extraLinkOptions;
  if(target.GetType() == cmTarget::EXECUTABLE)
    {
Ken Martin's avatar
Ken Martin committed
1104
1105
    extraLinkOptions = 
      this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
1106
1107
1108
    }
  if(target.GetType() == cmTarget::SHARED_LIBRARY)
    {
Ken Martin's avatar
Ken Martin committed
1109
1110
    extraLinkOptions = 
      this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS");
1111
    }
1112
1113
  if(target.GetType() == cmTarget::MODULE_LIBRARY)
    {
Ken Martin's avatar
Ken Martin committed
1114
1115
    extraLinkOptions = 
      this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS");
1116
    }
1117