cmLocalVisualStudio6Generator.cxx 56.6 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 "cmComputeLinkInformation.h"

27
28
#include <cmsys/RegularExpression.hxx>

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

cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator()
{
}

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//----------------------------------------------------------------------------
// Helper class to write build events.
class cmLocalVisualStudio6Generator::EventWriter
{
public:
  EventWriter(cmLocalVisualStudio6Generator* lg,
              const char* config, std::string& code):
    LG(lg), Config(config), Code(code), First(true) {}
  void Start(const char* event)
    {
    this->First = true;
    this->Event = event;
    }
  void Finish()
    {
    this->Code += (this->First? "" : "\n");
    }
  void Write(std::vector<cmCustomCommand> const& ccs)
    {
    for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
        ci != ccs.end(); ++ci)
      {
      this->Write(*ci);
      }
    }
  void Write(cmCustomCommand const& cc)
    {
    if(this->First)
      {
      this->Code += this->Event + "_Cmds=";
      this->First = false;
      }
    else
      {
      this->Code += "\\\n\t";
      }
    this->Code +=
      this->LG->ConstructScript(cc.GetCommandLines(),
                                cc.GetWorkingDirectory(),
                                this->Config,
                                cc.GetEscapeOldStyle(),
                                cc.GetEscapeAllowMakeVars(),
                                "\\\n\t");
    }
private:
  cmLocalVisualStudio6Generator* LG;
  const char* Config;
  std::string& Code;
  bool First;
  std::string Event;
};

Alexander Neundorf's avatar
   
Alexander Neundorf committed
89
90
void cmLocalVisualStudio6Generator::AddHelperCommands()
{
91
92
93
94
  std::set<cmStdString> lang;
  lang.insert("C");
  lang.insert("CXX");
  this->CreateCustomTargetsAndCommands(lang);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
95
96
97
98
}

void cmLocalVisualStudio6Generator::Generate()
{
Ken Martin's avatar
Ken Martin committed
99
100
101
102
103
104
  this->OutputDSPFile();
}

void cmLocalVisualStudio6Generator::OutputDSPFile()
{ 
  // If not an in source build, then create the output directory
Ken Martin's avatar
Ken Martin committed
105
106
  if(strcmp(this->Makefile->GetStartOutputDirectory(),
            this->Makefile->GetHomeDirectory()) != 0)
Ken Martin's avatar
Ken Martin committed
107
    {
Ken Martin's avatar
Ken Martin committed
108
109
    if(!cmSystemTools::MakeDirectory
       (this->Makefile->GetStartOutputDirectory()))
Ken Martin's avatar
Ken Martin committed
110
111
      {
      cmSystemTools::Error("Error creating directory ",
Ken Martin's avatar
Ken Martin committed
112
                           this->Makefile->GetStartOutputDirectory());
Ken Martin's avatar
Ken Martin committed
113
114
115
      }
    }

116
117
  // Setup /I and /LIBPATH options for the resulting DSP file.  VS 6
  // truncates long include paths so make it as short as possible if
118
  // the length threatens this problem.
119
120
121
  unsigned int maxIncludeLength = 3000;
  bool useShortPath = false;
  for(int j=0; j < 2; ++j)
Ken Martin's avatar
Ken Martin committed
122
    {
123
124
125
126
127
    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
128
129
      std::string tmp = 
        this->ConvertToOptionallyRelativeOutputPath(i->c_str());
130
131
132
133
      if(useShortPath)
        {
        cmSystemTools::GetShortPath(tmp.c_str(), tmp);
        }
Ken Martin's avatar
Ken Martin committed
134
      this->IncludeOptions +=  " /I ";
Ken Martin's avatar
Ken Martin committed
135

136
137
138
      // quote if not already quoted
      if (tmp[0] != '"')
        {
Ken Martin's avatar
Ken Martin committed
139
140
141
        this->IncludeOptions += "\"";
        this->IncludeOptions += tmp;
        this->IncludeOptions += "\"";
142
143
144
        }
      else
        {
Ken Martin's avatar
Ken Martin committed
145
        this->IncludeOptions += tmp;
146
147
        }
      }
Ken Martin's avatar
Ken Martin committed
148
    if(j == 0 && this->IncludeOptions.size() > maxIncludeLength)
Ken Martin's avatar
Ken Martin committed
149
      {
Ken Martin's avatar
Ken Martin committed
150
      this->IncludeOptions = "";
151
      useShortPath = true;
Ken Martin's avatar
Ken Martin committed
152
153
154
      }
    else
      {
155
      break;
Ken Martin's avatar
Ken Martin committed
156
157
158
159
160
161
      }
    }
  
  // Create the DSP or set of DSP's for libraries and executables

  // clear project names
