# \[RFC\] Add ability to create source\_group at target level and derive it via PUBLIC/INTERFACE/PRIVATE

**URL:** https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388
**Category:** Development
**Created:** [February 2, 2023, 3:49pm UTC](https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388 "2023-02-02T15:49:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [February 2, 2023, 3:49pm UTC](https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388/1 "2023-02-02T15:49:20Z")

</div>

Currently, source\_group() is restricted to subdirectories, which is not convenient then we have a base library with sets of headers (inside some target possibly).  
While we could use the `target\_sources( INTERFACE) for adding some headers/file sets, we can’t group it in a target itself.  
It would be convenient if we could also optionally store the source\_groups inside the targets and derive it as a property.

Possible design thoughts:

1. `source_group(TARGET <target_name> [PUBLIC|PRIVATE|INTERFACE] <old args>)`
2. `target_sources(<target_name> FILE_SET <set_name> SOURCE_GROUP NAME <group_name >[PUBLIC|PRIVATE|INTERFACE] ....)`

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [February 2, 2023, 5:09pm UTC](https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388/2 "2023-02-02T17:09:27Z")

</div>

Cc: @kyle.edwards @ben.boeckel

The `source_group` functionality is one of the last few pieces of the older directory-based model that hasn’t been updated to target-based equivalents. I agree with (2) in the original post that `target_sources` may be a reasonable place to specify source groups.

I expect people will want to control source groups both for normal sources and those in a `FILE_SET`, and perhaps map sources in the same file set to multiple different source groups.

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [February 2, 2023, 8:59pm UTC](https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388/3 "2023-02-02T20:59:04Z")

</div>

yes, we may just add the something like…  
`target_sources(<target> SOURCE_GROUP <name> FILES <files....>)`

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [January 2, 2024, 7:18pm UTC](https://discourse.cmake.org/t/rfc-add-ability-to-create-source-group-at-target-level-and-derive-it-via-public-interface-private/7388/4 "2024-01-02T19:18:49Z")

</div>

It seems that this issue is related to my question: [https://gitlab.kitware.com/cmake/cmake/-/issues/21209](https://gitlab.kitware.com/cmake/cmake/-/issues/21209) and with alternative design
