cmComputeTargetDepends.cxx 22.5 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
13
#include "cmComputeTargetDepends.h"

14
#include "cmComputeComponentGraph.h"
15
16
17
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
18
#include "cmState.h"
19
#include "cmSystemTools.h"
20
#include "cmSourceFile.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "cmTarget.h"
#include "cmake.h"

#include <algorithm>

#include <assert.h>

/*

This class is meant to analyze inter-target dependencies globally
during the generation step.  The goal is to produce a set of direct
dependencies for each target such that no cycles are left and the
build order is safe.

For most target types cyclic dependencies are not allowed.  However
36
STATIC libraries may depend on each other in a cyclic fashion.  In
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
89
90
91
92
93
94
95
96
97
98
99
100
101
general the directed dependency graph forms a directed-acyclic-graph
of strongly connected components.  All strongly connected components
should consist of only STATIC_LIBRARY targets.

In order to safely break dependency cycles we must preserve all other
dependencies passing through the corresponding strongly connected component.
The approach taken by this class is as follows:

  - Collect all targets and form the original dependency graph
  - Run Tarjan's algorithm to extract the strongly connected components
    (error if any member of a non-trivial component is not STATIC)
  - The original dependencies imply a DAG on the components.
    Use the implied DAG to construct a final safe set of dependencies.

The final dependency set is constructed as follows:

  - For each connected component targets are placed in an arbitrary
    order.  Each target depends on the target following it in the order.
    The first target is designated the head and the last target the tail.
    (most components will be just 1 target anyway)

  - Original dependencies between targets in different components are
    converted to connect the depender's component tail to the
    dependee's component head.

In most cases this will reproduce the original dependencies.  However
when there are cycles of static libraries they will be broken in a
safe manner.

For example, consider targets A0, A1, A2, B0, B1, B2, and C with these
dependencies:

  A0 -> A1 -> A2 -> A0  ,  B0 -> B1 -> B2 -> B0 -> A0  ,  C -> B0

Components may be identified as

  Component 0: A0, A1, A2
  Component 1: B0, B1, B2
  Component 2: C

Intra-component dependencies are:

  0: A0 -> A1 -> A2   , head=A0, tail=A2
  1: B0 -> B1 -> B2   , head=B0, tail=B2
  2: head=C, tail=C

The inter-component dependencies are converted as:

  B0 -> A0  is component 1->0 and becomes  B2 -> A0
  C  -> B0  is component 2->1 and becomes  C  -> B0

This leads to the final target dependencies:

  C -> B0 -> B1 -> B2 -> A0 -> A1 -> A2

These produce a safe build order since C depends directly or
transitively on all the static libraries it links.

*/

//----------------------------------------------------------------------------
cmComputeTargetDepends::cmComputeTargetDepends(cmGlobalGenerator* gg)
{
  this->GlobalGenerator = gg;
  cmake* cm = this->GlobalGenerator->GetCMakeInstance();
102
103
104
105
  this->DebugMode = cm->GetState()
                      ->GetGlobalPropertyAsBool("GLOBAL_DEPENDS_DEBUG_MODE");
  this->NoCycles = cm->GetState()
                      ->GetGlobalPropertyAsBool("GLOBAL_DEPENDS_NO_CYCLES");
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
}

//----------------------------------------------------------------------------
cmComputeTargetDepends::~cmComputeTargetDepends()
{
}

//----------------------------------------------------------------------------
bool cmComputeTargetDepends::Compute()
{
  // Build the original graph.
  this->CollectTargets();
  this->CollectDepends();
  if(this->DebugMode)
    {
121
    this->DisplayGraph(this->InitialGraph, "initial");
122
123
124
    }

  // Identify components.
125
  cmComputeComponentGraph ccg(this->InitialGraph);
126
127
  if(this->DebugMode)
    {
128
    this->DisplayComponents(ccg);
129
    }
130
  if(!this->CheckComponents(ccg))
131
132
133
134
135
    {
    return false;
    }

  // Compute the final dependency graph.
136
137
138
139
  if(!this->ComputeFinalDepends(ccg))
    {
    return false;
    }
140
141
  if(this->DebugMode)
    {
142
    this->DisplayGraph(this->FinalGraph, "final");
143
144
145
146
147
148
149
    }

  return true;
}

