C++20 modules: manually specifying module providers

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

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

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.

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.

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!