C++ Modules TS & CMake

Viewed 2465

I am curious about the C++ Modules TS. I have played a little around with Clang's implementation. Only one or two files or so at a time.

Now I would like to try something bigger than that. And I would like to use CMake.

Does someone know if there is some good way to use the Clang modules implementation with CMake or are there already some CMake modules which help me with this?

I would really like to know. Otherwise I have to consider using a different build system.

2 Answers

I would suggest you try build2:
https://build2.org/build2/doc/build2-build-system-manual.xhtml#cxx-modules
It supports modules for Visual Studio, gcc and clang. And for gcc there is a package that contains the standard library:
https://build2.org/pkg/hello/libstd-modules?f=full&q=library
Note that Microsoft implementation, as of Visual Studio 2017 update 4, is using the old syntax in the .ixx files (module xyz; instead of export module xyz; where the latter is what the last Modules TS draft mandates)

It shouldn't be any harder than configuring the proper command-line arguments. Since this feature has yet to be standardized and is different between the two known implementations (clang and MSVC -- gcc 7.2 documentation doesn't mention modules that I could find), I don't expect there are any CMake functions to handle anything.

AFAIK, the clang way of treating headers as special if they are in the module map file is lagging the current working draft for modules. IMO, it would be more useful to experiment with MSVC which is more closely tracking the WD for modules at this time. I don't know why g++ and clang are lagging here, they are usually early adopters. Perhaps it is because the specification is still in working draft stage and not yet a TS, I don't know.

Related