//----------------------------------------------------------------------------
void
150
cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t,
151
                                               cmTargetDependSet& deps)
152
153
154
{
  // Lookup the index for this target.  All targets should be known by
  // this point.
155
  std::map<cmGeneratorTarget const*, int>::const_iterator tii
156
                                                  = this->TargetIndex.find(t);
157
158
159
160
  assert(tii != this->TargetIndex.end());
  int i = tii->second;

  // Get its final dependencies.
161
162
  EdgeList const& nl = this->FinalGraph[i];
  for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
163
    {
164
    cmGeneratorTarget const* dep = this->Targets[*ni];
165
166
    cmTargetDependSet::iterator di = deps.insert(dep).first;
    di->SetType(ni->IsStrong());
167
168
169
170
171
172
173
174
175
176
177
    }
}

//----------------------------------------------------------------------------
void cmComputeTargetDepends::CollectTargets()
{
  // Collect all targets from all generators.
  std::vector<cmLocalGenerator*> const& lgens =
    this->GlobalGenerator->GetLocalGenerators();
  for(unsigned int i = 0; i < lgens.size(); ++i)
    {
178
179
180
    const cmTargets& targets = lgens[i]->GetMakefile()->GetTargets();
    for(cmTargets::const_iterator ti = targets.begin();
        ti != targets.end(); ++ti)
181
      {
182
      cmTarget const* target = &ti->second;
183
184
      cmGeneratorTarget* gt =
          this->GlobalGenerator->GetGeneratorTarget(target);
185
      int index = static_cast<int>(this->Targets.size());
186
187
      this->TargetIndex[gt] = index;
      this->Targets.push_back(gt);
188
189
190
191
192
193
194
195
      }
    }
}

//----------------------------------------------------------------------------
void cmComputeTargetDepends::CollectDepends()
{
  // Allocate the dependency graph adjacency lists.
196
  this->InitialGraph.resize(this->Targets.size());
197
198
199
200
201
202
203
204
205
206
207
208

  // Compute each dependency list.
  for(unsigned int i=0; i < this->Targets.size(); ++i)
    {
    this->CollectTargetDepends(i);
    }
}

