cmSourceGroup.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <memory>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include "cmsys/RegularExpression.hxx"
  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(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 explicit file list
  69. * in children.
  70. */
  71. const cmSourceGroup* MatchChildrenFiles(const std::string& name) const;
  72. /**
  73. * Check if the given name matches this group's regex in children.
  74. */
  75. cmSourceGroup* MatchChildrenRegex(const std::string& name);
  76. /**
  77. * Assign the given source file to this group. Used only by
  78. * generators.
  79. */
  80. void AssignSource(const cmSourceFile* sf);
  81. /**
  82. * Get the list of the source files that have been assigned to this
  83. * source group.
  84. */
  85. const std::vector<const cmSourceFile*>& GetSourceFiles() const;
  86. std::vector<cmSourceGroup> const& GetGroupChildren() const;
  87. private:
  88. /**
  89. * The name of the source group.
  90. */
  91. std::string Name;
  92. // Full path to group
  93. std::string FullName;
  94. /**
  95. * The regular expression matching the files in the group.
  96. */
  97. cmsys::RegularExpression GroupRegex;
  98. /**
  99. * Set of file names explicitly added to this group.
  100. */
  101. std::set<std::string> GroupFiles;
  102. /**
  103. * Vector of all source files that have been assigned to
  104. * this group.
  105. */
  106. std::vector<const cmSourceFile*> SourceFiles;
  107. std::unique_ptr<cmSourceGroupInternals> Internal;
  108. };