resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmSourceGroup.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <memory>
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "cmsys/RegularExpression.hxx"
13
14 class cmSourceFile;
15 class cmSourceGroupInternals;
16
17 /** \class cmSourceGroup
18  * \brief Hold a group of sources as specified by a SOURCE_GROUP command.
19  *
20  * cmSourceGroup holds a regular expression and a list of files.  When
21  * local generators are about to generate the rules for a target's
22  * files, the set of source groups is consulted to group files
23  * together.  A file is placed into the last source group that lists
24  * the file by name.  If no group lists the file, it is placed into
25  * the last group whose regex matches it.
26  */
27 class cmSourceGroup
28 {
29 public:
30   cmSourceGroup(std::string name, const char* regex,
31                 const char* parentName = nullptr);
32   cmSourceGroup(cmSourceGroup const& r);
33   ~cmSourceGroup();
34   cmSourceGroup& operator=(cmSourceGroup const&);
35
36   /**
37    * Set the regular expression for this group.
38    */
39   void SetGroupRegex(const char* regex);
40
41   /**
42    * Add a file name to the explicit list of files for this group.
43    */
44   void AddGroupFile(const std::string& name);
45
46   /**
47    * Add child to this sourcegroup
48    */
49   void AddChild(cmSourceGroup const& child);
50
51   /**
52    * Looks up child and returns it
53    */
54   cmSourceGroup* LookupChild(const std::string& name);
55
56   /**
57    * Get the name of this group.
58    */
59   std::string const& GetName() const;
60
61   /**
62    * Get the full path name for group.
63    */
64   std::string const& GetFullName() const;
65
66   /**
67    * Check if the given name matches this group's regex.
68    */
69   bool MatchesRegex(const std::string& name);
70
71   /**
72    * Check if the given name matches this group's explicit file list.
73    */
74   bool MatchesFiles(const std::string& name) const;
75
76   /**
77    * Check if the given name matches this group's explicit file list
78    * in children.
79    */
80   cmSourceGroup* MatchChildrenFiles(const std::string& name);
81
82   /**
83    * Check if the given name matches this group's explicit file list
84    * in children.
85    */
86   const cmSourceGroup* MatchChildrenFiles(const std::string& name) const;
87
88   /**
89    * Check if the given name matches this group's regex in children.
90    */
91   cmSourceGroup* MatchChildrenRegex(const std::string& name);
92
93   /**
94    * Assign the given source file to this group.  Used only by
95    * generators.
96    */
97   void AssignSource(const cmSourceFile* sf);
98
99   /**
100    * Get the list of the source files that have been assigned to this
101    * source group.
102    */
103   const std::vector<const cmSourceFile*>& GetSourceFiles() const;
104
105   std::vector<cmSourceGroup> const& GetGroupChildren() const;
106
107 private:
108   /**
109    * The name of the source group.
110    */
111   std::string Name;
112   // Full path to group
113   std::string FullName;
114
115   /**
116    * The regular expression matching the files in the group.
117    */
118   cmsys::RegularExpression GroupRegex;
119
120   /**
121    * Set of file names explicitly added to this group.
122    */
123   std::set<std::string> GroupFiles;
124
125   /**
126    * Vector of all source files that have been assigned to
127    * this group.
128    */
129   std::vector<const cmSourceFile*> SourceFiles;
130
131   std::unique_ptr<cmSourceGroupInternals> Internal;
132 };