Ken Martin's avatar
Ken Martin committed
162
163
  this->CreatedProjectNames.clear();
  cmTargets &tgts = this->Makefile->GetTargets(); 
164
165
166
  for(cmTargets::iterator l = tgts.begin(); 
      l != tgts.end(); l++)
    {
167
168
169
    // Add a rule to regenerate the build system when the target
    // specification source changes.
    const char* suppRegenRule =
Ken Martin's avatar
Ken Martin committed
170
      this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION");
171
172
173
174
    if (!cmSystemTools::IsOn(suppRegenRule))
      {
      this->AddDSPBuildRule(l->second);
      }
175
    }
176

Ken Martin's avatar
Ken Martin committed
177
178
179
180
181
182
183
  // 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
184
        this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
185
186
        break;
      case cmTarget::SHARED_LIBRARY:
Ken Martin's avatar
Ken Martin committed
187
      case cmTarget::MODULE_LIBRARY:
Brad King's avatar
Brad King committed
188
        this->SetBuildType(DLL, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
189
190
        break;
      case cmTarget::EXECUTABLE:
Brad King's avatar
Brad King committed
191
        this->SetBuildType(EXECUTABLE,l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
192
193
        break;
      case cmTarget::UTILITY:
194
      case cmTarget::GLOBAL_TARGET:
Brad King's avatar
Brad King committed
195
        this->SetBuildType(UTILITY, l->first.c_str(), l->second);
Ken Martin's avatar
Ken Martin committed
196
197
        break;
      default:
198
199
        cmSystemTools::Error("Bad target type", l->first.c_str());
        break;
Ken Martin's avatar
Ken Martin committed
200
201
202
      }
    // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
    // so don't build a projectfile for it
203
    if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
Ken Martin's avatar
Ken Martin committed
204
205
206
207
208
      {
      // 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
209
        std::string dir = this->Makefile->GetStartOutputDirectory();
Ken Martin's avatar
Ken Martin committed
210
211
212
213
214
215
216
217
218
219
220
221
        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);
      }
    }
}

222
223
224
225
226
// Utility function to make a valid VS6 *.dsp filename out
// of a CMake target name:
//
extern std::string GetVS6TargetName(const std::string& targetName);

Ken Martin's avatar
Ken Martin committed
227
228
void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, 
                                                    cmTarget &target)
Ken Martin's avatar
Ken Martin committed
229
230
{
  // add to the list of projects
231
232
  std::string pname = GetVS6TargetName(lname);

Ken Martin's avatar
Ken Martin committed
233
  this->CreatedProjectNames.push_back(pname);
Ken Martin's avatar
Ken Martin committed
234
235
  // create the dsp.cmake file
  std::string fname;
Ken Martin's avatar
Ken Martin committed
236
  fname = this->Makefile->GetStartOutputDirectory();
Ken Martin's avatar
Ken Martin committed
237
  fname += "/";
238
  fname += pname;
Ken Martin's avatar
Ken Martin committed
239
240
241
242
243
244
245
246
  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());
247
    cmSystemTools::ReportLastSystemError("");
Ken Martin's avatar
Ken Martin committed
248
    }
249
  this->WriteDSPFile(fout,pname.c_str(),target);
Ken Martin's avatar
Ken Martin committed
250
251
252
253
254
255
  fout.close();
  // if the dsp file has changed, then write it.
  cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str());
}


