summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorDaniel Eiband <daniel.eiband@brainlab.com>2019-09-14 20:01:20 (GMT)
committerDaniel Eiband <daniel.eiband@brainlab.com>2019-09-17 20:52:32 (GMT)
commit56c204e8eb8914b2ca273a56119cf1c40e13d75d (patch)
tree1d92f26a912997a7d4270af52c07e42ec553dac6 /Source/cmMakefile.cxx
parent3061dc6ac967e859424f81fb70bbc70a74246055 (diff)
downloadCMake-56c204e8eb8914b2ca273a56119cf1c40e13d75d.zip
CMake-56c204e8eb8914b2ca273a56119cf1c40e13d75d.tar.gz
CMake-56c204e8eb8914b2ca273a56119cf1c40e13d75d.tar.bz2
cmMakefile: Refactor AddCustomCommandOldStyle to be delay friendly
Custom command functions consist of two parts: setup and commit. Only the commit part will be delayed to generate time. This change puts the commit part of AddCustomCommandOldStyle into a lambda. When delayed, it will not be possible to break the loop over the outputs if an error occurs which seems reasonable.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx63
1 files changed, 36 insertions, 27 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 6707b1c..19cd068 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1134,41 +1134,50 @@ void cmMakefile::AddCustomCommandOldStyle(
return;
}
- // Each output must get its own copy of this rule.
- cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|m|mm|"
- "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
- "hm|hpp|hxx|in|txx|inl)$");
- for (std::string const& oi : outputs) {
- // Get the name of this output.
- const char* output = oi.c_str();
- cmSourceFile* sf;
-
- // Choose whether to use a main dependency.
- if (sourceFiles.find(source)) {
- // The source looks like a real file. Use it as the main dependency.
- sf = this->AddCustomCommandToOutput(output, depends, source,
- commandLines, comment, nullptr);
- } else {
- // The source may not be a real file. Do not use a main dependency.
- std::string no_main_dependency;
- std::vector<std::string> depends2 = depends;
- depends2.push_back(source);
- sf = this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
- commandLines, comment, nullptr);
- }
+ auto ti = this->Targets.find(target);
+ cmTarget* t = ti != this->Targets.end() ? &ti->second : nullptr;
+ auto addRuleFileToTarget = [=](cmSourceFile* sf) {
// If the rule was added to the source (and not a .rule file),
// then add the source to the target to make sure the rule is
// included.
- if (sf && !sf->GetPropertyAsBool("__CMAKE_RULE")) {
- auto ti = this->Targets.find(target);
- if (ti != this->Targets.end()) {
- ti->second.AddSource(sf->ResolveFullPath());
+ if (!sf->GetPropertyAsBool("__CMAKE_RULE")) {
+ if (t) {
+ t->AddSource(sf->ResolveFullPath());
} else {
cmSystemTools::Error("Attempt to add a custom rule to a target "
"that does not exist yet for target " +
target);
- return;
+ }
+ }
+ };
+
+ // Each output must get its own copy of this rule.
+ cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|m|mm|"
+ "rc|def|r|odl|idl|hpj|bat|h|h\\+\\+|"
+ "hm|hpp|hxx|in|txx|inl)$");
+
+ // Choose whether to use a main dependency.
+ if (sourceFiles.find(source)) {
+ // The source looks like a real file. Use it as the main dependency.
+ for (std::string const& output : outputs) {
+ cmSourceFile* sf = this->AddCustomCommandToOutput(
+ output, depends, source, commandLines, comment, nullptr);
+ if (sf) {
+ addRuleFileToTarget(sf);
+ }
+ }
+ } else {
+ std::string no_main_dependency;
+ std::vector<std::string> depends2 = depends;
+ depends2.push_back(source);
+
+ // The source may not be a real file. Do not use a main dependency.
+ for (std::string const& output : outputs) {
+ cmSourceFile* sf = this->AddCustomCommandToOutput(
+ output, depends2, no_main_dependency, commandLines, comment, nullptr);
+ if (sf) {
+ addRuleFileToTarget(sf);
}
}
}