source_group.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 options are:
  11. ``TREE``
  12. .. versionadded:: 3.8
  13. CMake will automatically detect, from ``<src>`` files paths, source groups
  14. it needs to create, to keep structure of source groups analogically to the
  15. actual files and directories structure in the project. Paths of ``<src>``
  16. files will be cut to be relative to ``<root>``.
  17. ``PREFIX``
  18. .. versionadded:: 3.8
  19. Source group and files located directly in ``<root>`` path, will be placed
  20. in ``<prefix>`` source groups.
  21. ``FILES``
  22. Any source file specified explicitly will be placed in group
  23. ``<name>``. Relative paths are interpreted with respect to the
  24. current source directory.
  25. ``REGULAR_EXPRESSION``
  26. Any source file whose name matches the regular expression will
  27. be placed in group ``<name>``.
  28. If a source file matches multiple groups, the *last* group that
  29. explicitly lists the file with ``FILES`` will be favored, if any.
  30. If no group explicitly lists the file, the *last* group whose
  31. regular expression matches the file will be favored.
  32. The ``<name>`` of the group and ``<prefix>`` argument may contain forward
  33. slashes or backslashes to specify subgroups. Backslashes need to be escaped
  34. appropriately:
  35. .. code-block:: cmake
  36. source_group(base/subdir ...)
  37. source_group(outer\\inner ...)
  38. source_group(TREE <root> PREFIX sources\\inc ...)
  39. .. versionadded:: 3.18
  40. Allow using forward slashes (``/``) to specify subgroups.
  41. For backwards compatibility, the short-hand signature
  42. .. code-block:: cmake
  43. source_group(<name> <regex>)
  44. is equivalent to
  45. .. code-block:: cmake
  46. source_group(<name> REGULAR_EXPRESSION <regex>)