mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
cmLocalGenerator: Refactor UpdateOutputToSourceMap to avoid boolean trap
This commit is contained in:
@@ -3924,7 +3924,9 @@ cmSourceFile* AddCustomCommand(
|
||||
cc->SetJobPool(job_pool);
|
||||
file->SetCustomCommand(std::move(cc));
|
||||
|
||||
lg.AddSourceOutputs(file, outputs, byproducts);
|
||||
lg.AddSourceOutputs(file, outputs, cmLocalGenerator::OutputRole::Primary);
|
||||
lg.AddSourceOutputs(file, byproducts,
|
||||
cmLocalGenerator::OutputRole::Byproduct);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
@@ -4177,13 +4179,10 @@ void cmLocalGenerator::AddTargetByproducts(
|
||||
|
||||
void cmLocalGenerator::AddSourceOutputs(
|
||||
cmSourceFile* source, const std::vector<std::string>& outputs,
|
||||
const std::vector<std::string>& byproducts)
|
||||
OutputRole role)
|
||||
{
|
||||
for (std::string const& o : outputs) {
|
||||
this->UpdateOutputToSourceMap(o, source, false);
|
||||
}
|
||||
for (std::string const& o : byproducts) {
|
||||
this->UpdateOutputToSourceMap(o, source, true);
|
||||
this->UpdateOutputToSourceMap(o, source, role);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4211,18 +4210,18 @@ void cmLocalGenerator::UpdateOutputToSourceMap(std::string const& byproduct,
|
||||
|
||||
void cmLocalGenerator::UpdateOutputToSourceMap(std::string const& output,
|
||||
cmSourceFile* source,
|
||||
bool byproduct)
|
||||
OutputRole role)
|
||||
{
|
||||
SourceEntry entry;
|
||||
entry.Sources.Source = source;
|
||||
entry.Sources.SourceIsByproduct = byproduct;
|
||||
entry.Sources.SourceIsByproduct = role == OutputRole::Byproduct;
|
||||
|
||||
auto pr = this->OutputToSource.emplace(output, entry);
|
||||
if (!pr.second) {
|
||||
SourceEntry& current = pr.first->second;
|
||||
// Outputs take precedence over byproducts
|
||||
if (!current.Sources.Source ||
|
||||
(current.Sources.SourceIsByproduct && !byproduct)) {
|
||||
(current.Sources.SourceIsByproduct && role == OutputRole::Primary)) {
|
||||
current.Sources.Source = source;
|
||||
current.Sources.SourceIsByproduct = false;
|
||||
} else {
|
||||
|
@@ -368,12 +368,18 @@ public:
|
||||
void AddTargetByproducts(cmTarget* target,
|
||||
const std::vector<std::string>& byproducts);
|
||||
|
||||
enum class OutputRole
|
||||
{
|
||||
Primary,
|
||||
Byproduct,
|
||||
};
|
||||
|
||||
/**
|
||||
* Add source file outputs.
|
||||
*/
|
||||
void AddSourceOutputs(cmSourceFile* source,
|
||||
const std::vector<std::string>& outputs,
|
||||
const std::vector<std::string>& byproducts);
|
||||
std::vector<std::string> const& outputs,
|
||||
OutputRole role);
|
||||
|
||||
/**
|
||||
* Return the target if the provided source name is a byproduct of a utility
|
||||
@@ -609,7 +615,7 @@ private:
|
||||
|
||||
void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target);
|
||||
void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source,
|
||||
bool byproduct);
|
||||
OutputRole role);
|
||||
|
||||
void AddSharedFlags(std::string& flags, const std::string& lang,
|
||||
bool shared);
|
||||
|
Reference in New Issue
Block a user