//----------------------------------------------------------------------------
void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
{
  // Get the depender.
209
  cmGeneratorTarget const* depender = this->Targets[depender_index];
210
  if (depender->GetType() == cmState::INTERFACE_LIBRARY)
211
212
213
    {
    return;
    }
214

215
216
217
218
  // Loop over all targets linked directly in all configs.
  // We need to make targets depend on the union of all config-specific
  // dependencies in all targets, because the generated build-systems can't
  // deal with config-specific dependencies.
219
  {
220
  std::set<std::string> emitted;
221

222
  std::vector<std::string> configs;
223
  depender->Makefile->GetConfigurations(configs);
224
225
226
227
  if (configs.empty())
    {
    configs.push_back("");
    }
228
229
230
  for (std::vector<std::string>::const_iterator it = configs.begin();
    it != configs.end(); ++it)
    {
231
    std::vector<cmSourceFile const*> objectFiles;
232
    depender->GetExternalObjects(objectFiles, *it);
233
234
235
236
237
238
    for(std::vector<cmSourceFile const*>::const_iterator
        oi = objectFiles.begin(); oi != objectFiles.end(); ++oi)
      {
      std::string objLib = (*oi)->GetObjectLibrary();
      if (!objLib.empty() && emitted.insert(objLib).second)
        {
239
240
241
242
        if(depender->GetType() != cmState::EXECUTABLE &&
            depender->GetType() != cmState::STATIC_LIBRARY &&
            depender->GetType() != cmState::SHARED_LIBRARY &&
            depender->GetType() != cmState::MODULE_LIBRARY)
243
244
245
246
247
          {
          this->GlobalGenerator->GetCMakeInstance()
            ->IssueMessage(cmake::FATAL_ERROR,
                            "Only executables and non-OBJECT libraries may "
                            "reference target objects.",
248
                            depender->Target->GetBacktrace());
249
250
          return;
          }
251
        const_cast<cmGeneratorTarget*>(depender)->Target->AddUtility(objLib);
252
253
        }
      }
254

255
    cmLinkImplementation const* impl = depender->GetLinkImplementation(*it);
256

257
258
    // A target should not depend on itself.
    emitted.insert(depender->GetName());
259
    for(std::vector<cmLinkImplItem>::const_iterator
260
261
          lib = impl->Libraries.begin();
        lib != impl->Libraries.end(); ++lib)
262
263
264
265
      {
      // Don't emit the same library twice for this target.
      if(emitted.insert(*lib).second)
        {
Stephen Kelly's avatar
Stephen Kelly committed
266
        this->AddTargetDepend(depender_index, *lib, true);
267
        this->AddInterfaceDepends(depender_index, *lib, emitted);
268
269
270
271
        }
      }
    }
  }
272
273

  // Loop over all utility dependencies.
274
  {
275
  std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
276
  std::set<std::string> emitted;
277
278
  // A target should not depend on itself.
  emitted.insert(depender->GetName());
279
  for(std::set<cmLinkItem>::const_iterator util = tutils.begin();
280
281
282
283
284
      util != tutils.end(); ++util)
    {
    // Don't emit the same utility twice for this target.
    if(emitted.insert(*util).second)
      {
Stephen Kelly's avatar
Stephen Kelly committed
285
      this->AddTargetDepend(depender_index, *util, false);
286
287
      }
    }
288
  }
289
290
}

291
292
//----------------------------------------------------------------------------
void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
293
294
295
                                             const cmGeneratorTarget* dependee,
                                             const std::string& config,
                                             std::set<std::string> &emitted)
296
{
297
  cmGeneratorTarget const* depender = this->Targets[depender_index];
298
  if(cmLinkInterface const* iface =
299
                                dependee->GetLinkInterface(config,
300
                                                           depender))
301
    {
302
    for(std::vector<cmLinkItem>::const_iterator
303
304
305
306
307
308
        lib = iface->Libraries.begin();
        lib != iface->Libraries.end(); ++lib)
      {
      // Don't emit the same library twice for this target.
      if(emitted.insert(*lib).second)
        {
Stephen Kelly's avatar
Stephen Kelly committed
309
        this->AddTargetDepend(depender_index, *lib, true);
310
        this->AddInterfaceDepends(depender_index, *lib, emitted);
311
312
313
314
315
316
317
        }
      }
    }
}

//----------------------------------------------------------------------------
void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
318
                                             cmLinkItem const& dependee_name,
319
                                             std::set<std::string> &emitted)
320
{
321
  cmGeneratorTarget const* depender = this->Targets[depender_index];
322
  cmGeneratorTarget const* dependee = dependee_name.Target;
323
324
325
  // Skip targets that will not really be linked.  This is probably a
  // name conflict between an external library and an executable
  // within the project.
326
  if(dependee &&
327
     dependee->GetType() == cmState::EXECUTABLE &&
328
     !dependee->Target->IsExecutableWithExports())
329
330
331
332
333
334
    {
    dependee = 0;
    }

  if(dependee)
    {
335
    this->AddInterfaceDepends(depender_index, dependee, "", emitted);
336
    std::vector<std::string> configs;
337
    depender->Makefile->GetConfigurations(configs);
338
339
340
341
342
    for (std::vector<std::string>::const_iterator it = configs.begin();
      it != configs.end(); ++it)
      {
      // A target should not depend on itself.
      emitted.insert(depender->GetName());
343
      this->AddInterfaceDepends(depender_index, dependee, *it, emitted);
344
345
346
347
      }
    }
}

348
//----------------------------------------------------------------------------
349
350
351
void cmComputeTargetDepends::AddTargetDepend(
  int depender_index, cmLinkItem const& dependee_name,
  bool linking)
