Save source dependencies from custom command trace
In each target we trace dependencies among custom commands to pull in all source files and build rules necessary to complete the target. This commit teaches cmTarget to save the inter-source dependencies found during its analysis. Later this can be used by generators that need to topologically order custom command rules.
This commit is contained in:
parent
355511ade9
commit
4224513cce
|
@ -88,6 +88,10 @@ public:
|
||||||
|
|
||||||
typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
|
typedef std::map<cmStdString, cmTarget::LinkClosure> LinkClosureMapType;
|
||||||
LinkClosureMapType LinkClosureMap;
|
LinkClosureMapType LinkClosureMap;
|
||||||
|
|
||||||
|
struct SourceEntry { std::vector<cmSourceFile*> Depends; };
|
||||||
|
typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
|
||||||
|
SourceEntriesType SourceEntries;
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -1081,12 +1085,16 @@ bool cmTarget::IsAppBundleOnApple()
|
||||||
class cmTargetTraceDependencies
|
class cmTargetTraceDependencies
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile);
|
cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
|
||||||
|
const char* vsProjectFile);
|
||||||
void Trace();
|
void Trace();
|
||||||
private:
|
private:
|
||||||
cmTarget* Target;
|
cmTarget* Target;
|
||||||
|
cmTargetInternals* Internal;
|
||||||
cmMakefile* Makefile;
|
cmMakefile* Makefile;
|
||||||
cmGlobalGenerator* GlobalGenerator;
|
cmGlobalGenerator* GlobalGenerator;
|
||||||
|
typedef cmTargetInternals::SourceEntry SourceEntry;
|
||||||
|
SourceEntry* CurrentEntry;
|
||||||
std::queue<cmSourceFile*> SourceQueue;
|
std::queue<cmSourceFile*> SourceQueue;
|
||||||
std::set<cmSourceFile*> SourcesQueued;
|
std::set<cmSourceFile*> SourcesQueued;
|
||||||
typedef std::map<cmStdString, cmSourceFile*> NameMapType;
|
typedef std::map<cmStdString, cmSourceFile*> NameMapType;
|
||||||
|
@ -1102,13 +1110,15 @@ private:
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmTargetTraceDependencies
|
cmTargetTraceDependencies
|
||||||
::cmTargetTraceDependencies(cmTarget* target, const char* vsProjectFile):
|
::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
|
||||||
Target(target)
|
const char* vsProjectFile):
|
||||||
|
Target(target), Internal(internal)
|
||||||
{
|
{
|
||||||
// Convenience.
|
// Convenience.
|
||||||
this->Makefile = this->Target->GetMakefile();
|
this->Makefile = this->Target->GetMakefile();
|
||||||
this->GlobalGenerator =
|
this->GlobalGenerator =
|
||||||
this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
|
this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
|
||||||
|
this->CurrentEntry = 0;
|
||||||
|
|
||||||
// Queue all the source files already specified for the target.
|
// Queue all the source files already specified for the target.
|
||||||
std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
|
std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
|
||||||
|
@ -1140,6 +1150,7 @@ void cmTargetTraceDependencies::Trace()
|
||||||
// Get the next source from the queue.
|
// Get the next source from the queue.
|
||||||
cmSourceFile* sf = this->SourceQueue.front();
|
cmSourceFile* sf = this->SourceQueue.front();
|
||||||
this->SourceQueue.pop();
|
this->SourceQueue.pop();
|
||||||
|
this->CurrentEntry = &this->Internal->SourceEntries[sf];
|
||||||
|
|
||||||
// Queue dependencies added explicitly by the user.
|
// Queue dependencies added explicitly by the user.
|
||||||
if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
|
if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
|
||||||
|
@ -1161,6 +1172,7 @@ void cmTargetTraceDependencies::Trace()
|
||||||
this->CheckCustomCommand(*cc);
|
this->CheckCustomCommand(*cc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->CurrentEntry = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -1188,6 +1200,12 @@ void cmTargetTraceDependencies::FollowName(std::string const& name)
|
||||||
}
|
}
|
||||||
if(cmSourceFile* sf = i->second)
|
if(cmSourceFile* sf = i->second)
|
||||||
{
|
{
|
||||||
|
// Record the dependency we just followed.
|
||||||
|
if(this->CurrentEntry)
|
||||||
|
{
|
||||||
|
this->CurrentEntry->Depends.push_back(sf);
|
||||||
|
}
|
||||||
|
|
||||||
this->QueueSource(sf);
|
this->QueueSource(sf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1308,7 +1326,7 @@ cmTargetTraceDependencies
|
||||||
void cmTarget::TraceDependencies(const char* vsProjectFile)
|
void cmTarget::TraceDependencies(const char* vsProjectFile)
|
||||||
{
|
{
|
||||||
// Use a helper object to trace the dependencies.
|
// Use a helper object to trace the dependencies.
|
||||||
cmTargetTraceDependencies tracer(this, vsProjectFile);
|
cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
|
||||||
tracer.Trace();
|
tracer.Trace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1336,12 +1354,30 @@ std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmTarget::AddSourceFile(cmSourceFile* sf)
|
void cmTarget::AddSourceFile(cmSourceFile* sf)
|
||||||
{
|
{
|
||||||
if(this->SourceFileSet.insert(sf).second)
|
typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
|
||||||
|
SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
|
||||||
|
if(i == this->Internal->SourceEntries.end())
|
||||||
{
|
{
|
||||||
|
typedef cmTargetInternals::SourceEntry SourceEntry;
|
||||||
|
SourceEntriesType::value_type entry(sf, SourceEntry());
|
||||||
|
i = this->Internal->SourceEntries.insert(entry).first;
|
||||||
this->SourceFiles.push_back(sf);
|
this->SourceFiles.push_back(sf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
std::vector<cmSourceFile*> const*
|
||||||
|
cmTarget::GetSourceDepends(cmSourceFile* sf)
|
||||||
|
{
|
||||||
|
typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
|
||||||
|
SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
|
||||||
|
if(i != this->Internal->SourceEntries.end())
|
||||||
|
{
|
||||||
|
return &i->second.Depends;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmTarget::AddSources(std::vector<std::string> const& srcs)
|
void cmTarget::AddSources(std::vector<std::string> const& srcs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
~cmTargetInternalPointer();
|
~cmTargetInternalPointer();
|
||||||
cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r);
|
cmTargetInternalPointer& operator=(cmTargetInternalPointer const& r);
|
||||||
cmTargetInternals* operator->() const { return this->Pointer; }
|
cmTargetInternals* operator->() const { return this->Pointer; }
|
||||||
|
cmTargetInternals* Get() const { return this->Pointer; }
|
||||||
private:
|
private:
|
||||||
cmTargetInternals* Pointer;
|
cmTargetInternals* Pointer;
|
||||||
};
|
};
|
||||||
|
@ -122,6 +123,9 @@ public:
|
||||||
std::vector<cmSourceFile*> const& GetSourceFiles();
|
std::vector<cmSourceFile*> const& GetSourceFiles();
|
||||||
void AddSourceFile(cmSourceFile* sf);
|
void AddSourceFile(cmSourceFile* sf);
|
||||||
|
|
||||||
|
/** Get sources that must be built before the given source. */
|
||||||
|
std::vector<cmSourceFile*> const* GetSourceDepends(cmSourceFile* sf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags for a given source file as used in this target. Typically assigned
|
* Flags for a given source file as used in this target. Typically assigned
|
||||||
* via SET_TARGET_PROPERTIES when the property is a list of source files.
|
* via SET_TARGET_PROPERTIES when the property is a list of source files.
|
||||||
|
@ -530,7 +534,6 @@ private:
|
||||||
std::vector<cmCustomCommand> PostBuildCommands;
|
std::vector<cmCustomCommand> PostBuildCommands;
|
||||||
TargetType TargetTypeValue;
|
TargetType TargetTypeValue;
|
||||||
std::vector<cmSourceFile*> SourceFiles;
|
std::vector<cmSourceFile*> SourceFiles;
|
||||||
std::set<cmSourceFile*> SourceFileSet;
|
|
||||||
LinkLibraryVectorType LinkLibraries;
|
LinkLibraryVectorType LinkLibraries;
|
||||||
LinkLibraryVectorType PrevLinkedLibraries;
|
LinkLibraryVectorType PrevLinkedLibraries;
|
||||||
bool LinkLibrariesAnalyzed;
|
bool LinkLibrariesAnalyzed;
|
||||||
|
|
Loading…
Reference in New Issue