2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2008-02-06 07:10:41 +03:00
|
|
|
#include "cmComputeTargetDepends.h"
|
|
|
|
|
2008-02-08 00:14:05 +03:00
|
|
|
#include "cmComputeComponentGraph.h"
|
2008-02-06 07:10:41 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2015-04-11 15:15:55 +03:00
|
|
|
#include "cmState.h"
|
2008-02-06 07:10:41 +03:00
|
|
|
#include "cmSystemTools.h"
|
2014-03-18 20:04:46 +04:00
|
|
|
#include "cmSourceFile.h"
|
2008-02-06 07:10:41 +03:00
|
|
|
#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
|
2012-02-26 22:44:20 +04:00
|
|
|
STATIC libraries may depend on each other in a cyclic fashion. In
|
2008-02-06 07:10:41 +03:00
|
|
|
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();
|
2015-04-11 15:15:55 +03:00
|
|
|
this->DebugMode = cm->GetState()
|
|
|
|
->GetGlobalPropertyAsBool("GLOBAL_DEPENDS_DEBUG_MODE");
|
|
|
|
this->NoCycles = cm->GetState()
|
|
|
|
->GetGlobalPropertyAsBool("GLOBAL_DEPENDS_NO_CYCLES");
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmComputeTargetDepends::~cmComputeTargetDepends()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmComputeTargetDepends::Compute()
|
|
|
|
{
|
|
|
|
// Build the original graph.
|
|
|
|
this->CollectTargets();
|
|
|
|
this->CollectDepends();
|
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
this->DisplayGraph(this->InitialGraph, "initial");
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Identify components.
|
2008-02-08 00:14:05 +03:00
|
|
|
cmComputeComponentGraph ccg(this->InitialGraph);
|
2008-02-06 07:10:41 +03:00
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
this->DisplayComponents(ccg);
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
2008-02-08 00:14:05 +03:00
|
|
|
if(!this->CheckComponents(ccg))
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the final dependency graph.
|
2010-08-25 18:14:31 +04:00
|
|
|
if(!this->ComputeFinalDepends(ccg))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
if(this->DebugMode)
|
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
this->DisplayGraph(this->FinalGraph, "final");
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
2015-06-06 14:08:17 +03:00
|
|
|
cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t,
|
2010-08-25 18:07:25 +04:00
|
|
|
cmTargetDependSet& deps)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
// Lookup the index for this target. All targets should be known by
|
|
|
|
// this point.
|
2015-06-06 14:08:17 +03:00
|
|
|
std::map<cmGeneratorTarget const*, int>::const_iterator tii
|
2013-12-10 18:16:23 +04:00
|
|
|
= this->TargetIndex.find(t);
|
2008-02-06 07:10:41 +03:00
|
|
|
assert(tii != this->TargetIndex.end());
|
|
|
|
int i = tii->second;
|
|
|
|
|
|
|
|
// Get its final dependencies.
|
2010-08-20 22:11:18 +04:00
|
|
|
EdgeList const& nl = this->FinalGraph[i];
|
|
|
|
for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* dep = this->Targets[*ni];
|
2010-08-25 18:07:25 +04:00
|
|
|
cmTargetDependSet::iterator di = deps.insert(dep).first;
|
|
|
|
di->SetType(ni->IsStrong());
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2013-12-10 18:16:23 +04:00
|
|
|
const cmTargets& targets = lgens[i]->GetMakefile()->GetTargets();
|
|
|
|
for(cmTargets::const_iterator ti = targets.begin();
|
|
|
|
ti != targets.end(); ++ti)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2013-12-10 18:16:23 +04:00
|
|
|
cmTarget const* target = &ti->second;
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget* gt =
|
|
|
|
this->GlobalGenerator->GetGeneratorTarget(target);
|
2008-02-06 07:10:41 +03:00
|
|
|
int index = static_cast<int>(this->Targets.size());
|
2015-06-06 14:08:17 +03:00
|
|
|
this->TargetIndex[gt] = index;
|
|
|
|
this->Targets.push_back(gt);
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmComputeTargetDepends::CollectDepends()
|
|
|
|
{
|
|
|
|
// Allocate the dependency graph adjacency lists.
|
2008-02-08 00:14:05 +03:00
|
|
|
this->InitialGraph.resize(this->Targets.size());
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// 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.
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[depender_index];
|
2013-12-10 20:16:08 +04:00
|
|
|
if (depender->GetType() == cmTarget::INTERFACE_LIBRARY)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2012-12-06 15:14:03 +04:00
|
|
|
// 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.
|
2010-08-25 18:07:25 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> emitted;
|
2014-02-13 20:25:00 +04:00
|
|
|
|
2012-12-06 15:14:03 +04:00
|
|
|
std::vector<std::string> configs;
|
2015-06-06 14:08:17 +03:00
|
|
|
depender->Makefile->GetConfigurations(configs);
|
2014-03-25 16:34:38 +04:00
|
|
|
if (configs.empty())
|
|
|
|
{
|
|
|
|
configs.push_back("");
|
|
|
|
}
|
2012-12-06 15:14:03 +04:00
|
|
|
for (std::vector<std::string>::const_iterator it = configs.begin();
|
|
|
|
it != configs.end(); ++it)
|
|
|
|
{
|
2014-02-13 20:25:00 +04:00
|
|
|
std::vector<cmSourceFile const*> objectFiles;
|
2015-06-06 14:08:17 +03:00
|
|
|
depender->GetExternalObjects(objectFiles, *it);
|
2014-02-13 20:25:00 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(depender->GetType() != cmTarget::EXECUTABLE &&
|
|
|
|
depender->GetType() != cmTarget::STATIC_LIBRARY &&
|
|
|
|
depender->GetType() != cmTarget::SHARED_LIBRARY &&
|
|
|
|
depender->GetType() != cmTarget::MODULE_LIBRARY)
|
|
|
|
{
|
|
|
|
this->GlobalGenerator->GetCMakeInstance()
|
|
|
|
->IssueMessage(cmake::FATAL_ERROR,
|
|
|
|
"Only executables and non-OBJECT libraries may "
|
|
|
|
"reference target objects.",
|
2015-06-06 14:08:17 +03:00
|
|
|
depender->Target->GetBacktrace());
|
2014-02-13 20:25:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-06-06 14:08:17 +03:00
|
|
|
const_cast<cmGeneratorTarget*>(depender)->Target->AddUtility(objLib);
|
2014-02-13 20:25:00 +04:00
|
|
|
}
|
|
|
|
}
|
2014-06-16 19:49:10 +04:00
|
|
|
|
2015-08-05 18:37:49 +03:00
|
|
|
cmLinkImplementation const* impl = depender->GetLinkImplementation(*it);
|
2013-12-10 20:16:08 +04:00
|
|
|
|
2012-12-06 15:14:03 +04:00
|
|
|
// A target should not depend on itself.
|
|
|
|
emitted.insert(depender->GetName());
|
2014-06-30 18:38:59 +04:00
|
|
|
for(std::vector<cmLinkImplItem>::const_iterator
|
2014-06-16 19:49:10 +04:00
|
|
|
lib = impl->Libraries.begin();
|
|
|
|
lib != impl->Libraries.end(); ++lib)
|
2012-12-06 15:14:03 +04:00
|
|
|
{
|
|
|
|
// Don't emit the same library twice for this target.
|
|
|
|
if(emitted.insert(*lib).second)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->AddTargetDepend(depender_index, *lib, true);
|
2014-06-16 17:49:13 +04:00
|
|
|
this->AddInterfaceDepends(depender_index, *lib, emitted);
|
2012-12-06 15:14:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// Loop over all utility dependencies.
|
2010-08-25 18:07:25 +04:00
|
|
|
{
|
2015-10-08 02:01:38 +03:00
|
|
|
std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> emitted;
|
2010-08-25 18:07:25 +04:00
|
|
|
// A target should not depend on itself.
|
|
|
|
emitted.insert(depender->GetName());
|
2014-06-16 19:49:10 +04:00
|
|
|
for(std::set<cmLinkItem>::const_iterator util = tutils.begin();
|
2008-02-06 07:10:41 +03:00
|
|
|
util != tutils.end(); ++util)
|
|
|
|
{
|
|
|
|
// Don't emit the same utility twice for this target.
|
|
|
|
if(emitted.insert(*util).second)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->AddTargetDepend(depender_index, *util, false);
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
2010-08-25 18:07:25 +04:00
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
|
2012-12-26 13:58:21 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
|
2015-06-06 14:08:17 +03:00
|
|
|
const cmGeneratorTarget* dependee,
|
|
|
|
const std::string& config,
|
|
|
|
std::set<std::string> &emitted)
|
2012-12-26 13:58:21 +04:00
|
|
|
{
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[depender_index];
|
2015-08-26 20:35:45 +03:00
|
|
|
if(cmLinkInterface const* iface =
|
2015-08-26 20:37:45 +03:00
|
|
|
dependee->GetLinkInterface(config,
|
2015-09-16 05:49:37 +03:00
|
|
|
depender))
|
2012-12-26 13:58:21 +04:00
|
|
|
{
|
2014-06-16 19:49:10 +04:00
|
|
|
for(std::vector<cmLinkItem>::const_iterator
|
2012-12-26 13:58:21 +04:00
|
|
|
lib = iface->Libraries.begin();
|
|
|
|
lib != iface->Libraries.end(); ++lib)
|
|
|
|
{
|
|
|
|
// Don't emit the same library twice for this target.
|
|
|
|
if(emitted.insert(*lib).second)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->AddTargetDepend(depender_index, *lib, true);
|
2014-06-16 17:49:13 +04:00
|
|
|
this->AddInterfaceDepends(depender_index, *lib, emitted);
|
2012-12-26 13:58:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmComputeTargetDepends::AddInterfaceDepends(int depender_index,
|
2014-06-16 19:49:10 +04:00
|
|
|
cmLinkItem const& dependee_name,
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> &emitted)
|
2012-12-26 13:58:21 +04:00
|
|
|
{
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[depender_index];
|
2015-10-08 02:18:42 +03:00
|
|
|
cmGeneratorTarget const* dependee = dependee_name.Target;
|
2012-12-26 13:58:21 +04:00
|
|
|
// Skip targets that will not really be linked. This is probably a
|
|
|
|
// name conflict between an external library and an executable
|
|
|
|
// within the project.
|
2014-06-16 17:49:13 +04:00
|
|
|
if(dependee &&
|
2012-12-26 13:58:21 +04:00
|
|
|
dependee->GetType() == cmTarget::EXECUTABLE &&
|
2015-10-08 02:18:42 +03:00
|
|
|
!dependee->Target->IsExecutableWithExports())
|
2012-12-26 13:58:21 +04:00
|
|
|
{
|
|
|
|
dependee = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dependee)
|
|
|
|
{
|
2015-10-08 02:18:42 +03:00
|
|
|
this->AddInterfaceDepends(depender_index, dependee, "", emitted);
|
2012-12-26 13:58:21 +04:00
|
|
|
std::vector<std::string> configs;
|
2015-06-06 14:08:17 +03:00
|
|
|
depender->Makefile->GetConfigurations(configs);
|
2012-12-26 13:58:21 +04:00
|
|
|
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());
|
2015-10-08 02:18:42 +03:00
|
|
|
this->AddInterfaceDepends(depender_index, dependee, *it, emitted);
|
2012-12-26 13:58:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:10:41 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2014-06-16 19:49:10 +04:00
|
|
|
void cmComputeTargetDepends::AddTargetDepend(
|
|
|
|
int depender_index, cmLinkItem const& dependee_name,
|
|
|
|
bool linking)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
// Get the depender.
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[depender_index];
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// Check the target's makefile first.
|
2015-10-08 02:18:42 +03:00
|
|
|
cmGeneratorTarget const* dependee = dependee_name.Target;
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2014-01-12 15:58:04 +04:00
|
|
|
if(!dependee && !linking &&
|
|
|
|
(depender->GetType() != cmTarget::GLOBAL_TARGET))
|
|
|
|
{
|
|
|
|
cmake::MessageType messageType = cmake::AUTHOR_WARNING;
|
|
|
|
bool issueMessage = false;
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2015-06-06 14:08:17 +03:00
|
|
|
switch(depender->Target->GetPolicyStatusCMP0046())
|
2014-01-12 15:58:04 +04:00
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0046) << "\n";
|
2014-01-12 15:58:04 +04:00
|
|
|
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();
|
2014-03-29 00:38:10 +04:00
|
|
|
|
2014-01-12 15:58:04 +04:00
|
|
|
e << "The dependency target \"" << dependee_name
|
|
|
|
<< "\" of target \"" << depender->GetName() << "\" does not exist.";
|
|
|
|
|
|
|
|
cmListFileBacktrace const* backtrace =
|
2015-06-06 14:08:17 +03:00
|
|
|
depender->Target->GetUtilityBacktrace(dependee_name);
|
2014-05-23 22:54:42 +04:00
|
|
|
if(backtrace)
|
2014-01-12 15:58:04 +04:00
|
|
|
{
|
2014-05-23 22:54:42 +04:00
|
|
|
cm->IssueMessage(messageType, e.str(), *backtrace);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cm->IssueMessage(messageType, e.str());
|
2014-01-12 15:58:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-07 01:48:53 +04:00
|
|
|
// 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 &&
|
|
|
|
dependee->GetType() == cmTarget::EXECUTABLE &&
|
2015-10-08 02:18:42 +03:00
|
|
|
!dependee->Target->IsExecutableWithExports())
|
2008-08-07 01:48:53 +04:00
|
|
|
{
|
|
|
|
dependee = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-19 21:36:11 +03:00
|
|
|
if(dependee)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2015-10-08 02:18:42 +03:00
|
|
|
this->AddTargetDepend(depender_index, dependee, linking);
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
2010-11-19 21:36:11 +03:00
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2010-11-19 21:36:11 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmComputeTargetDepends::AddTargetDepend(int depender_index,
|
2015-06-06 14:08:17 +03:00
|
|
|
const cmGeneratorTarget* dependee,
|
2010-11-19 21:36:11 +03:00
|
|
|
bool linking)
|
|
|
|
{
|
2015-06-06 14:08:17 +03:00
|
|
|
if(dependee->Target->IsImported() ||
|
2015-03-27 23:25:09 +03:00
|
|
|
dependee->GetType() == cmTarget::INTERFACE_LIBRARY)
|
2010-11-19 21:36:11 +03:00
|
|
|
{
|
2015-03-27 23:25:09 +03:00
|
|
|
// Skip IMPORTED and INTERFACE targets but follow their utility
|
|
|
|
// dependencies.
|
2015-10-08 02:01:38 +03:00
|
|
|
std::set<cmLinkItem> const& utils = dependee->GetUtilityItems();
|
2014-06-16 18:58:23 +04:00
|
|
|
for(std::set<cmLinkItem>::const_iterator i = utils.begin();
|
2010-11-19 21:36:11 +03:00
|
|
|
i != utils.end(); ++i)
|
|
|
|
{
|
2015-10-08 02:18:42 +03:00
|
|
|
if(cmGeneratorTarget const* transitive_dependee = i->Target)
|
2011-08-04 23:35:59 +04:00
|
|
|
{
|
2015-10-08 02:18:42 +03:00
|
|
|
this->AddTargetDepend(depender_index, transitive_dependee, false);
|
2011-08-04 23:35:59 +04:00
|
|
|
}
|
2010-11-19 21:36:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Lookup the index for this target. All targets should be known by
|
|
|
|
// this point.
|
2015-06-06 14:08:17 +03:00
|
|
|
std::map<cmGeneratorTarget const*, int>::const_iterator tii =
|
2010-11-19 21:36:11 +03:00
|
|
|
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));
|
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
2014-02-07 02:31:47 +04:00
|
|
|
cmComputeTargetDepends::DisplayGraph(Graph const& graph,
|
|
|
|
const std::string& name)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2014-02-07 02:31:47 +04:00
|
|
|
fprintf(stderr, "The %s target dependency graph is:\n", name.c_str());
|
2008-02-06 07:10:41 +03:00
|
|
|
int n = static_cast<int>(graph.size());
|
|
|
|
for(int depender_index = 0; depender_index < n; ++depender_index)
|
|
|
|
{
|
2010-08-20 22:11:18 +04:00
|
|
|
EdgeList const& nl = graph[depender_index];
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[depender_index];
|
2008-02-06 07:10:41 +03:00
|
|
|
fprintf(stderr, "target %d is [%s]\n",
|
2014-02-07 02:31:47 +04:00
|
|
|
depender_index, depender->GetName().c_str());
|
2010-08-20 22:11:18 +04:00
|
|
|
for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
int dependee_index = *ni;
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* dependee = this->Targets[dependee_index];
|
2010-08-25 18:07:25 +04:00
|
|
|
fprintf(stderr, " depends on target %d [%s] (%s)\n", dependee_index,
|
2014-02-07 02:31:47 +04:00
|
|
|
dependee->GetName().c_str(), ni->IsStrong()? "strong" : "weak");
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-02-08 00:14:05 +03:00
|
|
|
void
|
|
|
|
cmComputeTargetDepends
|
|
|
|
::DisplayComponents(cmComputeComponentGraph const& ccg)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, "The strongly connected components are:\n");
|
2008-02-08 00:14:05 +03:00
|
|
|
std::vector<NodeList> const& components = ccg.GetComponents();
|
|
|
|
int n = static_cast<int>(components.size());
|
2008-02-06 07:10:41 +03:00
|
|
|
for(int c = 0; c < n; ++c)
|
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
NodeList const& nl = components[c];
|
2008-02-06 07:10:41 +03:00
|
|
|
fprintf(stderr, "Component (%d):\n", c);
|
2008-02-08 00:14:05 +03:00
|
|
|
for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
int i = *ni;
|
2008-02-06 07:10:41 +03:00
|
|
|
fprintf(stderr, " contains target %d [%s]\n",
|
2014-02-07 02:31:47 +04:00
|
|
|
i, this->Targets[i]->GetName().c_str());
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-02-08 00:14:05 +03:00
|
|
|
bool
|
|
|
|
cmComputeTargetDepends
|
|
|
|
::CheckComponents(cmComputeComponentGraph const& ccg)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
// All non-trivial components should consist only of static
|
|
|
|
// libraries.
|
2008-02-08 00:14:05 +03:00
|
|
|
std::vector<NodeList> const& components = ccg.GetComponents();
|
|
|
|
int nc = static_cast<int>(components.size());
|
2008-02-06 07:10:41 +03:00
|
|
|
for(int c=0; c < nc; ++c)
|
|
|
|
{
|
|
|
|
// Get the current component.
|
2008-02-08 00:14:05 +03:00
|
|
|
NodeList const& nl = components[c];
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// Skip trivial components.
|
2008-02-08 00:14:05 +03:00
|
|
|
if(nl.size() < 2)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-24 17:54:27 +04:00
|
|
|
// Immediately complain if no cycles are allowed at all.
|
|
|
|
if(this->NoCycles)
|
|
|
|
{
|
|
|
|
this->ComplainAboutBadComponent(ccg, c);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:10:41 +03:00
|
|
|
// Make sure the component is all STATIC_LIBRARY targets.
|
2008-02-08 00:14:05 +03:00
|
|
|
for(NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
if(this->Targets[*ni]->GetType() != cmTarget::STATIC_LIBRARY)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
this->ComplainAboutBadComponent(ccg, c);
|
2008-02-06 07:10:41 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
2008-02-08 00:14:05 +03:00
|
|
|
cmComputeTargetDepends
|
2010-08-25 18:14:31 +04:00
|
|
|
::ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
|
|
|
|
bool strong)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
// Construct the error message.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-02-06 07:10:41 +03:00
|
|
|
e << "The inter-target dependency graph contains the following "
|
|
|
|
<< "strongly connected component (cycle):\n";
|
2008-02-08 00:14:05 +03:00
|
|
|
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)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
|
|
|
// Get the depender.
|
|
|
|
int i = *ci;
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* depender = this->Targets[i];
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// Describe the depender.
|
2008-08-07 01:48:49 +04:00
|
|
|
e << " \"" << depender->GetName() << "\" of type "
|
2015-06-06 14:08:17 +03:00
|
|
|
<< cmTarget::GetTargetTypeName(depender->Target->GetType()) << "\n";
|
2008-02-06 07:10:41 +03:00
|
|
|
|
|
|
|
// List its dependencies that are inside the component.
|
2010-08-20 22:11:18 +04:00
|
|
|
EdgeList const& nl = this->InitialGraph[i];
|
|
|
|
for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
int j = *ni;
|
|
|
|
if(cmap[j] == c)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2015-06-06 14:08:17 +03:00
|
|
|
cmGeneratorTarget const* dependee = this->Targets[j];
|
2010-08-25 18:07:25 +04:00
|
|
|
e << " depends on \"" << dependee->GetName() << "\""
|
|
|
|
<< " (" << (ni->IsStrong()? "strong" : "weak") << ")\n";
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 18:14:31 +04:00
|
|
|
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)
|
2009-08-24 17:54:27 +04:00
|
|
|
{
|
|
|
|
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.";
|
|
|
|
}
|
2008-02-06 07:10:41 +03:00
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2010-08-25 18:14:31 +04:00
|
|
|
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())
|
|
|
|
{
|
2010-08-25 18:07:25 +04:00
|
|
|
this->FinalGraph[i].push_back(cmGraphEdge(j, true));
|
2010-08-25 18:14:31 +04:00
|
|
|
if(!this->IntraComponent(cmap, c, j, head, emitted, visited))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepend to a linear linked-list of intra-component edges.
|
|
|
|
if(*head >= 0)
|
|
|
|
{
|
2010-08-25 18:07:25 +04:00
|
|
|
this->FinalGraph[i].push_back(cmGraphEdge(*head, false));
|
2010-08-25 18:14:31 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->ComponentTail[c] = i;
|
|
|
|
}
|
|
|
|
*head = i;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool
|
2008-02-08 00:14:05 +03:00
|
|
|
cmComputeTargetDepends
|
|
|
|
::ComputeFinalDepends(cmComputeComponentGraph const& ccg)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
// 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());
|
2008-02-06 07:10:41 +03:00
|
|
|
|
2010-08-25 18:14:31 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-02-06 07:10:41 +03:00
|
|
|
// Convert inter-component edges to connect component tails to heads.
|
2008-02-08 00:14:05 +03:00
|
|
|
int n = static_cast<int>(cgraph.size());
|
|
|
|
for(int depender_component=0; depender_component < n; ++depender_component)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2010-08-25 18:14:31 +04:00
|
|
|
int depender_component_tail = this->ComponentTail[depender_component];
|
2010-08-20 22:11:18 +04:00
|
|
|
EdgeList const& nl = cgraph[depender_component];
|
|
|
|
for(EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni)
|
2008-02-06 07:10:41 +03:00
|
|
|
{
|
2008-02-08 00:14:05 +03:00
|
|
|
int dependee_component = *ni;
|
2010-08-25 18:14:31 +04:00
|
|
|
int dependee_component_head = this->ComponentHead[dependee_component];
|
2008-02-08 00:14:05 +03:00
|
|
|
this->FinalGraph[depender_component_tail]
|
2010-08-25 18:07:25 +04:00
|
|
|
.push_back(cmGraphEdge(dependee_component_head, ni->IsStrong()));
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|
|
|
|
}
|
2010-08-25 18:14:31 +04:00
|
|
|
return true;
|
2008-02-06 07:10:41 +03:00
|
|
|
}
|