source_group.rst 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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>``. The command fails if the
  19. paths within ``src`` do not start with ``root``.
  20. ``PREFIX``
  21. .. versionadded:: 3.8
  22. Source group and files located directly in ``<root>`` path, will be placed
  23. in ``<prefix>`` source groups.
  24. ``FILES``
  25. Any source file specified explicitly will be placed in group
  26. ``<name>``. Relative paths are interpreted with respect to the
  27. current source directory.
  28. ``REGULAR_EXPRESSION``
  29. Any source file whose name matches the regular expression will
  30. be placed in group ``<name>``.
  31. If a source file matches multiple groups, the *last* group that
  32. explicitly lists the file with ``FILES`` will be favored, if any.
  33. If no group explicitly lists the file, the *last* group whose
  34. regular expression matches the file will be favored.
  35. The ``<name>`` of the group and ``<prefix>`` argument may contain forward
  36. slashes or backslashes to specify subgroups. Backslashes need to be escaped
  37. appropriately:
  38. .. code-block:: cmake
  39. source_group(base/subdir ...)
  40. source_group(outer\\inner ...)
  41. source_group(TREE <root> PREFIX sources\\inc ...)
  42. .. versionadded:: 3.18
  43. Allow using forward slashes (``/``) to specify subgroups.
  44. For backwards compatibility, the short-hand signature
  45. .. code-block:: cmake
  46. source_group(<name> <regex>)
  47. is equivalent to
  48. .. code-block:: cmake
  49. source_group(<name> REGULAR_EXPRESSION <regex>)