# CMAKE\_UNITY\_BUILD and CXX\_MODULES

**URL:** https://discourse.cmake.org/t/cmake-unity-build-and-cxx-modules/15450
**Category:** Development
**Tags:** gen:ninja
**Created:** [January 9, 2026, 9:20pm UTC](https://discourse.cmake.org/t/cmake-unity-build-and-cxx-modules/15450 "2026-01-09T21:20:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [January 9, 2026, 9:20pm UTC](https://discourse.cmake.org/t/cmake-unity-build-and-cxx-modules/15450/1 "2026-01-09T21:20:18Z")

</div>

I am wondering why `CMAKE_CXX_SCAN_FOR_MODULES` disables `UNITY_BUILD` on all plattforms?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 10, 2026, 3:10am UTC](https://discourse.cmake.org/t/cmake-unity-build-and-cxx-modules/15450/2 "2026-01-10T03:10:25Z")

</div>

Modules-using TUs cannot be combined into unity sources.

Basically, post-`#include`, module sources look like:

```cpp
import foo;

int implstuff() {
    return 0;
}

import bar; // error: imports belong at the top of the file.

int moreimpl() {
    return 1;
}

```