256
void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt)
Ken Martin's avatar
Ken Martin committed
257
{
258
  std::string dspname = GetVS6TargetName(tgt.GetName());
Ken Martin's avatar
Ken Martin committed
259
  dspname += ".dsp.cmake";
Ken Martin's avatar
Ken Martin committed
260
261
  const char* dsprule = 
    this->Makefile->GetRequiredDefinition("CMAKE_COMMAND");
262
263
  cmCustomCommandLine commandLine;
  commandLine.push_back(dsprule);
Ken Martin's avatar
Ken Martin committed
264
  std::string makefileIn = this->Makefile->GetStartDirectory();
265
266
  makefileIn += "/";
  makefileIn += "CMakeLists.txt";
267
268
  std::string comment = "Building Custom Rule ";
  comment += makefileIn;
269
270
  std::string args;
  args = "-H";
Ken Martin's avatar
Ken Martin committed
271
  args += this->Convert(this->Makefile->GetHomeDirectory(),
272
                        START_OUTPUT, UNCHANGED, true);
273
  commandLine.push_back(args);
274
  args = "-B";
Ken Martin's avatar
Ken Martin committed
275
  args += 
Ken Martin's avatar
Ken Martin committed
276
    this->Convert(this->Makefile->GetHomeOutputDirectory(), 
277
                  START_OUTPUT, UNCHANGED, true);
278
  commandLine.push_back(args);
Ken Martin's avatar
Ken Martin committed
279

280
  std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
281
282
283

  cmCustomCommandLines commandLines;
  commandLines.push_back(commandLine);
284
  const char* no_working_directory = 0;
285
286
287
288
  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
289
  if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str()))
290
    {
291
    tgt.AddSourceFile(file);
292
293
294
295
296
    }
  else
    {
    cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
    }
Ken Martin's avatar
Ken Martin committed
297
298
299
300
}


void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, 
Bill Hoffman's avatar
Bill Hoffman committed
301
302
                                                 const char *libName,
                                                 cmTarget &target)
Ken Martin's avatar
Ken Martin committed
303
{
304
305
306
307
308
309
  // 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.
310
311
  if ((target.GetType() == cmTarget::UTILITY ||
      target.GetType() == cmTarget::GLOBAL_TARGET) &&
312
313
      (!target.GetPreBuildCommands().empty() ||
       !target.GetPostBuildCommands().empty()))
314
    {
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
    // 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.
333
    int count = 1;
334
335
336
337
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPreBuildCommands().begin();
         cr != target.GetPreBuildCommands().end(); ++cr)
      {
338
      this->AddUtilityCommandHack(target, count++, depends, *cr);
339
340
341
      }
    for (std::vector<cmCustomCommand>::const_iterator cr =
           target.GetPostBuildCommands().begin();
342
343
         cr != target.GetPostBuildCommands().end(); ++cr)
      {
344
      this->AddUtilityCommandHack(target, count++, depends, *cr);
345
346
      }
    }
Ken Martin's avatar
Ken Martin committed
347
348
  
  // We may be modifying the source groups temporarily, so make a copy.
Ken Martin's avatar
Ken Martin committed
349
  std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
Ken Martin's avatar
Ken Martin committed
350
  
Ken Martin's avatar
Ken Martin committed
351
  // get the classes from the source lists then add them to the groups
352
  std::vector<cmSourceFile*> const & classes = target.GetSourceFiles();
353

Ken Martin's avatar
Ken Martin committed
354
355
  // now all of the source files have been properly assigned to the target
  // now stick them into source groups using the reg expressions
