# Support for reduced bmi in clang?

**URL:** https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258
**Category:** Code
**Tags:** comp:clang
**Created:** [June 18, 2025, 3:20pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258 "2025-06-18T15:20:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gracicot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gracicot/32/4525_2.png) [@gracicot](https://discourse.cmake.org/u/gracicot)
#### Post date: [June 18, 2025, 3:20pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258/1 "2025-06-18T15:20:18Z")

</div>

Hi! Clang now has support for one phase compilation through `-fmodules-reduced-bmi`, just like GCC and MSVC does. Is there a way to use this new compiler feature in CMake C++20 modules support? I searched and couldn’t find documentation about that. Thanks!

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [June 18, 2025, 7:45pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258/2 "2025-06-18T19:45:03Z")

</div>

I might be misunderstanding the full intent here, but adding it to `CMAKE_CXX_FLAGS` seems to work fine, ie `cmake -S <sourcedir> -B <builddir> -DCMAKE_CXX_FLAGS=-fmodules-reduced-bmi`.

You can sneak it onto only sources that actually use modules by appending to the undocumented variable `CMAKE_CXX_MODULE_MAP_FLAG` after the `project()` call.

`string(APPEND CMAKE_CXX_MODULE_MAP_FLAG " -fmodules-reduced-bmi")`

But I think the right answer is simple `CMAKE_CXX_FLAGS` via `-D` or a CMakePreset at config time

---

<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: [June 18, 2025, 7:55pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258/3 "2025-06-18T19:55:20Z")

</div>

CMake only supports one-phase compilation anyways (`.cxx` → {`.o`, `.pch`} rather than `.cxx` → `.pch` → `.o`). This sounds like a further enhancement to keep BMI sizes small when doing the former.

---

<div class="post-metadata">

### Author: ![vito.gamberini](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vito.gamberini/32/4376_2.png) [@vito.gamberini](https://discourse.cmake.org/u/vito.gamberini)
#### Post date: [June 18, 2025, 8:01pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258/4 "2025-06-18T20:01:38Z")

</div>

Ya it makes the BMI files ~40% smaller from my limited test, so it’s a nice little optimization

---

<div class="post-metadata">

### Author: ![gracicot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gracicot/32/4525_2.png) [@gracicot](https://discourse.cmake.org/u/gracicot)
#### Post date: [June 18, 2025, 8:28pm UTC](https://discourse.cmake.org/t/support-for-reduced-bmi-in-clang/14258/5 "2025-06-18T20:28:40Z")

</div>

Interesting. I wrongly assumed clang only supported two phase compilation. Seeing it was supported from the beginning and CMake only uses one phase, adding the flag seems sufficient. Thank you for the quick answer!
