~ubuntu-branches/ubuntu/quantal/cmake/quantal

« back to all changes in this revision

Viewing changes to Source/cmMakefileTargetGenerator.cxx

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2012-04-30 12:14:32 UTC
  • mfrom: (3.1.30 sid)
  • Revision ID: package-import@ubuntu.com-20120430121432-rqh2fjl3zcblehh5
Tags: 2.8.8-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add xfail_compiler_flag.diff: Mark compiler flag tests as expected
    failures.
  - Add ubuntu_qt_import_dir_variable.diff: define QT_IMPORTS_DIR even
    when that dir does not exist.
* Remove increase_ctest_test_timeout.diff, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
============================================================================*/
12
12
#include "cmMakefileTargetGenerator.h"
13
13
 
 
14
#include "cmGeneratorTarget.h"
14
15
#include "cmGeneratedFileStream.h"
15
16
#include "cmGlobalGenerator.h"
16
17
#include "cmGlobalUnixMakefileGenerator3.h"
42
43
  this->GlobalGenerator =
43
44
    static_cast<cmGlobalUnixMakefileGenerator3*>(
44
45
      this->LocalGenerator->GetGlobalGenerator());
 
46
  this->GeneratorTarget = this->GlobalGenerator->GetGeneratorTarget(target);
45
47
  cmake* cm = this->GlobalGenerator->GetCMakeInstance();
46
48
  this->NoRuleMessages = false;
47
49
  if(const char* ruleStatus = cm->GetProperty("RULE_MESSAGES"))
63
65
    case cmTarget::STATIC_LIBRARY:
64
66
    case cmTarget::SHARED_LIBRARY:
65
67
    case cmTarget::MODULE_LIBRARY:
 
68
    case cmTarget::OBJECT_LIBRARY:
66
69
      result = new cmMakefileLibraryTargetGenerator(tgt);
67
70
      break;
68
71
    case cmTarget::UTILITY:
131
134
 
132
135
  // First generate the object rule files.  Save a list of all object
133
136
  // files for this target.
134
 
  const std::vector<cmSourceFile*>& sources = this->Target->GetSourceFiles();
135
 
  for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
136
 
      source != sources.end(); ++source)
 
137
  for(std::vector<cmSourceFile*>::const_iterator
 
138
        si = this->GeneratorTarget->CustomCommands.begin();
 
139
      si != this->GeneratorTarget->CustomCommands.end(); ++si)
 
140
    {
 
141
    cmCustomCommand const* cc = (*si)->GetCustomCommand();
 
142
    this->GenerateCustomRuleFile(*cc);
 
143
    if (clean)
 
144
      {
 
145
      const std::vector<std::string>& outputs = cc->GetOutputs();
 
146
      for(std::vector<std::string>::const_iterator o = outputs.begin();
 
147
          o != outputs.end(); ++o)
 
148
        {
 
149
        this->CleanFiles.push_back
 
150
          (this->Convert(o->c_str(),
 
151
                         cmLocalGenerator::START_OUTPUT,
 
152
                         cmLocalGenerator::UNCHANGED));
 
153
        }
 
154
      }
 
155
    }
 
156
  for(std::vector<cmSourceFile*>::const_iterator
 
157
        si = this->GeneratorTarget->OSXContent.begin();
 
158
      si != this->GeneratorTarget->OSXContent.end(); ++si)
137
159
    {
138
160
    cmTarget::SourceFileFlags tsFlags =
139
 
      this->Target->GetTargetSourceFileFlags(*source);
140
 
    if(cmCustomCommand* cc = (*source)->GetCustomCommand())
141
 
      {
142
 
      this->GenerateCustomRuleFile(*cc);
143
 
      if (clean)
144
 
        {
145
 
        const std::vector<std::string>& outputs = cc->GetOutputs();
146
 
        for(std::vector<std::string>::const_iterator o = outputs.begin();
147
 
            o != outputs.end(); ++o)
148
 
          {
149
 
          this->CleanFiles.push_back
150
 
            (this->Convert(o->c_str(),
151
 
                           cmLocalGenerator::START_OUTPUT,
152
 
                           cmLocalGenerator::UNCHANGED));
153
 
          }
154
 
        }
155
 
      }
156
 
    else if(tsFlags.Type != cmTarget::SourceFileTypeNormal)
157
 
      {
158
 
      this->WriteMacOSXContentRules(*(*source), tsFlags.MacFolder);
159
 
      }
160
 
    else if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY"))
161
 
      {
162
 
      if(!this->GlobalGenerator->IgnoreFile
163
 
         ((*source)->GetExtension().c_str()))
164
 
        {
165
 
        // Generate this object file's rule file.
166
 
        this->WriteObjectRuleFiles(*(*source));
167
 
        }
168
 
      else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT"))
169
 
        {
170
 
        // This is an external object file.  Just add it.
171
 
        this->ExternalObjects.push_back((*source)->GetFullPath());
172
 
        }
173
 
      else if(cmSystemTools::UpperCase((*source)->GetExtension()) == "DEF")
174
 
        {
175
 
        this->ModuleDefinitionFile = (*source)->GetFullPath();
176
 
        }
177
 
      else
178
 
        {
179
 
        // We only get here if a source file is not an external object
180
 
        // and has an extension that is listed as an ignored file type
181
 
        // for this language.  No message or diagnosis should be
182
 
        // given.
183
 
        }
184
 
      }
185
 
    }
 
