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

« back to all changes in this revision

Viewing changes to Source/cmMakefileLibraryTargetGenerator.cxx

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*=========================================================================
2
 
 
3
 
  Program:   CMake - Cross-Platform Makefile Generator
4
 
  Module:    $RCSfile: cmMakefileLibraryTargetGenerator.cxx,v $
5
 
  Language:  C++
6
 
  Date:      $Date: 2008-10-24 15:18:52 $
7
 
  Version:   $Revision: 1.58.2.5 $
8
 
 
9
 
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
10
 
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11
 
 
12
 
     This software is distributed WITHOUT ANY WARRANTY; without even
13
 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
 
     PURPOSE.  See the above copyright notices for more information.
15
 
 
16
 
=========================================================================*/
 
1
/*============================================================================
 
2
  CMake - Cross Platform Makefile Generator
 
3
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
 
4
 
 
5
  Distributed under the OSI-approved BSD License (the "License");
 
6
  see accompanying file Copyright.txt for details.
 
7
 
 
8
  This software is distributed WITHOUT ANY WARRANTY; without even the
 
9
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
10
  See the License for more information.
 
11
============================================================================*/
17
12
#include "cmMakefileLibraryTargetGenerator.h"
18
13
 
19
14
#include "cmGeneratedFileStream.h"
34
29
  this->CustomCommandDriver = OnDepends;
35
30
  this->Target->GetLibraryNames(
36
31
    this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
37
 
    this->TargetNameImport, this->TargetNamePDB,
38
 
    this->LocalGenerator->ConfigurationName.c_str());
 
32
    this->TargetNameImport, this->TargetNamePDB, this->ConfigName);
39
33
 
40
34
  if(this->Target->IsFrameworkOnApple())
