summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorDaniel Eiband <daniel.eiband@brainlab.com>2019-09-11 09:32:23 (GMT)
committerDaniel Eiband <daniel.eiband@brainlab.com>2019-09-12 13:49:55 (GMT)
commit62d59323899330197e795872c13c1d300a97d088 (patch)
tree3c2e3d9036ace01ee3686a4a2ee86a1d678741aa /Source/cmMakefile.cxx
parent9602bcfc62d50d7bb302b02ae3b1f9afe941bae7 (diff)
downloadCMake-62d59323899330197e795872c13c1d300a97d088.zip
CMake-62d59323899330197e795872c13c1d300a97d088.tar.gz
CMake-62d59323899330197e795872c13c1d300a97d088.tar.bz2
Refatoring: Extract AnyOutputMatches utility
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx37
1 files changed, 22 insertions, 15 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 16cc453..3a80b02 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2012,27 +2012,34 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
return &it->second;
}
+namespace {
+bool AnyOutputMatches(const std::string& name,
+ const std::vector<std::string>& outputs)
+{
+ for (std::string const& output : outputs) {
+ std::string::size_type pos = output.rfind(name);
+ // If the output matches exactly
+ if (pos != std::string::npos && pos == output.size() - name.size() &&
+ (pos == 0 || output[pos - 1] == '/')) {
+ return true;
+ }
+ }
+ return false;
+}
+}
+
cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput(
const std::string& name) const
{
- std::string out;
-
- // look through all the source files that have custom commands
- // and see if the custom command has the passed source file as an output
+ // Look through all the source files that have custom commands and see if the
+ // custom command has the passed source file as an output.
for (cmSourceFile* src : this->SourceFiles) {
- // does this source file have a custom command?
+ // Does this source file have a custom command?
if (src->GetCustomCommand()) {
// Does the output of the custom command match the source file name?
- const std::vector<std::string>& outputs =
- src->GetCustomCommand()->GetOutputs();
- for (std::string const& output : outputs) {
- out = output;
- std::string::size_type pos = out.rfind(name);
- // If the output matches exactly
- if (pos != std::string::npos && pos == out.size() - name.size() &&
- (pos == 0 || out[pos - 1] == '/')) {
- return src;
- }
+ if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) {
+ // Return the first matching output.
+ return src;
}
}
}