source_group.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. source_group
  2. ------------
  3. Define a grouping for source files in IDE project generation.
  4. There are two different signatures to create source groups.
  5. .. code-block:: cmake
  6. source_group(<name> [FILES <src>...] [REGULAR_EXPRESSION <regex>])
  7. source_group(TREE <root> [PREFIX <prefix>] [FILES <src>...])
  8. Defines a group into which sources will be placed in project files.
  9. This is intended to set up file tabs in Visual Studio.
  10. The group is scoped in the directory where the command is called,
  11. and applies to sources in targets created in that directory.
  12. The options are:
  13. ``TREE``
  14. .. versionadded:: 3.8
  15. CMake will automatically detect, from ``<src>`` files paths, source groups
  16. it needs to create, to keep structure of source groups analogically to the
  17. actual files and directories structure in the project. Paths of ``<src>``
  18. files will be cut to be relative to ``<root>``.
  19. ``PREFIX``
  20. .. versionadded:: 3.8
  21. Source group and files located directly in ``<root>`` path, will be placed
  22. in ``<prefix>`` source groups.
  23. ``FILES``
  24. Any source file specified explicitly will be placed in group
  25. ``<name>``. Relative paths are interpreted with respect to the
  26. current source directory.
  27. ``REGULAR_EXPRESSION``
  28. Any source file whose name matches the regular expression will
  29. be placed in group ``<name>``.
  30. If a source file matches multiple groups, the *last* group that
  31. explicitly lists the file with ``FILES`` will be favored, if any.
  32. If no group explicitly lists the file, the *last* group whose
  33. regular expression matches the file will be favored.
  34. The ``<name>`` of the group and ``<prefix>`` argument may contain forward
  35. slashes or backslashes to specify subgroups. Backslashes need to be escaped
  36. appropriately:
  37. .. code-block:: cmake
  38. source_group(base/subdir ...)
  39. source_group(outer\\inner ...)
  40. source_group(TREE <root> PREFIX sources\\inc ...)
  41. .. versionadded:: 3.18
  42. Allow using forward slashes (``/``) to specify subgroups.
  43. For backwards compatibility, the short-hand signature
  44. .. code-block:: cmake
  45. source_group(<name> <regex>)
  46. is equivalent to
  47. .. code-block:: cmake
  48. source_group(<name> REGULAR_EXPRESSION <regex>)