41
35
    {
42
36
    this->FrameworkVersion = this->Target->GetFrameworkVersion();
43
 
    this->MacContentDirectory = this->Target->GetDirectory();
 
37
    this->MacContentDirectory = this->Target->GetDirectory(this->ConfigName);
44
38
    this->MacContentDirectory += "/";
45
39
    this->MacContentDirectory += this->TargetNameOut;
46
40
    this->MacContentDirectory += ".framework/Versions/";
73
67
      break;
74
68
    case cmTarget::SHARED_LIBRARY:
75
69
      this->WriteSharedLibraryRules(false);
76
 
      if(this->Target->NeedRelinkBeforeInstall())
 
70
      if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
77
71
        {
78
72
        // Write rules to link an installable version of the target.
79
73
        this->WriteSharedLibraryRules(true);
81
75
      break;
82
76
    case cmTarget::MODULE_LIBRARY:
83
77
      this->WriteModuleLibraryRules(false);
84
 
      if(this->Target->NeedRelinkBeforeInstall())
 
78
      if(this->Target->NeedRelinkBeforeInstall(this->ConfigName))
85
79
        {
86
80
        // Write rules to link an installable version of the target.
87
81
        this->WriteModuleLibraryRules(true);
111
105
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
112
106
{
113
107
  const char* linkLanguage =
114
 
    this->Target->GetLinkerLanguage(this->GlobalGenerator);
 
108
    this->Target->GetLinkerLanguage(this->ConfigName);
115
109
  std::string linkRuleVar = "CMAKE_";
116
110
  if (linkLanguage)
117
111
    {
119
113
    }
120
114
  linkRuleVar += "_CREATE_STATIC_LIBRARY";
121
115
 
 
116
  if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION") &&
 
117
     this->Makefile->GetDefinition((linkRuleVar+"_IPO").c_str()))
 
118
    {
 
119
    linkRuleVar += "_IPO";
 
120
    }
 
121
 
122
122
  std::string extraFlags;
123
123
  this->LocalGenerator->AppendFlags
124
124
    (extraFlags,this->Target->GetProperty("STATIC_LIBRARY_FLAGS"));
134
134
    return;
135
135
    }
136
136
  const char* linkLanguage =
137
 
    this->Target->GetLinkerLanguage(this->GlobalGenerator);
 
137
    this->Target->GetLinkerLanguage(this->ConfigName);
138
138
  std::string linkRuleVar = "CMAKE_";
139
139
  if (linkLanguage)
140
140
    {
146
146
  this->LocalGenerator->AppendFlags
147
147
    (extraFlags, this->Target->GetProperty("LINK_FLAGS"));
148
148
  std::string linkFlagsConfig = "LINK_FLAGS_";
149
 
  linkFlagsConfig += 
150
 
    cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
 
149
  linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
151
150
  this->LocalGenerator->AppendFlags
152
151
    (extraFlags, this->Target->GetProperty(linkFlagsConfig.c_str()));
153
152
                                    
154
153
  this->LocalGenerator->AddConfigVariableFlags
155
 
    (extraFlags, "CMAKE_SHARED_LINKER_FLAGS",
156
 
     this->LocalGenerator->ConfigurationName.c_str());
157
 
  if(this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") 
158
 
                                        || this->Makefile->IsOn("MINGW")))
159
 
    {
160
 
    const std::vector<cmSourceFile*>& sources = 
161
 
      this->Target->GetSourceFiles();
162
 
    for(std::vector<cmSourceFile*>::const_iterator i = sources.begin();
163
 
        i != sources.end(); ++i)
164
 
      {
165
 
      cmSourceFile* sf = *i;
166
 
      if(sf->GetExtension() == "def")
167
 
        {
168
 
        extraFlags += " ";
169
 
        extraFlags += 
170
 
          this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
171
 
        extraFlags += 
172
 
          this->Convert(sf->GetFullPath().c_str(),
173
 
                        cmLocalGenerator::START_OUTPUT,
174
 
                        cmLocalGenerator::SHELL);
175
 
        }
176
 
      }
177
 
    }
 
154
    (extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
 
155
  this->AddModuleDefinitionFlag(extraFlags);
 
156
 
178
157
  this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
179
158
}
180
159
 
182
161
void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
183
162
{
184
163
  const char* linkLanguage =
185
 
    this->Target->GetLinkerLanguage(this->GlobalGenerator);
 
164
    this->Target->GetLinkerLanguage(this->ConfigName);
186
165
  std::string linkRuleVar = "CMAKE_";
187
166
  if (linkLanguage)
188
167
    {
194
173
  this->LocalGenerator->AppendFlags(extraFlags, 
195
174
                                    this->Target->GetProperty("LINK_FLAGS"));
196
175
  std::string linkFlagsConfig = "LINK_FLAGS_";
197
 
  linkFlagsConfig += 
198
 
    cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
 
176
  linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
199
177
  this->LocalGenerator->AppendFlags
200
178
    (extraFlags, this->Target->GetProperty(linkFlagsConfig.c_str()));
201
179
  this->LocalGenerator->AddConfigVariableFlags
202
 
    (extraFlags, "CMAKE_MODULE_LINKER_FLAGS",
203
 
     this->LocalGenerator->ConfigurationName.c_str());
 
180
    (extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
 
181
  this->AddModuleDefinitionFlag(extraFlags);
204
182
 
205
 
  // TODO: .def files should be supported here also.
206
183
  this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
207
184
}
208
185
 
210
187
void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
211
188
{
212
189
  const char* linkLanguage =
213
 
    this->Target->GetLinkerLanguage(this->GlobalGenerator);
 
190
    this->Target->GetLinkerLanguage(this->ConfigName);
214
191
  std::string linkRuleVar = "CMAKE_";
215
192
  if (linkLanguage)
216
193
    {
222
199
  this->LocalGenerator->AppendFlags(extraFlags, 
223
200
                                    this->Target->GetProperty("LINK_FLAGS"));
224
201
  std::string linkFlagsConfig = "LINK_FLAGS_";
225
 
  linkFlagsConfig += 
226
 
    cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
 
202
  linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
227
203
  this->LocalGenerator->AppendFlags
228
204
    (extraFlags, this->Target->GetProperty(linkFlagsConfig.c_str()));
229
205
  this->LocalGenerator->AddConfigVariableFlags
230
 
    (extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS",
231
 
     this->LocalGenerator->ConfigurationName.c_str());
 
206
    (extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->ConfigName);
232
207
 
233
 
  // TODO: .def files should be supported here also.
234
208
  this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), relink);
235
209
}
236
210
 
252
226
  std::string newName;
253
227
 
254
228
  // Compute the location of the top-level foo.framework directory.
255
 
  std::string top = this->Target->GetDirectory();
 
229
  std::string top = this->Target->GetDirectory(this->ConfigName);
256
230
  top += "/";
257
231
  top += this->TargetNameOut;
258
232
  top += ".framework/";
359
333
  
360
334
  // Get the language to use for linking this library.
361
335
  const char* linkLanguage =
362
 
    this->Target->GetLinkerLanguage(this->GlobalGenerator);
 
336
    this->Target->GetLinkerLanguage(this->ConfigName);
363
337
 
364
338
  // Make sure we have a link language.
365
339
  if(!linkLanguage)
389
363
  std::string targetNamePDB;
390
364
  this->Target->GetLibraryNames(
391
365
    targetName, targetNameSO, targetNameReal, targetNameImport, targetNamePDB,
392
 
    this->LocalGenerator->ConfigurationName.c_str());
 
366
    this->ConfigName);
393
367
 
394
368
  // Construct the full path version of the names.
395
369
  std::string outpath;
413
387
    }
414
388
  else
415
389
    {
416
 
    outpath = this->Target->GetDirectory();
 
390
    outpath = this->Target->GetDirectory(this->ConfigName);
417
391
    cmSystemTools::MakeDirectory(outpath.c_str());
418
392
    outpath += "/";
419
393
    if(!targetNameImport.empty())
420
394
      {
421
 
      outpathImp = this->Target->GetDirectory(0, true);
 
395
      outpathImp = this->Target->GetDirectory(this->ConfigName, true);
422
396
      cmSystemTools::MakeDirectory(outpathImp.c_str());
423
397
      outpathImp += "/";
424
398
      }
433
407
  // Construct the output path version of the names for use in command
434
408
  // arguments.
435
409
  std::string targetOutPathPDB = 
436
 
    this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::FULL,
 
410
    this->Convert(targetFullPathPDB.c_str(),cmLocalGenerator::NONE,
437
411
                  cmLocalGenerator::SHELL);
438
412
  std::string targetOutPath = 
439
413
    this->Convert(targetFullPath.c_str(),cmLocalGenerator::START_OUTPUT,
448
422
    this->Convert(targetFullPathImport.c_str(),cmLocalGenerator::START_OUTPUT,
449
423
                  cmLocalGenerator::SHELL);
450
424
 
451
 
  // Add the link message.
452
 
  std::string buildEcho = "Linking ";
453
 
  buildEcho += linkLanguage;
 
425
  if(!this->NoRuleMessages)
 
426
    {
 
427
    // Add the link message.
 
428
    std::string buildEcho = "Linking ";
 
429
    buildEcho += linkLanguage;
 
430
    switch(this->Target->GetType())
 
431
      {
 
432
      case cmTarget::STATIC_LIBRARY:
 
433
        buildEcho += " static library ";
 
434
        break;
 
435
      case cmTarget::SHARED_LIBRARY:
 
436
        buildEcho += " shared library ";
 
437
        break;
 
438
      case cmTarget::MODULE_LIBRARY:
 
439
        buildEcho += " shared module ";
 
440
        break;
 
441
      default:
 
442
        buildEcho += " library ";
 
443
        break;
 
444
      }
 
445
    buildEcho += targetOutPath.c_str();
 
446
    this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
 
447
                                     cmLocalUnixMakefileGenerator3::EchoLink);
 
448
    }
 
449
 
454
450
  const char* forbiddenFlagVar = 0;
455
451
  switch(this->Target->GetType())
456
452
    {
457
 
    case cmTarget::STATIC_LIBRARY:
458
 
      buildEcho += " static library "; 
459
 
      break;
460
453
    case cmTarget::SHARED_LIBRARY:
461
454
      forbiddenFlagVar = "_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS";
462
 
      buildEcho += " shared library ";
463
455
      break;
464
456
    case cmTarget::MODULE_LIBRARY:
465
457
      forbiddenFlagVar = "_CREATE_SHARED_MODULE_FORBIDDEN_FLAGS";
466
 
      buildEcho += " shared module ";
467
 
      break;
468
 
    default:
469
 
      buildEcho += " library "; 
470
 
      break;
 
458
      break;
 
459
    default: break;
471
460
    }
472
 
  buildEcho += targetOutPath.c_str();
473
 
  this->LocalGenerator->AppendEcho(commands, buildEcho.c_str(),
474
 
                                   cmLocalUnixMakefileGenerator3::EchoLink);
475
461
 
476
 
  // Construct a list of files associated with this library that may
477
 
  // need to be cleaned.
 
462
  // Clean files associated with this library.
478
463
  std::vector<std::string> libCleanFiles;
479
 
  if(this->Target->GetPropertyAsBool("CLEAN_DIRECT_OUTPUT"))
480
 
    {
481
 
    // The user has requested that only the files directly built
482
 
    // by this target be cleaned instead of all possible names.
483
 
    libCleanFiles.push_back(this->Convert(targetFullPath.c_str(),
484
 
          cmLocalGenerator::START_OUTPUT,
485
 
          cmLocalGenerator::UNCHANGED));
486
 
    if(targetNameReal != targetName)
487
 
      {
488
 
      libCleanFiles.push_back(this->Convert(targetFullPathReal.c_str(),
489
 
          cmLocalGenerator::START_OUTPUT,
490
 
          cmLocalGenerator::UNCHANGED));
491
 
      }
492
 
    if(targetNameSO != targetName &&
493
 
       targetNameSO != targetNameReal)
494
 
      {
495
 
      libCleanFiles.push_back(this->Convert(targetFullPathSO.c_str(),
496
 
          cmLocalGenerator::START_OUTPUT,
497
 
          cmLocalGenerator::UNCHANGED));
498
 
      }
499
 
    if(!targetNameImport.empty())
500
 
      {
501
 
      libCleanFiles.push_back(this->Convert(targetFullPathImport.c_str(),
502
 
          cmLocalGenerator::START_OUTPUT,
503
 
          cmLocalGenerator::UNCHANGED));
504
 
      }
505
 
    }
506
 
  else
507
 
    {
508
 
    // This target may switch between static and shared based
509
 
    // on a user option or the BUILD_SHARED_LIBS switch.  Clean
510
 
    // all possible names.
511
 
    std::string cleanStaticName;
512
 
    std::string cleanSharedName;
513
 
    std::string cleanSharedSOName;
514
 
    std::string cleanSharedRealName;
515
 
    std::string cleanImportName;
516
 
    std::string cleanPDBName;
517
 
    this->Target->GetLibraryCleanNames(
518
 
      cleanStaticName,
519
 
      cleanSharedName,
520
 
      cleanSharedSOName,
521
 
      cleanSharedRealName,
522
 
      cleanImportName,
523
 
      cleanPDBName,
524
 
      this->LocalGenerator->ConfigurationName.c_str());
525
 
    std::string cleanFullStaticName = outpath + cleanStaticName;
526
 
    std::string cleanFullSharedName = outpath + cleanSharedName;
527
 
    std::string cleanFullSharedSOName = outpath + cleanSharedSOName;
528
 
    std::string cleanFullSharedRealName = outpath + cleanSharedRealName;
529
 
    std::string cleanFullImportName = outpathImp + cleanImportName;
530
 
    std::string cleanFullPDBName = outpath + cleanPDBName;
531
 
    libCleanFiles.push_back
532
 
      (this->Convert(cleanFullStaticName.c_str(),
533
 
                     cmLocalGenerator::START_OUTPUT,
534
 
                     cmLocalGenerator::UNCHANGED));
535
 
    if(cleanSharedRealName != cleanStaticName)
536
 
      {
537
 
      libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
538
 
          cmLocalGenerator::START_OUTPUT,
539
 
          cmLocalGenerator::UNCHANGED));
540
 
      }
541
 
    if(cleanSharedSOName != cleanStaticName &&
542
 
      cleanSharedSOName != cleanSharedRealName)
543
 
      {
544
 
      libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
545
 
          cmLocalGenerator::START_OUTPUT,
546
 
          cmLocalGenerator::UNCHANGED));
