cmTarget,cmGeneratorTarget: Add optional before
parameter to AddSource
The new optional `before` parameter in `cmTarget::AddSource` and `cmGeneratorTarget::AddSource` allows to prepend a source file to the sources list instead of appending it.
This commit is contained in:
parent
a61c061b61
commit
a42b700cc2
@ -355,20 +355,22 @@ void cmGeneratorTarget::ClearSourcesCache()
|
||||
this->Objects.clear();
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::AddSourceCommon(const std::string& src)
|
||||
void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
|
||||
{
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
cmGeneratorExpression ge(lfbt);
|
||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
|
||||
cge->SetEvaluateForBuildsystem(true);
|
||||
this->SourceEntries.push_back(new TargetPropertyEntry(std::move(cge)));
|
||||
this->SourceEntries.insert(before ? this->SourceEntries.begin()
|
||||
: this->SourceEntries.end(),
|
||||
new TargetPropertyEntry(std::move(cge)));
|
||||
this->ClearSourcesCache();
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::AddSource(const std::string& src)
|
||||
void cmGeneratorTarget::AddSource(const std::string& src, bool before)
|
||||
{
|
||||
this->Target->AddSource(src);
|
||||
this->AddSourceCommon(src);
|
||||
this->Target->AddSource(src, before);
|
||||
this->AddSourceCommon(src, before);
|
||||
}
|
||||
|
||||
void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
|
||||
@ -387,12 +389,10 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
|
||||
cmGeneratorExpression ge(lfbt);
|
||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
|
||||
cge->SetEvaluateForBuildsystem(true);
|
||||
// Insert before begin/end
|
||||
std::vector<TargetPropertyEntry*>::iterator pos = before
|
||||
? this->IncludeDirectoriesEntries.begin()
|
||||
: this->IncludeDirectoriesEntries.end();
|
||||
this->IncludeDirectoriesEntries.insert(
|
||||
pos, new TargetPropertyEntry(std::move(cge)));
|
||||
before ? this->IncludeDirectoriesEntries.begin()
|
||||
: this->IncludeDirectoriesEntries.end(),
|
||||
new TargetPropertyEntry(std::move(cge)));
|
||||
}
|
||||
|
||||
std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
|
||||
|
@ -536,7 +536,7 @@ public:
|
||||
*/
|
||||
void ClearSourcesCache();
|
||||
|
||||
void AddSource(const std::string& src);
|
||||
void AddSource(const std::string& src, bool before = false);
|
||||
void AddTracedSources(std::vector<std::string> const& srcs);
|
||||
|
||||
/**
|
||||
@ -694,7 +694,7 @@ public:
|
||||
const char* GetSourcesProperty() const;
|
||||
|
||||
private:
|
||||
void AddSourceCommon(const std::string& src);
|
||||
void AddSourceCommon(const std::string& src, bool before = false);
|
||||
|
||||
std::string CreateFortranModuleDirectory(
|
||||
std::string const& working_dir) const;
|
||||
|
@ -662,7 +662,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
cmSourceFile* cmTarget::AddSource(const std::string& src)
|
||||
cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
|
||||
{
|
||||
cmSourceFileLocation sfl(this->Makefile, src,
|
||||
cmSourceFileLocationKind::Known);
|
||||
@ -671,8 +671,14 @@ cmSourceFile* cmTarget::AddSource(const std::string& src)
|
||||
TargetPropertyEntryFinder(sfl)) ==
|
||||
this->Internal->SourceEntries.end()) {
|
||||
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
|
||||
this->Internal->SourceEntries.push_back(src);
|
||||
this->Internal->SourceBacktraces.push_back(lfbt);
|
||||
this->Internal->SourceEntries.insert(
|
||||
before ? this->Internal->SourceEntries.begin()
|
||||
: this->Internal->SourceEntries.end(),
|
||||
src);
|
||||
this->Internal->SourceBacktraces.insert(
|
||||
before ? this->Internal->SourceBacktraces.begin()
|
||||
: this->Internal->SourceBacktraces.end(),
|
||||
lfbt);
|
||||
}
|
||||
if (cmGeneratorExpression::Find(src) != std::string::npos) {
|
||||
return nullptr;
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
void AddSources(std::vector<std::string> const& srcs);
|
||||
void AddTracedSources(std::vector<std::string> const& srcs);
|
||||
cmSourceFile* AddSourceCMP0049(const std::string& src);
|
||||
cmSourceFile* AddSource(const std::string& src);
|
||||
cmSourceFile* AddSource(const std::string& src, bool before = false);
|
||||
|
||||
//* how we identify a library, by name and type
|
||||
typedef std::pair<std::string, cmTargetLinkLibraryType> LibraryID;
|
||||
|
Loading…
Reference in New Issue
Block a user