356
  for(std::vector<cmSourceFile*>::const_iterator i = classes.begin(); 
Ken Martin's avatar
Ken Martin committed
357
358
359
360
      i != classes.end(); i++)
    {
    // Add the file to the list of sources.
    std::string source = (*i)->GetFullPath();
Ken Martin's avatar
Ken Martin committed
361
362
    cmSourceGroup& sourceGroup = 
      this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
363
    sourceGroup.AssignSource(*i);
Ken Martin's avatar
Ken Martin committed
364
365
    // while we are at it, if it is a .rule file then for visual studio 6 we
    // must generate it
366
    if ((*i)->GetExtension() == "rule")
Ken Martin's avatar
Ken Martin committed
367
368
369
      {
      if(!cmSystemTools::FileExists(source.c_str()))
        {
370
        cmSystemTools::ReplaceString(source, "$(IntDir)/", "");
Ken Martin's avatar
Ken Martin committed
371
372
#if defined(_WIN32) || defined(__CYGWIN__)
        std::ofstream fout(source.c_str(), 
Ken Martin's avatar
Ken Martin committed
373
374
                           std::ios::binary | std::ios::out 
                           | std::ios::trunc);
Ken Martin's avatar
Ken Martin committed
375
376
377
378
379
380
381
382
383
384
385
386
#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
387
    }
388
389
390

  // Compute which sources need unique object computation.
  this->ComputeObjectNameRequirements(sourceGroups);
Ken Martin's avatar
Ken Martin committed
391
392
393
394
  
  // Write the DSP file's header.
  this->WriteDSPHeader(fout, libName, target, sourceGroups);
  
395

Ken Martin's avatar
Ken Martin committed
396
397
398
399
  // 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
400
401
402
403
404
405
406
    this->WriteGroup(&(*sg), target, fout, libName);
    }  

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

Ken Martin's avatar
Ken Martin committed
407
void cmLocalVisualStudio6Generator
408
::WriteGroup(const cmSourceGroup *sg, cmTarget& target,
Ken Martin's avatar
Ken Martin committed
409
             std::ostream &fout, const char *libName)
Bill Hoffman's avatar
Bill Hoffman committed
410
411
412
413
414
{
  const std::vector<const cmSourceFile *> &sourceFiles = 
    sg->GetSourceFiles();
  // If the group is empty, don't write it at all.
        
415
  if(sourceFiles.empty() && sg->GetGroupChildren().empty())
Bill Hoffman's avatar
Bill Hoffman committed
416
417
418
419
420
421
422
423
424
425
    { 
    return; 
    }
    
  // If the group has a name, write the header.
  std::string name = sg->GetName();
  if(name != "")
    {
    this->WriteDSPBeginGroup(fout, name.c_str(), "");
    }
426

427
428
  // Compute the maximum length configuration name.
  std::string config_max;
429
430
431
432
  for(std::vector<std::string>::iterator i = this->Configurations.begin();
      i != this->Configurations.end(); ++i)
    {
    // Strip the subdirectory name out of the configuration name.
433
    std::string config = this->GetConfigName(*i);
434
    if(config.size() > config_max.size())
435
      {
436
      config_max = config;
437
438
439
      }
    }

440
  // Compute the maximum length full path to the intermediate
441
442
  // files directory for any configuration.  This is used to construct
  // object file names that do not produce paths that are too long.
443
444
445
446
447
  std::string dir_max;
  dir_max += this->Makefile->GetCurrentOutputDirectory();
  dir_max += "/";
  dir_max += config_max;
  dir_max += "/";
448

Bill Hoffman's avatar
Bill Hoffman committed
449
450
451
452
453
454
455
456
457
  // 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;
458
459
460
461
462
    std::string objectNameDir;
    if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end())
      {
      objectNameDir =
        cmSystemTools::GetFilenamePath(
463
          this->GetObjectFileNameWithoutTarget(*(*sf), dir_max));
464
      }
465
466
467

    // Add per-source file flags.
    if(const char* cflags = (*sf)->GetProperty("COMPILE_FLAGS"))
468
      {
469
      compileFlags += cflags;
470
471
      }

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
    const char* lang = this->GetSourceFileLanguage(*(*sf));
    if(lang)
      {
      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 ";
        }
      }

487
488
489
    // Add per-source and per-configuration preprocessor definitions.
    std::map<cmStdString, cmStdString> cdmap;
    this->AppendDefines(compileFlags,
490
                        (*sf)->GetProperty("COMPILE_DEFINITIONS"), lang);
491
    if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_DEBUG"))
492
      {
493
      this->AppendDefines(cdmap["DEBUG"], cdefs, lang);
494
      }
495
    if(const char* cdefs = (*sf)->GetProperty("COMPILE_DEFINITIONS_RELEASE"))
496
      {
497
      this->AppendDefines(cdmap["RELEASE"], cdefs, lang);
498
499
      }
    if(const char* cdefs =
500
       (*sf)->GetProperty("COMPILE_DEFINITIONS_MINSIZEREL"))
501
      {
502
      this->AppendDefines(cdmap["MINSIZEREL"], cdefs, lang);
503
504
      }
    if(const char* cdefs =
505
       (*sf)->GetProperty("COMPILE_DEFINITIONS_RELWITHDEBINFO"))
506
      {
507
      this->AppendDefines(cdmap["RELWITHDEBINFO"], cdefs, lang);
Bill Hoffman's avatar
Bill Hoffman committed
508
      }