547
 
      }
548
 
    if(cleanSharedName != cleanStaticName &&
549
 
      cleanSharedName != cleanSharedSOName &&
550
 
      cleanSharedName != cleanSharedRealName)
551
 
      {
552
 
      libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
553
 
          cmLocalGenerator::START_OUTPUT,
554
 
          cmLocalGenerator::UNCHANGED));
555
 
      }
556
 
    if(!cleanImportName.empty())
557
 
      {
558
 
      libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
559
 
          cmLocalGenerator::START_OUTPUT,
560
 
          cmLocalGenerator::UNCHANGED));
561
 
      }
 
464
  libCleanFiles.push_back(this->Convert(targetFullPath.c_str(),
 
465
        cmLocalGenerator::START_OUTPUT,
 
466
        cmLocalGenerator::UNCHANGED));
 
467
  if(targetNameReal != targetName)
 
468
    {
 
469
    libCleanFiles.push_back(this->Convert(targetFullPathReal.c_str(),
 
470
        cmLocalGenerator::START_OUTPUT,
 
471
        cmLocalGenerator::UNCHANGED));
 
472
    }
 
473
  if(targetNameSO != targetName &&
 
474
     targetNameSO != targetNameReal)
 
475
    {
 
476
    libCleanFiles.push_back(this->Convert(targetFullPathSO.c_str(),
 
477
        cmLocalGenerator::START_OUTPUT,
 
478
        cmLocalGenerator::UNCHANGED));
 
479
    }
 