352
353
{
  // Get the depender.
354
  cmGeneratorTarget const* depender = this->Targets[depender_index];
355
356

  // Check the target's makefile first.
357
  cmGeneratorTarget const* dependee = dependee_name.Target;
358

359
  if(!dependee && !linking &&
360
    (depender->GetType() != cmState::GLOBAL_TARGET))
361
362
363
    {
    cmake::MessageType messageType = cmake::AUTHOR_WARNING;
    bool issueMessage = false;
364
    std::ostringstream e;
365
    switch(depender->Target->GetPolicyStatusCMP0046())
366
367
      {
      case cmPolicies::WARN:
Stephen Kelly's avatar
Stephen Kelly committed
368
        e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0046) << "\n";
369
370
371
372
373
374
375
376
377
378
379
380
        issueMessage = true;
      case cmPolicies::OLD:
        break;
      case cmPolicies::NEW:
      case cmPolicies::REQUIRED_IF_USED:
      case cmPolicies::REQUIRED_ALWAYS:
        issueMessage = true;
        messageType = cmake::FATAL_ERROR;
      }
    if(issueMessage)
      {
      cmake* cm = this->GlobalGenerator->GetCMakeInstance();
381

382
383
384
385
      e << "The dependency target \"" <<  dependee_name
        << "\" of target \"" << depender->GetName() << "\" does not exist.";

      cmListFileBacktrace const* backtrace =
386
        depender->Target->GetUtilityBacktrace(dependee_name);
387
      if(backtrace)
388
        {
389
390
391
392
393
        cm->IssueMessage(messageType, e.str(), *backtrace);
        }
      else
        {
        cm->IssueMessage(messageType, e.str());
394
395
396
397
398
        }

      }
    }

399
400
401
402
  // Skip targets that will not really be linked.  This is probably a
  // name conflict between an external library and an executable
  // within the project.
  if(linking && dependee &&
403
     dependee->GetType() == cmState::EXECUTABLE &&
404
     !dependee->Target->IsExecutableWithExports())
405
406
407
408
    {
    dependee = 0;
    }

409
  if(dependee)
410
    {
411
    this->AddTargetDepend(depender_index, dependee, linking);
412
    }
413
}
414

415
416
//----------------------------------------------------------------------------
void cmComputeTargetDepends::AddTargetDepend(int depender_index,
417
                                             const cmGeneratorTarget* dependee,
418
419
                                             bool linking)
{
420
  if(dependee->Target->IsImported() ||
421
     dependee->GetType() == cmState::INTERFACE_LIBRARY)
422
    {
423
424
    // Skip IMPORTED and INTERFACE targets but follow their utility
    // dependencies.
425
    std::set<cmLinkItem> const& utils = dependee->GetUtilityItems();
426
    for(std::set<cmLinkItem>::const_iterator i = utils.begin();
427
428
        i != utils.end(); ++i)
      {
429
      if(cmGeneratorTarget const* transitive_dependee = i->Target)
430
        {
431
        this->AddTargetDepend(depender_index, transitive_dependee, false);
432
        }
433
434
435
436
437
438
      }
    }
  else
    {
    // Lookup the index for this target.  All targets should be known by
    // this point.
439
    std::map<cmGeneratorTarget const*, int>::const_iterator tii =
440
441
442
443
444
445
446
447
      this->TargetIndex.find(dependee);
    assert(tii != this->TargetIndex.end());
    int dependee_index = tii->second;

    // Add this entry to the dependency graph.
    this->InitialGraph[depender_index].push_back(
      cmGraphEdge(dependee_index, !linking));
    }
448
449
450
451
}

//----------------------------------------------------------------------------
void
452
453
cmComputeTargetDepends::DisplayGraph(Graph const& graph,
                                     const std::string& name)
