summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-09-12 13:38:03 +0000
committerKitware Robot <kwrobot@kitware.com>2017-09-12 09:38:24 -0400
commitcb171502287db0e4911faa10d748c72f08e5a9dd (patch)
treed51e973edeac480e1ab4383970bfcad35078883e
parent3f8c6cab4bb4a9f68708c11a38e4487dad363e38 (diff)
parent95b17c89be15a768178d66f42573d90852a1b986 (diff)
downloadcmake-cb171502287db0e4911faa10d748c72f08e5a9dd.tar.gz
Merge topic 'get-or-create-source-group'
95b17c89 Use cmMakefile::GetOrCreateSourceGroup in cmQtAutogeneratorsInitializer a451995f Use cmMakefile::GetOrCreateSourceGroup in cmSourceGroupCommand 1e6569c9 cmMakefile: Add GetOrCreateSourceGroup methods 3e8b3e94 cmMakefile: Collect source group methods in one place Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1243
-rw-r--r--Source/cmMakefile.cxx86
-rw-r--r--Source/cmMakefile.h53
-rw-r--r--Source/cmQtAutoGeneratorInitializer.cxx15
-rw-r--r--Source/cmSourceGroupCommand.cxx34
4 files changed, 85 insertions, 103 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 230c21086c..c9dc93c9dd 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2010,6 +2010,58 @@ void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
sg->SetGroupRegex(regex);
}
+cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(
+ const std::vector<std::string>& 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
+ * 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<cmSourceGroup>& groups) const
+{
+ // First search for a group that lists the file explicitly.
+ for (std::vector<cmSourceGroup>::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<cmSourceGroup>::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 +2870,6 @@ std::string cmMakefile::GetConfigurations(std::vector<std::string>& 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<cmSourceGroup>& groups) const
-{
- // First search for a group that lists the file explicitly.
- for (std::vector<cmSourceGroup>::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<cmSourceGroup>::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 938b61b5c0..398604d4d7 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<std::string>& name,
- const char* regex = nullptr);
-
-#endif
-
//@{
/**
* Set, Push, Pop policy values for CMake.
@@ -476,6 +461,36 @@ public:
* Get the source group
*/
cmSourceGroup* GetSourceGroup(const std::vector<std::string>& 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<std::string>& name,
+ const char* regex = nullptr);
+
+ /**
+ * Get and existing or create a new source group.
+ */
+ cmSourceGroup* GetOrCreateSourceGroup(
+ const std::vector<std::string>& 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,
+ std::vector<cmSourceGroup>& groups) const;
#endif
/**
@@ -552,14 +567,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<cmSourceGroup>& groups) const;
-#endif
-
/**
* Print a command's invocation
*/
diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx
index 22ac9d2a17..1b6020f703 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<std::string> 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);
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx
index 77fde7b3b7..890109e5ff 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<std::string>& 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<std::string> const& args,
return true;
}
- std::string delimiter = "\\";
- if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) {
- delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
- }
-
- std::vector<std::string> 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");