# CMake 4.5.0: source\_group() undocumented prefix detection change: regression or intentional?

**URL:** <https://discourse.cmake.org/t/cmake-4-5-0-source-group-undocumented-prefix-detection-change-regression-or-intentional/15914>\
**Category:** Code\
**Created:** [November 14, 2026, 10:25am UTC](https://discourse.cmake.org/t/cmake-4-5-0-source-group-undocumented-prefix-detection-change-regression-or-intentional/15914 "2026-11-14T10:25:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ark1409](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ark1409/32/6320_2.png) [@Ark1409](https://discourse.cmake.org/u/Ark1409)\
**Post date:** [November 14, 2026, 10:25am UTC](https://discourse.cmake.org/t/cmake-4-5-0-source-group-undocumented-prefix-detection-change-regression-or-intentional/15914/1 "2026-11-14T10:25:38Z")

</div>

Consider this file tree:

```auto
.
├── CMakeLists.txt
├── thing
│ └── file.cpp
└── thing.cpp

```

* * *

Prior to CMake 4.5.0, the following project configured successfully without any errors:

```cmake
cmake_minimum_required(VERSION 4.4)
project(my_project NONE)

source_group(TREE thing FILES thing.cpp thing/file.cpp)

```

Output:

```sh
$ ./cmake-4.4.5-linux-x86_64/bin/cmake -S . -B build

-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /dir/build

```

* * *

However, with the latest CMake (4.5.0), we get

```txt
$ cmake -S . -B build

CMake Error at CMakeLists.txt:4 (source_group):
  source_group "/dir/thing" is not a prefix of file
  "/dir/thing.cpp"

-- Configuring incomplete, errors occurred!

```

Admittedly, you could claim that doing this is a bit weird, but nothing in the documentation ever gave a precise description of what it meant for the paths in `src` to “start with” `root`. As such, we have projects such as Boost.Locale depending on this old behavior that are now unable to be built using CMake.

The change seems to have been introduced in `44fd6ec` when they [switched the prefix checking mechanism to use `cmCMakePath::IsPrefix`](https://github.com/Kitware/CMake/blob/44fd6ec55168f6869495e6bdefd8088912074b09/Source/cmSourceGroupCommand.cxx#L72), which only returns true if its within a subdirectory of that name or is an exact match. Meanwhile, the old mechanism [only checked for string prefix](https://github.com/Kitware/CMake/blob/c76a8de6b65424b684b7e466b2f31a27286847b7/Source/cmStringAlgorithms.h#L318).

Was the above change in semantics intended, or is this some sort of regression?

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [November 14, 2026, 10:47am UTC](https://discourse.cmake.org/t/cmake-4-5-0-source-group-undocumented-prefix-detection-change-regression-or-intentional/15914/2 "2026-11-14T10:47:10Z")

</div>

I disagree, the documentation seems pretty clear about this erroneous usage of `source_group`:

> The command fails if the paths within `src` do not start with `root`.

A file path **must** start with the value of `root`.

The problem is this erroneous usage was not detected previsoulsy.

---

<div class="post-metadata">

**Author:** ![Ark1409](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ark1409/32/6320_2.png) [@Ark1409](https://discourse.cmake.org/u/Ark1409)\
**Post date:** [November 14, 2026, 10:50am UTC](https://discourse.cmake.org/t/cmake-4-5-0-source-group-undocumented-prefix-detection-change-regression-or-intentional/15914/3 "2026-11-14T10:50:57Z")

</div>

> the documentation seems pretty clear about this […]

~~I mean, that’s a matter of definition. The paths in question were~~

```txt
/dir/thing
/dir/thing.cpp

```

~~Arguments can be made for either side that `/dir/thing.cpp` does indeed (or does not) start with `/dir/thing`.~~

EDIT: In retrospect, “cutting paths to be relative to `root`” wouldn’t make much sense otherwise…

There is indeed only one correct option here. This is simply a bug fix then.