161
      this->Target->GetTargetSourceFileFlags(*si);
 
162
    this->WriteMacOSXContentRules(**si, tsFlags.MacFolder);
 
163
    }
 
164
  for(std::vector<cmSourceFile*>::const_iterator
 
165
        si = this->GeneratorTarget->ExternalObjects.begin();
 
166
      si != this->GeneratorTarget->ExternalObjects.end(); ++si)
 
167
    {
 
168
    this->ExternalObjects.push_back((*si)->GetFullPath());
 
169
    }
 
170
  for(std::vector<cmSourceFile*>::const_iterator
 
171
        si = this->GeneratorTarget->ObjectSources.begin();
 
172
      si != this->GeneratorTarget->ObjectSources.end(); ++si)
 
173
    {
 
174
    // Generate this object file's rule file.
 
175
    this->WriteObjectRuleFiles(**si);
 
176
    }
 
177
 
 
178
  // Add object library contents as external objects.
 
179
  this->GeneratorTarget->UseObjectLibraries(this->ExternalObjects);
186
180
}
187
181
 
188
182
 
428
422
    }
429
423
 
430
424
  // Get the full path name of the object file.
431
 
  bool hasSourceExtension;
432
 
  std::string objNoTargetDir;
433
 
  std::string obj =
434
 
    this->LocalGenerator->GetObjectFileName(*this->Target, source,
435
 
                                            &objNoTargetDir,
436
 
                                            &hasSourceExtension);
 
425
  std::string const& objectName = this->GeneratorTarget->Objects[&source];
 
426
  std::string obj = this->LocalGenerator->GetTargetDirectory(*this->Target);
 
427
  obj += "/";
 
428
  obj += objectName;
437
429
 
438
430
  // Avoid generating duplicate rules.
439
431
  if(this->ObjectFiles.find(obj) == this->ObjectFiles.end())
487
479
    AddImplicitDepends(*this->Target, lang,
488
480
                       objFullPath.c_str(),
489
481
                       srcFullPath.c_str());
490
 
 
491
 
  // add this to the list of objects for this local generator
492
 
  if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str()))
493
 
    {
494
 
    objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir);
495
 
    }
496
 
  cmLocalUnixMakefileGenerator3::LocalObjectInfo& info =
497
 
    this->LocalGenerator->LocalObjectFiles[objNoTargetDir];
498
 
  info.HasSourceExtension = hasSourceExtension;
499
 
  info.push_back(
500
 
    cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang)
501
 
    );
502
482
}
503
483
 
504
484
//----------------------------------------------------------------------------
1069
1049
      << "SET(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n";
1070
1050
    }
1071
1051
 
 
1052
  // Target-specific include directories:
 
1053
  *this->InfoFileStream
 
1054
    << "\n"
 
1055
    << "# The include file search paths:\n";
 
1056
  *this->InfoFileStream
 
1057
    << "SET(CMAKE_C_TARGET_INCLUDE_PATH\n";
 
1058
  std::vector<std::string> includes;
 
1059
  this->LocalGenerator->GetIncludeDirectories(includes, this->Target);
 
1060
  for(std::vector<std::string>::iterator i = includes.begin();
 
1061
      i != includes.end(); ++i)
 
1062
    {
 
1063
    *this->InfoFileStream
 
1064
      << "  \""
 
1065
      << this->LocalGenerator->Convert(i->c_str(),
 
1066
                                       cmLocalGenerator::HOME_OUTPUT)
 
1067
      << "\"\n";
 
1068
    }
 
1069
  *this->InfoFileStream
 
1070
    << "  )\n";
 
1071
  *this->InfoFileStream
 
1072
    << "SET(CMAKE_CXX_TARGET_INCLUDE_PATH "
 
1073
    << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
 
1074
  *this->InfoFileStream
 
1075
    << "SET(CMAKE_Fortran_TARGET_INCLUDE_PATH "
 
1076
    << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
 
1077
  *this->InfoFileStream
 
1078
    << "SET(CMAKE_ASM_TARGET_INCLUDE_PATH "
 
1079
    << "${CMAKE_C_TARGET_INCLUDE_PATH})\n";
 
1080
 
1072
1081
  // and now write the rule to use it
