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