cmSourceGroup.h 3.1 KB

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