1073
1082
  std::vector<std::string> depends;
1074
1083
  std::vector<std::string> commands;
1534
1543
  emitted.insert("/System/Library/Frameworks");
1535
1544
#endif
1536
1545
  std::vector<std::string> includes;
1537
 
  this->LocalGenerator->GetIncludeDirectories(includes);
 
1546
  this->LocalGenerator->GetIncludeDirectories(includes, this->Target);
1538
1547
  std::vector<std::string>::iterator i;
1539
1548
  // check all include directories for frameworks as this
1540
1549
  // will already have added a -F for the framework
1591
1600
 
1592
1601
//----------------------------------------------------------------------------
1593
1602
void cmMakefileTargetGenerator
1594
 
::AppendLinkDepends(std::vector<std::string>& depends)
 
1603
::AppendObjectDepends(std::vector<std::string>& depends)
1595
1604
{
1596
1605
  // Add dependencies on the compiled object files.
1597
1606
  std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
1604
1613
    depends.push_back(objTarget);
1605
1614
    }
1606
1615
 
1607
 
  // Add dependencies on targets that must be built first.
1608
 
  this->AppendTargetDepends(depends);
1609
 
 
1610
 
  // Add a dependency on the rule file itself.
1611
 
  this->LocalGenerator->AppendRuleDepend(depends,
1612
 
                                         this->BuildFileNameFull.c_str());
1613
 
 
1614
 
  // Add a dependency on the link definitions file, if any.
1615
 
  if(!this->ModuleDefinitionFile.empty())
1616
 
    {
1617
 
    depends.push_back(this->ModuleDefinitionFile);
1618
 
    }
1619
 
 
1620
1616
  // Add dependencies on the external object files.
1621
1617
  for(std::vector<std::string>::const_iterator obj
1622
1618
        = this->ExternalObjects.begin();
1625
1621
    depends.push_back(*obj);
1626
1622
    }
1627
1623
 
 
1624
  // Add a dependency on the rule file itself.
 
1625
  this->LocalGenerator->AppendRuleDepend(depends,
 
1626
                                         this->BuildFileNameFull.c_str());
 
1627
}
 
1628
 
 
1629
//----------------------------------------------------------------------------
 
1630
void cmMakefileTargetGenerator
 
1631
::AppendLinkDepends(std::vector<std::string>& depends)
 
1632
{
 
1633
  this->AppendObjectDepends(depends);
 
1634
 
 
1635
  // Add dependencies on targets that must be built first.
 
1636
  this->AppendTargetDepends(depends);
 
1637
 
 
1638
  // Add a dependency on the link definitions file, if any.
 
1639
  if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
 
1640
    {
 
1641
    depends.push_back(this->GeneratorTarget->ModuleDefinitionFile);
 
1642
    }
 
1643
 
1628
1644
  // Add user-specified dependencies.
1629
1645
  if(const char* linkDepends =
1630
1646
     this->Target->GetProperty("LINK_DEPENDS"))
1829
1845
  responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
1830
1846
  bool useResponseFile = this->Makefile->IsOn(responseVar.c_str());
1831
1847
 
 
1848
 
 
1849
  std::vector<std::string> includes;
 
1850
  this->LocalGenerator->GetIncludeDirectories(includes, this->Target, lang);
 
1851
 
1832
1852
  std::string includeFlags =
1833
 
    this->LocalGenerator->GetIncludeFlags(lang, useResponseFile);
 
1853
    this->LocalGenerator->GetIncludeFlags(includes, lang, useResponseFile);
1834
1854
  if(includeFlags.empty())
1835
1855
    {
1836
1856
    return;
1930
1950
     this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG"))
1931
1951
    {
1932
1952
    std::vector<std::string> includes;
1933
 
    this->LocalGenerator->GetIncludeDirectories(includes);
 
1953
    this->LocalGenerator->GetIncludeDirectories(includes, this->Target);
1934
1954
    for(std::vector<std::string>::const_iterator idi = includes.begin();
1935
1955
        idi != includes.end(); ++idi)
1936
1956
      {
1946
1966
//----------------------------------------------------------------------------
1947
1967
void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
1948
1968
{
1949
 
  if(this->ModuleDefinitionFile.empty())
 
1969
  if(this->GeneratorTarget->ModuleDefinitionFile.empty())
1950
1970
    {
1951
1971
    return;
1952
1972
    }
1963
1983
  // vs6's "cl -link" pass it to the linker.
1964
1984
  std::string flag = defFileFlag;
1965
1985
  flag += (this->LocalGenerator->ConvertToLinkReference(
1966
 
             this->ModuleDefinitionFile.c_str()));
 
1986
             this->GeneratorTarget->ModuleDefinitionFile.c_str()));
1967
1987
  this->LocalGenerator->AppendFlags(flags, flag.c_str());
1968
1988
}
1969
1989