summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-02 13:20:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-09-02 13:21:22 (GMT)
commit68b674b8bc862f943863b48925a5c4d065de8f39 (patch)
treef060546d4eb79483ff69f4b622995d821d129b4c
parent913855f9e6722ad010419b4a190051a5677c55e3 (diff)
parente33f8f078a289e51636067414ff73d1d1b945552 (diff)
downloadCMake-68b674b8bc862f943863b48925a5c4d065de8f39.zip
CMake-68b674b8bc862f943863b48925a5c4d065de8f39.tar.gz
CMake-68b674b8bc862f943863b48925a5c4d065de8f39.tar.bz2
Merge topic 'xcode-custom-commands'
e33f8f078a Xcode: Avoid unnecessary duplication of custom commands across targets 8c60c49ae2 Xcode: Refactor custom command dependency expansion Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5176
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx42
-rw-r--r--Source/cmGlobalXCodeGenerator.h2
2 files changed, 37 insertions, 7 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 9f8e331..450b2b1 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -679,6 +679,7 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
this->FileRefs.clear();
this->ExternalLibRefs.clear();
this->FileRefToBuildFileMap.clear();
+ this->CommandsVisited.clear();
}
void cmGlobalXCodeGenerator::addObject(std::unique_ptr<cmXCodeObject> obj)
@@ -1271,6 +1272,16 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget(
return true;
}
+ auto& gtgt_visited = this->CommandsVisited[gtgt];
+ auto& deps = this->GetTargetDirectDepends(gtgt);
+ for (auto& d : deps) {
+ // Take the union of visited source files of custom commands so far.
+ // ComputeTargetOrder ensures our dependencies already visited their
+ // custom commands and updated CommandsVisited.
+ auto& dep_visited = this->CommandsVisited[d];
+ gtgt_visited.insert(dep_visited.begin(), dep_visited.end());
+ }
+
if (gtgt->GetType() == cmStateEnums::UTILITY ||
gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
gtgt->GetType() == cmStateEnums::GLOBAL_TARGET) {
@@ -1628,8 +1639,9 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(
}
// add all the sources
std::vector<cmCustomCommand> commands;
+ auto& visited = this->CommandsVisited[gtgt];
for (auto sourceFile : classes) {
- if (sourceFile->GetCustomCommand()) {
+ if (sourceFile->GetCustomCommand() && visited.insert(sourceFile).second) {
commands.push_back(*sourceFile->GetCustomCommand());
}
}
@@ -1839,6 +1851,15 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
for (auto const& command : commands) {
cmCustomCommandGenerator ccg(command, configName,
this->CurrentLocalGenerator);
+ std::vector<std::string> realDepends;
+ realDepends.reserve(ccg.GetDepends().size());
+ for (auto const& d : ccg.GetDepends()) {
+ std::string dep;
+ if (this->CurrentLocalGenerator->GetRealDependency(d, configName, dep)) {
+ realDepends.emplace_back(std::move(dep));
+ }
+ }
+
if (ccg.GetNumberOfCommands() > 0) {
makefileStream << "\n";
const std::vector<std::string>& outputs = ccg.GetOutputs();
@@ -1854,12 +1875,8 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
// There are no outputs. Use the generated force rule name.
makefileStream << tname[&ccg.GetCC()] << ": ";
}
- for (auto const& d : ccg.GetDepends()) {
- std::string dep;
- if (this->CurrentLocalGenerator->GetRealDependency(d, configName,
- dep)) {
- makefileStream << "\\\n" << this->ConvertToRelativeForMake(dep);
- }
+ for (auto const& dep : realDepends) {
+ makefileStream << "\\\n" << this->ConvertToRelativeForMake(dep);
}
makefileStream << "\n";
@@ -1888,6 +1905,17 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
ccg.AppendArguments(c, cmd);
makefileStream << "\t" << cmd << "\n";
}
+
+ // Symbolic inputs are not expected to exist, so add dummy rules.
+ for (auto const& dep : realDepends) {
+ if (cmSourceFile* dsf =
+ target->GetLocalGenerator()->GetMakefile()->GetSource(
+ dep, cmSourceFileLocationKind::Known)) {
+ if (dsf->GetPropertyAsBool("SYMBOLIC")) {
+ makefileStream << this->ConvertToRelativeForMake(dep) << ":\n";
+ }
+ }
+ }
}
}
}
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index f9b6300..c02cc1d 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -306,6 +306,8 @@ private:
std::string GeneratorToolset;
std::map<cmGeneratorTarget const*, size_t> TargetOrderIndex;
std::vector<std::string> EnabledLangs;
+ std::map<cmGeneratorTarget const*, std::set<cmSourceFile const*>>
+ CommandsVisited;
};
#endif