From 3e8b3e94dc6d3ea59dd437f1ea46786f9f0ec1d2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 7 Sep 2017 11:42:29 +0200 Subject: cmMakefile: Collect source group methods in one place --- Source/cmMakefile.cxx | 65 ++++++++++++++++++++++++--------------------------- Source/cmMakefile.h | 41 ++++++++++++++------------------ 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 230c210..24c2de2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2010,6 +2010,37 @@ void cmMakefile::AddSourceGroup(const std::vector& name, sg->SetGroupRegex(regex); } +/** + * Find a source group whose regular expression matches the filename + * part of the given source name. Search backward through the list of + * source groups, and take the first matching group found. This way + * non-inherited SOURCE_GROUP commands will have precedence over + * inherited ones. + */ +cmSourceGroup* cmMakefile::FindSourceGroup( + const char* source, std::vector& groups) const +{ + // First search for a group that lists the file explicitly. + for (std::vector::reverse_iterator sg = groups.rbegin(); + sg != groups.rend(); ++sg) { + cmSourceGroup* result = sg->MatchChildrenFiles(source); + if (result) { + return result; + } + } + + // Now search for a group whose regex matches the file. + for (std::vector::reverse_iterator sg = groups.rbegin(); + sg != groups.rend(); ++sg) { + cmSourceGroup* result = sg->MatchChildrenRegex(source); + if (result) { + return result; + } + } + + // Shouldn't get here, but just in case, return the default group. + return &groups.front(); +} #endif static bool mightExpandVariablesCMP0019(const char* s) @@ -2818,40 +2849,6 @@ std::string cmMakefile::GetConfigurations(std::vector& configs, return buildType; } -#if defined(CMAKE_BUILD_WITH_CMAKE) -/** - * Find a source group whose regular expression matches the filename - * part of the given source name. Search backward through the list of - * source groups, and take the first matching group found. This way - * non-inherited SOURCE_GROUP commands will have precedence over - * inherited ones. - */ -cmSourceGroup* cmMakefile::FindSourceGroup( - const char* source, std::vector& groups) const -{ - // First search for a group that lists the file explicitly. - for (std::vector::reverse_iterator sg = groups.rbegin(); - sg != groups.rend(); ++sg) { - cmSourceGroup* result = sg->MatchChildrenFiles(source); - if (result) { - return result; - } - } - - // Now search for a group whose regex matches the file. - for (std::vector::reverse_iterator sg = groups.rbegin(); - sg != groups.rend(); ++sg) { - cmSourceGroup* result = sg->MatchChildrenRegex(source); - if (result) { - return result; - } - } - - // Shouldn't get here, but just in case, return the default group. - return &groups.front(); -} -#endif - bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus& status) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 938b61b..31ae229 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -270,21 +270,6 @@ public: bool excludeFromAll = false); void AddAlias(const std::string& libname, const std::string& tgt); -#if defined(CMAKE_BUILD_WITH_CMAKE) - /** - * Add a root source group for consideration when adding a new source. - */ - void AddSourceGroup(const std::string& name, const char* regex = nullptr); - - /** - * Add a source group for consideration when adding a new source. - * name is tokenized. - */ - void AddSourceGroup(const std::vector& name, - const char* regex = nullptr); - -#endif - //@{ /** * Set, Push, Pop policy values for CMake. @@ -476,6 +461,24 @@ public: * Get the source group */ cmSourceGroup* GetSourceGroup(const std::vector& name) const; + + /** + * Add a root source group for consideration when adding a new source. + */ + void AddSourceGroup(const std::string& name, const char* regex = nullptr); + + /** + * Add a source group for consideration when adding a new source. + * name is tokenized. + */ + void AddSourceGroup(const std::vector& name, + const char* regex = nullptr); + + /** + * find what source group this source is in + */ + cmSourceGroup* FindSourceGroup(const char* source, + std::vector& groups) const; #endif /** @@ -552,14 +555,6 @@ public: bool atOnly, bool escapeQuotes, cmNewLineStyle = cmNewLineStyle()); -#if defined(CMAKE_BUILD_WITH_CMAKE) - /** - * find what source group this source is in - */ - cmSourceGroup* FindSourceGroup(const char* source, - std::vector& groups) const; -#endif - /** * Print a command's invocation */ -- cgit v0.12 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 From a451995fc6485929bc606986572eee162d6fc4e4 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 7 Sep 2017 12:00:13 +0200 Subject: Use cmMakefile::GetOrCreateSourceGroup in cmSourceGroupCommand --- Source/cmSourceGroupCommand.cxx | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 77fde7b..890109e 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -61,23 +61,6 @@ bool rootIsPrefix(const std::string& root, return true; } -cmSourceGroup* addSourceGroup(const std::vector& tokenizedPath, - cmMakefile& makefile) -{ - cmSourceGroup* sg; - - sg = makefile.GetSourceGroup(tokenizedPath); - if (!sg) { - makefile.AddSourceGroup(tokenizedPath); - sg = makefile.GetSourceGroup(tokenizedPath); - if (!sg) { - return nullptr; - } - } - - return sg; -} - std::string prepareFilePathForTree(const std::string& path, const std::string& currentSourceDir) { @@ -121,7 +104,7 @@ bool addFilesToItsSourceGroups(const std::string& root, if (tokenizedPath.size() > 1) { tokenizedPath.pop_back(); - sg = addSourceGroup(tokenizedPath, makefile); + sg = makefile.GetOrCreateSourceGroup(tokenizedPath); if (!sg) { errorMsg = "Could not create source group for file: " + *it; @@ -158,20 +141,7 @@ bool cmSourceGroupCommand::InitialPass(std::vector const& args, return true; } - std::string delimiter = "\\"; - if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) { - delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); - } - - std::vector folders = - cmSystemTools::tokenize(args[0], delimiter); - - cmSourceGroup* sg = nullptr; - sg = this->Makefile->GetSourceGroup(folders); - if (!sg) { - this->Makefile->AddSourceGroup(folders); - sg = this->Makefile->GetSourceGroup(folders); - } + cmSourceGroup* sg = this->Makefile->GetOrCreateSourceGroup(args[0]); if (!sg) { this->SetError("Could not create or find source group"); -- cgit v0.12 From 95b17c89be15a768178d66f42573d90852a1b986 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 7 Sep 2017 12:02:34 +0200 Subject: Use cmMakefile::GetOrCreateSourceGroup in cmQtAutogeneratorsInitializer --- Source/cmQtAutoGeneratorInitializer.cxx | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 22ac9d2..1b6020f 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -237,20 +237,7 @@ static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, } // Generate a source group on demand if (!groupName.empty()) { - { - const char* delimiter = - makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); - if (delimiter == nullptr) { - delimiter = "\\"; - } - std::vector folders = - cmSystemTools::tokenize(groupName, delimiter); - sourceGroup = makefile->GetSourceGroup(folders); - if (sourceGroup == nullptr) { - makefile->AddSourceGroup(folders); - sourceGroup = makefile->GetSourceGroup(folders); - } - } + sourceGroup = makefile->GetOrCreateSourceGroup(groupName); if (sourceGroup == nullptr) { std::ostringstream ost; ost << cmQtAutoGen::GeneratorNameUpper(genType); -- cgit v0.12