480
  if(!targetNameImport.empty())
 
481
    {
 
482
    libCleanFiles.push_back(this->Convert(targetFullPathImport.c_str(),
 
483
        cmLocalGenerator::START_OUTPUT,
 
484
        cmLocalGenerator::UNCHANGED));
 
485
    }
562
486
 
563
 
    // List the PDB for cleaning only when the whole target is
564
 
    // cleaned.  We do not want to delete the .pdb file just before
565
 
    // linking the target.
566
 
    this->CleanFiles.push_back
567
 
      (this->Convert(cleanFullPDBName.c_str(),
568
 
                     cmLocalGenerator::START_OUTPUT,
569
 
                     cmLocalGenerator::UNCHANGED));
570
 
    }
 
487
  // List the PDB for cleaning only when the whole target is
 
488
  // cleaned.  We do not want to delete the .pdb file just before
 
489
  // linking the target.
 
490
  this->CleanFiles.push_back
 
491
    (this->Convert(targetFullPathPDB.c_str(),
 
492
                   cmLocalGenerator::START_OUTPUT,
 
493
                   cmLocalGenerator::UNCHANGED));
571
494
 
572
495
#ifdef _WIN32
573
496
  // There may be a manifest file for this target.  Add it to the
600
523
  if(!relink)
601
524
    {
602
525
    this->LocalGenerator
603
 
      ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands());
 
