# Behaviour of source\_group(TREE ...) with no FILES specified

**URL:** https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357
**Category:** Code
**Tags:** gen:xcode
**Created:** [June 9, 2020, 7:08am UTC](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357 "2020-06-09T07:08:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrew/32/2478_2.png) [@Andrew](https://discourse.cmake.org/u/Andrew)
#### Post date: [June 9, 2020, 7:08am UTC](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357/1 "2020-06-09T07:08:25Z")

</div>

Generating for Xcode using CMake 3.15.3:

Why does:

`source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/${my_source_subdir} FILES ${my_files})`

do something sensible (all source files in a nested structure), while

`source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/${my_source_subdir})`

lists all files under a directory called TREE?

If it can implicitly find the files, why doesn’t it implicitly use them to create nested source groups?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [June 9, 2020, 11:42am UTC](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357/2 "2020-06-09T11:42:01Z")

</div>

I guess that is due to the legacy signature of `source_group`:

```auto
source_group(<name> <regex>)

```

which is equivalent to

```auto
source_group(<name> REGULAR_EXPRESSION <regex>)

```

(see at the bottom of [https://cmake.org/cmake/help/latest/command/source\_group.html](https://cmake.org/cmake/help/latest/command/source_group.html))

In your case, I guess you could use

```auto
source_group(TREE <root> PREFIX <prefix>)

```

to avoid passing `FILES`.

I hope this helps!

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrew/32/2478_2.png) [@Andrew](https://discourse.cmake.org/u/Andrew)
#### Post date: [June 9, 2020, 10:40pm UTC](https://discourse.cmake.org/t/behaviour-of-source-group-tree-with-no-files-specified/1357/3 "2020-06-09T22:40:32Z")

</div>

I tried

```
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/${my_source_subdir} PREFIX source)

```

and that doesn’t seem to do anything. I just get the traditional Sources and Headers with all files in there flat.

At this point, it seems the option to omit FILES from source\_group(TREE) is meaningless.