454
{
455
  fprintf(stderr, "The %s target dependency graph is:\n", name.c_str());
456
457
458
  int n = static_cast<int>(graph.size());
  for(int depender_index = 0; depender_index < n; ++depender_index)
    {
459
    EdgeList const& nl = graph[depender_index];
460
    cmGeneratorTarget const* depender = this->Targets[depender_index];
461
    fprintf(stderr, "target %d is [%s]\n",
462
            depender_index, depender->GetName().c_str());
463
    for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
464
      {
465
      int dependee_index = *ni;
466
      cmGeneratorTarget const* dependee = this->Targets[dependee_index];
467
      fprintf(stderr, "  depends on target %d [%s] (%s)\n", dependee_index,
468
              dependee->GetName().c_str(), ni->IsStrong()? "strong" : "weak");
469
470
471
472
473
474
      }
    }
  fprintf(stderr, "\n");
}

//----------------------------------------------------------------------------
475
476
477
void
cmComputeTargetDepends
::DisplayComponents(cmComputeComponentGraph const& ccg)
478
479
{
  fprintf(stderr, "The strongly connected components are:\n");
480
481
  std::vector<NodeList> const& components = ccg.GetComponents();
  int n = static_cast<int>(components.size());
482
483
  for(int c = 0; c < n; ++c)
    {
484
    NodeList const& nl = components[c];
485
    fprintf(stderr, "Component (%d):\n", c);
486
    for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
487
      {
488
      int i = *ni;
489
      fprintf(stderr, "  contains target %d [%s]\n",
490
              i, this->Targets[i]->GetName().c_str());
491
492
493
494
495
496
      }
    }
  fprintf(stderr, "\n");
}

//----------------------------------------------------------------------------
497
498
499
bool
cmComputeTargetDepends
::CheckComponents(cmComputeComponentGraph const& ccg)
500
501
502
{
  // All non-trivial components should consist only of static
  // libraries.
503
504
  std::vector<NodeList> const& components = ccg.GetComponents();
  int nc = static_cast<int>(components.size());
505
506
507
  for(int c=0; c < nc; ++c)
    {
    // Get the current component.
508
    NodeList const& nl = components[c];
509
510

    // Skip trivial components.
511
    if(nl.size() < 2)
512
513
514
515
      {
      continue;
      }

516
517
518
519
520
521
522
    // Immediately complain if no cycles are allowed at all.
    if(this->NoCycles)
      {
      this->ComplainAboutBadComponent(ccg, c);
      return false;
      }

523
    // Make sure the component is all STATIC_LIBRARY targets.
524
    for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
525
      {
526
      if(this->Targets[*ni]->GetType() != cmState::STATIC_LIBRARY)
527
        {
528
        this->ComplainAboutBadComponent(ccg, c);
529
530
531
532
533
534
535
536
537
        return false;
        }
      }
    }
  return true;
}

//----------------------------------------------------------------------------
void
538
cmComputeTargetDepends
539
540
::ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
                            bool strong)
541
542
{
  // Construct the error message.
543
  std::ostringstream e;
544
545
  e << "The inter-target dependency graph contains the following "
    << "strongly connected component (cycle):\n";
546
547
548
549
  std::vector<NodeList> const& components = ccg.GetComponents();
  std::vector<int> const& cmap = ccg.GetComponentMap();
  NodeList const& cl = components[c];
  for(NodeList::const_iterator ci = cl.begin(); ci != cl.end(); ++ci)
550
551
552
    {
    // Get the depender.
    int i = *ci;
553
    cmGeneratorTarget const* depender = this->Targets[i];
554
555

    // Describe the depender.
556
    e << "  \"" << depender->GetName() << "\" of type "
557
      << cmTarget::GetTargetTypeName(
558
           (cmState::TargetType)depender->GetType()) << "\n";
559
560

    // List its dependencies that are inside the component.
561
562
    EdgeList const& nl = this->InitialGraph[i];
    for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
563
      {
564
565
      int j = *ni;
      if(cmap[j] == c)
566
        {
567
        cmGeneratorTarget const* dependee = this->Targets[j];
568
569
        e << "    depends on \"" << dependee->GetName() << "\""
          << " (" << (ni->IsStrong()? "strong" : "weak") << ")\n";
570
571
572
        }
      }
    }
573
574
575
576
577
578
579
580
581
  if(strong)
    {
    // Custom command executable dependencies cannot occur within a
    // component of static libraries.  The cycle must appear in calls
    // to add_dependencies.
    e << "The component contains at least one cycle consisting of strong "
      << "dependencies (created by add_dependencies) that cannot be broken.";
    }
  else if(this->NoCycles)
582
583
584
585
586
587
588
589
590
    {
    e << "The GLOBAL_DEPENDS_NO_CYCLES global property is enabled, so "
      << "cyclic dependencies are not allowed even among static libraries.";
    }
  else
    {
    e << "At least one of these targets is not a STATIC_LIBRARY.  "
      << "Cyclic dependencies are allowed only among static libraries.";
    }
591
592
593
594
  cmSystemTools::Error(e.str().c_str());
}

