From 1e6569c9f4614b3d915653bab2fd423c99d814d6 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 7 Sep 2017 11:55:52 +0200 Subject: cmMakefile: Add GetOrCreateSourceGroup methods --- Source/cmMakefile.cxx | 21 +++++++++++++++++++++ Source/cmMakefile.h | 12 ++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 24c2de2..c9dc93c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2010,6 +2010,27 @@ void cmMakefile::AddSourceGroup(const std::vector& name, sg->SetGroupRegex(regex); } +cmSourceGroup* cmMakefile::GetOrCreateSourceGroup( + const std::vector& folders) +{ + cmSourceGroup* sg = this->GetSourceGroup(folders); + if (sg == nullptr) { + this->AddSourceGroup(folders); + sg = this->GetSourceGroup(folders); + } + return sg; +} + +cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(const std::string& name) +{ + const char* delimiter = this->GetDefinition("SOURCE_GROUP_DELIMITER"); + if (delimiter == nullptr) { + delimiter = "\\"; + } + return this->GetOrCreateSourceGroup( + cmSystemTools::tokenize(name, delimiter)); +} + /** * Find a source group whose regular expression matches the filename * part of the given source name. Search backward through the list of diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 31ae229..398604d 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -475,6 +475,18 @@ public: const char* regex = nullptr); /** + * Get and existing or create a new source group. + */ + cmSourceGroup* GetOrCreateSourceGroup( + const std::vector& folders); + + /** + * Get and existing or create a new source group. + * The name will be tokenized. + */ + cmSourceGroup* GetOrCreateSourceGroup(const std::string& name); + + /** * find what source group this source is in */ cmSourceGroup* FindSourceGroup(const char* source, -- cgit v0.12