526
      ->AppendCustomCommands(commands, this->Target->GetPreBuildCommands(),
 
527
                             this->Target);
604
528
    this->LocalGenerator
605
 
      ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands());
 
529
      ->AppendCustomCommands(commands, this->Target->GetPreLinkCommands(),
 
530
                             this->Target);
606
531
    }
607
532
 
608
533
  // Determine whether a link script will be used.
711
636
  vars.TargetVersionMajor = targetVersionMajor.c_str();
712
637
  vars.TargetVersionMinor = targetVersionMinor.c_str();
713
638
 
 
639
  vars.RuleLauncher = "RULE_LAUNCH_LINK";
 
640
  vars.CMTarget = this->Target;
714
641
  vars.Language = linkLanguage;
715
642
  vars.Objects = buildObjs.c_str();
716
643
  std::string objdir = cmake::GetCMakeFilesDirectoryPostSlash();
732
659
  if(this->Target->GetType() == cmTarget::SHARED_LIBRARY)
733
660
    {
734
661
    // Get the install_name directory for the build tree.
735
 
    const char* config = this->LocalGenerator->ConfigurationName.c_str();
736
 
    install_name_dir = this->Target->GetInstallNameDirForBuildTree(config);
 
662
    install_name_dir =
 
663
      this->Target->GetInstallNameDirForBuildTree(this->ConfigName);
737
664
 
738
665
    // Set the rule variable replacement value.
739
666
    if(install_name_dir.empty())
750
677
      vars.TargetInstallNameDir = install_name_dir.c_str();
751
678
      }
752
679
    }
 
680
 
 
681
  // Add language feature flags.
753
682
  std::string langFlags;
754
 
  this->LocalGenerator
755
 
    ->AddLanguageFlags(langFlags, linkLanguage,
756
 
                       this->LocalGenerator->ConfigurationName.c_str());
 
683
  this->AddFeatureFlags(langFlags, linkLanguage);
 
684
 
757
685
  // remove any language flags that might not work with the
758
686
  // particular os
759
687
  if(forbiddenFlagVar)
867
795
  if(!relink)
868
796
    {
869
797
    this->LocalGenerator->
870
 
      AppendCustomCommands(commands, this->Target->GetPostBuildCommands());
 
798
      AppendCustomCommands(commands, this->Target->GetPostBuildCommands(),
 
799
                           this->Target);
871
800
    }
872
801
 
873
802
  // Write the build rule.