cmTarget: Store strings instead of cmSourceFile* to represent SOURCES.

This will allow the strings to contain generator expressions.

At this point, generator expressions are still not part of the
SOURCES property when it is read.
This commit is contained in:
Stephen Kelly 2014-03-17 18:36:04 +01:00
parent 4959f3413c
commit 8cd113ad1d
2 changed files with 134 additions and 41 deletions

View File

@ -150,6 +150,7 @@ public:
std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
std::vector<TargetPropertyEntry*> SourceEntries;
std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
@ -545,26 +546,20 @@ bool cmTarget::IsBundleOnApple() const
void cmTarget::GetSourceFiles(std::vector<std::string> &files) const
{
assert(this->GetType() != INTERFACE_LIBRARY);
std::vector<cmSourceFile*> sourceFiles;
this->GetSourceFiles(sourceFiles);
for(std::vector<cmSourceFile*>::const_iterator
si = sourceFiles.begin();
si != sourceFiles.end(); ++si)
for(std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
si = this->Internal->SourceEntries.begin();
si != this->Internal->SourceEntries.end(); ++si)
{
files.push_back((*si)->GetFullPath());
}
}
//----------------------------------------------------------------------------
void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
{
assert(this->GetType() != INTERFACE_LIBRARY);
for(std::vector<cmSourceFile*>::const_iterator
si = this->SourceFiles.begin();
si != this->SourceFiles.end(); ++si)
std::vector<std::string> srcs;
cmSystemTools::ExpandListArgument((*si)->ge->GetInput(), srcs);
for(std::vector<std::string>::const_iterator i = srcs.begin();
i != srcs.end(); ++i)
{
std::string src = *i;
cmSourceFile* sf = this->Makefile->GetOrCreateSource(src);
std::string e;
if((*si)->GetFullPath(&e).empty())
src = sf->GetFullPath(&e);
if(src.empty())
{
if(!e.empty())
{
@ -574,8 +569,28 @@ void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
}
return;
}
files.push_back(src);
}
}
}
//----------------------------------------------------------------------------
void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
{
std::vector<std::string> srcs;
this->GetSourceFiles(srcs);
std::set<cmSourceFile*> emitted;
for(std::vector<std::string>::const_iterator i = srcs.begin();
i != srcs.end(); ++i)
{
cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
if (emitted.insert(sf).second)
{
files.push_back(sf);
}
}
files = this->SourceFiles;
}
//----------------------------------------------------------------------------
@ -639,18 +654,87 @@ cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
return this->AddSource(src);
}
//----------------------------------------------------------------------------
struct CreateLocation
{
cmMakefile const* Makefile;
CreateLocation(cmMakefile const* mf)
: Makefile(mf)
{
}
cmSourceFileLocation operator()(const std::string& filename)
{
return cmSourceFileLocation(this->Makefile, filename);
}
};
//----------------------------------------------------------------------------
struct LocationMatcher
{
const cmSourceFileLocation& Needle;
LocationMatcher(const cmSourceFileLocation& needle)
: Needle(needle)
{
}
bool operator()(cmSourceFileLocation &loc)
{
return loc.Matches(this->Needle);
}
};
//----------------------------------------------------------------------------
struct TargetPropertyEntryFinder
{
private:
const cmSourceFileLocation& Needle;
public:
TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
: Needle(needle)
{
}
bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
{
std::vector<std::string> files;
cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
std::vector<cmSourceFileLocation> locations(files.size());
std::transform(files.begin(), files.end(), locations.begin(),
CreateLocation(this->Needle.GetMakefile()));
return std::find_if(locations.begin(), locations.end(),
LocationMatcher(this->Needle)) != locations.end();
}
};
//----------------------------------------------------------------------------
cmSourceFile* cmTarget::AddSource(const std::string& src)
{
cmSourceFile* sf = this->Makefile->GetOrCreateSource(src);
if (std::find(this->SourceFiles.begin(), this->SourceFiles.end(), sf)
== this->SourceFiles.end())
cmSourceFileLocation sfl(this->Makefile, src);
if (std::find_if(this->Internal->SourceEntries.begin(),
this->Internal->SourceEntries.end(),
TargetPropertyEntryFinder(sfl))
== this->Internal->SourceEntries.end())
{
this->SourceFiles.push_back(sf);
cmListFileBacktrace lfbt;
this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt);
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
this->Internal->SourceEntries.push_back(
new cmTargetInternals::TargetPropertyEntry(cge));
}
return sf;
return this->Makefile->GetOrCreateSource(src);
}
//----------------------------------------------------------------------------
void cmTarget::ProcessSourceExpression(std::string const& expr)
{
@ -2779,16 +2863,22 @@ const char *cmTarget::GetProperty(const std::string& prop,
{
cmOStringStream ss;
const char* sep = "";
for(std::vector<cmSourceFile*>::const_iterator
i = this->SourceFiles.begin();
i != this->SourceFiles.end(); ++i)
typedef cmTargetInternals::TargetPropertyEntry
TargetPropertyEntry;
for(std::vector<TargetPropertyEntry*>::const_iterator
i = this->Internal->SourceEntries.begin();
i != this->Internal->SourceEntries.end(); ++i)
{
// Separate from the previous list entries.
ss << sep;
sep = ";";
std::string entry = (*i)->ge->GetInput();
std::vector<std::string> files;
cmSystemTools::ExpandListArgument(entry, files);
for (std::vector<std::string>::const_iterator
li = files.begin(); li != files.end(); ++li)
{
cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
// Construct what is known about this source file location.
cmSourceFileLocation const& location = (*i)->GetLocation();
cmSourceFileLocation const& location = sf->GetLocation();
std::string sname = location.GetDirectory();
if(!sname.empty())
{
@ -2796,9 +2886,12 @@ const char *cmTarget::GetProperty(const std::string& prop,
}
sname += location.GetName();
ss << sep;
sep = ";";
// Append this list entry.
ss << sname;
}
}
this->Properties.SetProperty("SOURCES", ss.str().c_str(),
cmProperty::TARGET);
}
@ -6410,6 +6503,7 @@ cmTargetInternalPointer::~cmTargetInternalPointer()
deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
deleteAndClear(this->Pointer->CompileOptionsEntries);
deleteAndClear(this->Pointer->CompileDefinitionsEntries);
deleteAndClear(this->Pointer->SourceEntries);
delete this->Pointer;
}

View File

@ -686,7 +686,6 @@ private:
std::vector<cmCustomCommand> PreLinkCommands;
std::vector<cmCustomCommand> PostBuildCommands;
TargetType TargetTypeValue;
std::vector<cmSourceFile*> SourceFiles;
std::vector<std::string> ObjectLibraries;
LinkLibraryVectorType LinkLibraries;
LinkLibraryVectorType PrevLinkedLibraries;