509
510
511

    bool excludedFromBuild =
      (lang && (*sf)->GetPropertyAsBool("HEADER_FILE_ONLY"));
Bill Hoffman's avatar
Bill Hoffman committed
512
513
514
515
516
517
518
      
    // Check for extra object-file dependencies.
    const char* dependsValue = (*sf)->GetProperty("OBJECT_DEPENDS");
    if(dependsValue)
      {
      cmSystemTools::ExpandListArgument(dependsValue, depends);
      }
519
520
    if (GetVS6TargetName(source) != libName ||
      target.GetType() == cmTarget::UTILITY ||
521
      target.GetType() == cmTarget::GLOBAL_TARGET)
Bill Hoffman's avatar
Bill Hoffman committed
522
523
524
525
526
527
528
529
      {
      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())
530
        {
Bill Hoffman's avatar
Bill Hoffman committed
531
532
533
534
535
536
537
538
539
        // 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";
540
        }
Bill Hoffman's avatar
Bill Hoffman committed
541
      if (command)
542
        {
Bill Hoffman's avatar
Bill Hoffman committed
543
        const char* flags = compileFlags.size() ? compileFlags.c_str(): 0;
Alexander Neundorf's avatar
   
Alexander Neundorf committed
544
        this->WriteCustomRule(fout, source.c_str(), *command, flags);
Ken Martin's avatar
Ken Martin committed
545
        }
546
      else if(!compileFlags.empty() || !objectNameDir.empty() ||
547
              excludedFromBuild || !cdmap.empty())
Ken Martin's avatar
Ken Martin committed
548
        {
Bill Hoffman's avatar
Bill Hoffman committed
549
        for(std::vector<std::string>::iterator i
Ken Martin's avatar
Ken Martin committed
550
551
              = this->Configurations.begin(); 
            i != this->Configurations.end(); ++i)
Bill Hoffman's avatar
Bill Hoffman committed
552
          { 
553
554
          // Strip the subdirectory name out of the configuration name.
          std::string config = this->GetConfigName(*i);
Ken Martin's avatar
Ken Martin committed
555
          if (i == this->Configurations.begin())
Bill Hoffman's avatar
Bill Hoffman committed
556
557
            {
            fout << "!IF  \"$(CFG)\" == " << i->c_str() << std::endl;
558
            }
Bill Hoffman's avatar
Bill Hoffman committed
559
560
561
562
          else 
            {
            fout << "!ELSEIF  \"$(CFG)\" == " << i->c_str() << std::endl;
            }
563
564
565
566
          if(excludedFromBuild)
            {
            fout << "# PROP Exclude_From_Build 1\n";
            }
567
568
569
570
          if(!compileFlags.empty())
            {
            fout << "\n# ADD CPP " << compileFlags << "\n\n";
            }
571
572
573
574
575
576
          std::map<cmStdString, cmStdString>::iterator cdi =
            cdmap.find(cmSystemTools::UpperCase(config));
          if(cdi != cdmap.end() && !cdi->second.empty())
            {
            fout << "\n# ADD CPP " << cdi->second << "\n\n";
            }
577
578
579
580
581
582
          if(!objectNameDir.empty())
            {
            // Setup an alternate object file directory.
            fout << "\n# PROP Intermediate_Dir \""
                 << config << "/" << objectNameDir << "\"\n\n";
            }
Bill Hoffman's avatar
Bill Hoffman committed
583
584
          } 
        fout << "!ENDIF\n\n";
Ken Martin's avatar
Ken Martin committed
585
        }
Bill Hoffman's avatar
Bill Hoffman committed
586
      fout << "# End Source File\n";
Ken Martin's avatar
Ken Martin committed
587
      }
Bill Hoffman's avatar
Bill Hoffman committed
588
589
    }

590
  std::vector<cmSourceGroup> const& children  = sg->GetGroupChildren();
Bill Hoffman's avatar
Bill Hoffman committed
591
592
593
594
595
596
597
598

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



Ken Martin's avatar
Ken Martin committed
599
    
Bill Hoffman's avatar
Bill Hoffman committed
600
601
602
603
604
  // If the group has a name, write the footer.
  if(name != "")
    {
    this->WriteDSPEndGroup(fout);
    }
Ken Martin's avatar
Ken Martin committed
605
606
607
608

}


