source_group.rst 1.7 KB

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