//----------------------------------------------------------------------------
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
bool
cmComputeTargetDepends
::IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
                 std::set<int>& emitted, std::set<int>& visited)
{
  if(!visited.insert(i).second)
    {
    // Cycle in utility depends!
    return false;
    }
  if(emitted.insert(i).second)
    {
    // Honor strong intra-component edges in the final order.
    EdgeList const& el = this->InitialGraph[i];
    for(EdgeList::const_iterator ei = el.begin(); ei != el.end(); ++ei)
      {
      int j = *ei;
      if(cmap[j] == c && ei->IsStrong())
        {
614
        this->FinalGraph[i].push_back(cmGraphEdge(j, true));
615
616
617
618
619
620
621
622
623
624
        if(!this->IntraComponent(cmap, c, j, head, emitted, visited))
          {
          return false;
          }
        }
      }

    // Prepend to a linear linked-list of intra-component edges.
    if(*head >= 0)
      {
625
      this->FinalGraph[i].push_back(cmGraphEdge(*head, false));
626
627
628
629
630
631
632
633
634
635
636
637
      }
    else
      {
      this->ComponentTail[c] = i;
      }
    *head = i;
    }
  return true;
}

//----------------------------------------------------------------------------
bool
638
639
cmComputeTargetDepends
::ComputeFinalDepends(cmComputeComponentGraph const& ccg)
640
{
641
642
643
644
645
646
647
  // Get the component graph information.
  std::vector<NodeList> const& components = ccg.GetComponents();
  Graph const& cgraph = ccg.GetComponentGraph();

  // Allocate the final graph.
  this->FinalGraph.resize(0);
  this->FinalGraph.resize(this->InitialGraph.size());
648

649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
  // Choose intra-component edges to linearize dependencies.
  std::vector<int> const& cmap = ccg.GetComponentMap();
  this->ComponentHead.resize(components.size());
  this->ComponentTail.resize(components.size());
  int nc = static_cast<int>(components.size());
  for(int c=0; c < nc; ++c)
    {
    int head = -1;
    std::set<int> emitted;
    NodeList const& nl = components[c];
    for(NodeList::const_reverse_iterator ni = nl.rbegin();
        ni != nl.rend(); ++ni)
      {
      std::set<int> visited;
      if(!this->IntraComponent(cmap, c, *ni, &head, emitted, visited))
        {
        // Cycle in add_dependencies within component!
        this->ComplainAboutBadComponent(ccg, c, true);
        return false;
        }
      }
    this->ComponentHead[c] = head;
    }

673
  // Convert inter-component edges to connect component tails to heads.
674
675
  int n = static_cast<int>(cgraph.size());
  for(int depender_component=0; depender_component < n; ++depender_component)
676
    {
677
    int depender_component_tail = this->ComponentTail[depender_component];
678
679
    EdgeList const& nl = cgraph[depender_component];
    for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
680
      {
681
      int dependee_component = *ni;
682
      int dependee_component_head = this->ComponentHead[dependee_component];
683
      this->FinalGraph[depender_component_tail]
684
        .push_back(cmGraphEdge(dependee_component_head, ni->IsStrong()));
685
686
      }
    }
687
  return true;
688
}