# C++20 modules: manually specifying module providers

**URL:** https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948
**Category:** Usage
**Tags:** os:linux, gen:ninja
**Created:** [June 5, 2024, 9:41am UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948 "2024-06-05T09:41:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![osiris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/osiris/32/3822_2.png) [@osiris](https://discourse.cmake.org/u/osiris)
#### Post date: [June 5, 2024, 9:41am UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948/1 "2024-06-05T09:41:20Z")

</div>

Hi,

is there a way to manually specify what modules are provided by given library?

I.e. I precompile header modules in add\_custom\_command via:  
“g++ -fmodule-header -x c++system-header cassert”  
Then wrap it into a static library “cxx\_std”

How do I tell cmake that my “cxx\_std” library provides definitions of cassert and other header modules?

Is it even possible without modifications of cmake implementation?

Regards

---

<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 8, 2024, 2:33am UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948/2 "2024-06-08T02:33:30Z")

</div>

Header units are not supported at all (CMake doesn’t know how to deal with a reported `import <cassert>;` report from dependency scanners).

---

<div class="post-metadata">

### Author: ![osiris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/osiris/32/3822_2.png) [@osiris](https://discourse.cmake.org/u/osiris)
#### Post date: [June 8, 2024, 8:03am UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948/3 "2024-06-08T08:03:41Z")

</div>

Yes, I am aware cmake does not support header units. But I am trying to implement by hand.  
Also for now I am interested in “include translation” feature of header units, i.e.  
“#include ” is automatically translated into “import cassert;”

At least for gcc this is very simple, just add new entry into modmap file:  
/usr/include/c++/14/cassert $\<BUILD\_DIR\>/usr/include/c++/14/cassert.gcm

The process is as follows:

- compiler performs usual include path resolution
- upon success it queries module mapper whether a module named with absolute path of header file exists
- if exists, replace the include with an import.

The problem is that I cannot seems to find a proper way of injecting such manually specified entries into module-mapper of given cmake target, and make them propagate into cmake target users.

---

<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 8, 2024, 1:27pm UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948/4 "2024-06-08T13:27:57Z")

</div>

> [@osiris](#):
>
> The problem is that I cannot seems to find a proper way of injecting such manually specified entries into module-mapper of given cmake target, and make them propagate into cmake target users.

CMake’s module mapper generation is completely internal to CMake. It would require coordination with the collator which is not public API. There’s no way to supplement it either.

---

<div class="post-metadata">

### Author: ![osiris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/osiris/32/3822_2.png) [@osiris](https://discourse.cmake.org/u/osiris)
#### Post date: [June 8, 2024, 7:15pm UTC](https://discourse.cmake.org/t/c-20-modules-manually-specifying-module-providers/10948/5 "2024-06-08T19:15:00Z")

</div>

I see, I guess I will have to wait for official “header units” support.

Thanks for all your modules related work in cmake and gcc!