609
610
611
612
void
cmLocalVisualStudio6Generator
::AddUtilityCommandHack(cmTarget& target, int count,
                        std::vector<std::string>& depends,
613
                        const cmCustomCommand& origCommand)
614
615
{
  // Create a fake output that forces the rule to run.
Ken Martin's avatar
Ken Martin committed
616
  char* output = new char[(strlen(this->Makefile->GetStartOutputDirectory()) +
617
                           strlen(target.GetName()) + 30)];
Ken Martin's avatar
Ken Martin committed
618
  sprintf(output,"%s/%s_force_%i", this->Makefile->GetStartOutputDirectory(),
619
          target.GetName(), count);
620
  std::string comment = this->ConstructComment(origCommand, "<hack>");
621
622
623

  // Add the rule with the given dependencies and commands.
  const char* no_main_dependency = 0;
Ken Martin's avatar
Ken Martin committed
624
  this->Makefile->AddCustomCommandToOutput(output,
625
626
                                       depends,
                                       no_main_dependency,
627
                                       origCommand.GetCommandLines(),
628
                                       comment.c_str(),
629
                                       origCommand.GetWorkingDirectory());
630
631
632
633
634
635
636

  // 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
637
  cmSourceFile* outsf = this->Makefile->GetSourceFileWithOutput(output);
638
  target.AddSourceFile(outsf);
639
640
641
642
643

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

644
645
646
647
void
cmLocalVisualStudio6Generator
::WriteCustomRule(std::ostream& fout,
                  const char* source,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
648
                  const cmCustomCommand& command,
649
                  const char* flags)
Ken Martin's avatar
Ken Martin committed
650
{
Alexander Neundorf's avatar
   
Alexander Neundorf committed
651
652
653
654
655
656
657
  std::string comment =
    this->ConstructComment(command, "Building Custom Rule $(InputPath)");
  if(comment == "<hack>")
    {
    comment = "";
    }
  
658
  // Write the rule for each configuration.
Ken Martin's avatar
Ken Martin committed
659
  std::vector<std::string>::iterator i;
Ken Martin's avatar
Ken Martin committed
660
  for(i = this->Configurations.begin(); i != this->Configurations.end(); ++i)
Ken Martin's avatar
Ken Martin committed
661
    {
662
    std::string config = this->GetConfigName(*i);
Alexander Neundorf's avatar
   
Alexander Neundorf committed
663
664
665
    std::string script =
      this->ConstructScript(command.GetCommandLines(), 
                            command.GetWorkingDirectory(),
666
                            config.c_str(),
Alexander Neundorf's avatar
   
Alexander Neundorf committed
667
668
669
670
                            command.GetEscapeOldStyle(),
                            command.GetEscapeAllowMakeVars(),
                            "\\\n\t");
      
Ken Martin's avatar
Ken Martin committed
671
    if (i == this->Configurations.begin())
Ken Martin's avatar
Ken Martin committed
672
673
674
675
676
677
678
679
680
681
682
683
684
      {
      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
685
686
    for(std::vector<std::string>::const_iterator d = 
          command.GetDepends().begin();
Alexander Neundorf's avatar
   
Alexander Neundorf committed
687
688
        d != command.GetDepends().end(); 
        ++d)
Ken Martin's avatar
Ken Martin committed
689
      {
690
      // Lookup the real name of the dependency in case it is a CMake target.
691
692
      std::string dep = this->GetRealDependency(d->c_str(),
                                                config.c_str());
693
694
      fout << "\\\n\t" <<
        this->ConvertToOptionallyRelativeOutputPath(dep.c_str());
Ken Martin's avatar
Ken Martin committed
695
696
697
698
      }
    fout << "\n";

    fout << "# PROP Ignore_Default_Tool 1\n";
699
    fout << "# Begin Custom Build -";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
700
    if(!comment.empty())
701
      {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
702
      fout << " " << comment.c_str();
703
704
      }
    fout << "\n\n";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
705
    if(command.GetOutputs().empty())
Ken Martin's avatar
Ken Martin committed
706
      {
Ken Martin's avatar
Ken Martin committed
707
708
      fout << source 
           << "_force :  \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"\n\t";
Alexander Neundorf's avatar
   
Alexander Neundorf committed
709
      fout << script.c_str() << "\n\n";
Ken Martin's avatar
Ken Martin committed
710
      }
711
712
    else
      {
Alexander Neundorf's avatar
   
Alexander Neundorf committed
713
714
715
716
      for(std::vector<std::string>::const_iterator o = 
          command.GetOutputs().begin();
          o != command.GetOutputs().end(); 
          ++o)
717
718
719
720
        {
        // 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
721
        fout << script.c_str() << "\n\n";
722
723
        }
      }
Ken Martin's avatar
Ken Martin committed
724
725
726
727
728
729
730
731
    fout << "# End Custom Build\n\n";
    }
  
  fout << "!ENDIF\n\n";
}


void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout, 
Bill Hoffman's avatar
Bill Hoffman committed
732
733
                                                       const char* group,
                                                       const char* filter)
Ken Martin's avatar
Ken Martin committed
734
735
736
737
738
739
740
741
742
743
744
745
746
747
{
  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
748
749
void cmLocalVisualStudio6Generator::SetBuildType(BuildType b,
                                                 const char* libName,
750
                                                 cmTarget& target)
Ken Martin's avatar
Ken Martin committed
751
{
Ken Martin's avatar
Ken Martin committed
752
  std::string root= this->Makefile->GetRequiredDefinition("CMAKE_ROOT");
Ken Martin's avatar
Ken Martin committed
753
754
  const char *def= 
    this->Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY");
Ken Martin's avatar
Ken Martin committed
755
756
757
758
759
760
761
762
763
764
765
766
767

  if( def)
    {
    root = def;
    }
  else
    {
    root += "/Templates";
    }
  
  switch(b)
    {
    case STATIC_LIBRARY:
Ken Martin's avatar
Ken Martin committed
768
769
770
771
      this->DSPHeaderTemplate = root;
      this->DSPHeaderTemplate += "/staticLibHeader.dsptemplate";
      this->DSPFooterTemplate = root;
      this->DSPFooterTemplate += "/staticLibFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
772
773
      break;
    case DLL:
Ken Martin's avatar
Ken Martin committed
774
775
776
777
      this->DSPHeaderTemplate =  root;
      this->DSPHeaderTemplate += "/DLLHeader.dsptemplate";
      this->DSPFooterTemplate =  root;
      this->DSPFooterTemplate += "/DLLFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
778
779
      break;
    case EXECUTABLE:
780
781
      if ( target.GetPropertyAsBool("WIN32_EXECUTABLE") )
        {
Ken Martin's avatar
Ken Martin committed
782
783
784
785
        this->DSPHeaderTemplate = root;
        this->DSPHeaderTemplate += "/EXEWinHeader.dsptemplate";
        this->DSPFooterTemplate = root;
        this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
786
787
788
        }
      else
        {
Ken Martin's avatar
Ken Martin committed
789
790
791
792
        this->DSPHeaderTemplate = root;
        this->DSPHeaderTemplate += "/EXEHeader.dsptemplate";
        this->DSPFooterTemplate = root;
        this->DSPFooterTemplate += "/EXEFooter.dsptemplate";
793
        }
Ken Martin's avatar
Ken Martin committed
794
795
      break;
    case UTILITY:
Ken Martin's avatar
Ken Martin committed
796
797
798
799
      this->DSPHeaderTemplate = root;
      this->DSPHeaderTemplate += "/UtilityHeader.dsptemplate";
      this->DSPFooterTemplate = root;
      this->DSPFooterTemplate += "/UtilityFooter.dsptemplate";
Ken Martin's avatar
Ken Martin committed
800
801
802
803
804
      break;
    }

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

807
  cmsys::RegularExpression reg("# Name ");
Ken Martin's avatar
Ken Martin committed
808
809
  if(!fin)
    {
Ken Martin's avatar
Ken Martin committed
810
    cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
Ken Martin's avatar
Ken Martin committed
811
812
    }

Ken Martin's avatar
Ken Martin committed
813
  // reset this->Configurations
Ken Martin's avatar
Ken Martin committed
814
815
  this->Configurations.erase(this->Configurations.begin(), 
                             this->Configurations.end());
816

Ken Martin's avatar
Ken Martin committed
817
  // now add all the configurations possible
818
  std::string vs6name = GetVS6TargetName(libName);
819
820
  std::string line;
  while(cmSystemTools::GetLineFromStream(fin, line))
Ken Martin's avatar
Ken Martin committed
821
    {
822
    cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME", vs6name.c_str());
Ken Martin's avatar
Ken Martin committed
823
824
    if (reg.find(line))
      {
Ken Martin's avatar
Ken Martin committed
825
      this->Configurations.push_back(line.substr(reg.end()));
Ken Martin's avatar
Ken Martin committed
826
827
828
829
830
831
      }
    }
}

// look for custom rules on a target and collect them together
std::string 
832
cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, 
Alexander Neundorf's avatar
   
Alexander Neundorf committed
833
                                                 const char* configName, 
Ken Martin's avatar
Ken Martin committed
834
                                                 const char * /* libName */)
Ken Martin's avatar
Ken Martin committed
835
{
836
  if (target.GetType() >= cmTarget::UTILITY )
Ken Martin's avatar
Ken Martin committed
837
    {
838
    return "";
Ken Martin's avatar
Ken Martin committed
839
    }
840

841
842
  std::string customRuleCode = "# Begin Special Build Tool\n";
  EventWriter event(this, configName, customRuleCode);
843

844
845
846
847
848
849
850
851
852
853
  // Write the pre-build and pre-link together (VS6 does not support both).
  event.Start("PreLink");
  event.Write(target.GetPreBuildCommands());
  event.Write(target.GetPreLinkCommands());
  event.Finish();

  // Write the post-build rules.
  event.Start("PostBuild");
  event.Write(target.GetPostBuildCommands());
  event.Finish();
854

855
  customRuleCode += "# End Special Build Tool\n";
Ken Martin's avatar
Ken Martin committed
856
857
858
859
860
861
862
863
864
865
866
867
868
  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;
}

869
870
871
// 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.
872
#define CM_USE_OLD_VS6
873

874
875
void cmLocalVisualStudio6Generator
::WriteDSPHeader(std::ostream& fout, 
876
                 const char *libName, cmTarget &target, 
877
                 std::vector<cmSourceGroup> &)
Ken Martin's avatar
Ken Martin committed
878
{
879
880
881
882
  // Lookup the output directory for the target.
  std::string outPath = target.GetDirectory();

#ifdef CM_USE_OLD_VS6
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
  // 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
911
912
913
914
915
916
917
918
  std::set<std::string> pathEmitted;
  
  // determine the link directories
  std::string libOptions;
  std::string libDebugOptions;
  std::string libOptimizedOptions;

  std::string libMultiLineOptions;
919
  std::string libMultiLineOptionsForDebug;
Ken Martin's avatar
Ken Martin committed
920
921
922
923
924
925
  std::string libMultiLineDebugOptions;
  std::string libMultiLineOptimizedOptions;

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

Ken Martin's avatar
Ken Martin committed
1074
1075
1076
1077
1078
1079
1080
      if (j->second == cmTarget::GENERAL)
        {
        libOptions += " ";
        libOptions += lib;
        libMultiLineOptions += "# ADD LINK32 ";
        libMultiLineOptions +=  lib;
        libMultiLineOptions += "\n";
1081
1082
1083
        libMultiLineOptionsForDebug += "# ADD LINK32 ";
        libMultiLineOptionsForDebug +=  libDebug;
        libMultiLineOptionsForDebug += "\n";
Ken Martin's avatar
Ken Martin committed
1084
1085
1086
1087
1088
1089
1090
        }
      if (j->second == cmTarget::DEBUG)
        {
        libDebugOptions += " ";
        libDebugOptions += lib;

        libMultiLineDebugOptions += "# ADD LINK32 ";
1091
        libMultiLineDebugOptions += libDebug;
Ken Martin's avatar
Ken Martin committed
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
        libMultiLineDebugOptions += "\n";
        }
      if (j->second == cmTarget::OPTIMIZED)
        {
        libOptimizedOptions += " ";
        libOptimizedOptions += lib;

        libMultiLineOptimizedOptions += "# ADD LINK32 ";
        libMultiLineOptimizedOptions += lib;
        libMultiLineOptimizedOptions += "\n";
        }      
      }
    }
1105
#endif
1106
1107

  // Get extra linker options for this target type.
1108
1109
1110
  std::string extraLinkOptions;
  if(target.GetType() == cmTarget::EXECUTABLE)
    {