Anyone using C++ modules with CMake?

I’m using Clang 15 and it looks like it has a fair amount C++ modules support. But what’s the status in CMake. Is it usable?

~ Rob

It’s in progress. Support is currently experimental. See:

1 Like

I think it’s practically unusable cause it doesn’t deliver sane encapsulation of the imported symbols and they are dangling inside a global namespace. The modules don’t do the most important thing they do in most programming languages: provide a way to refer imported symbols by an alias and import them from files.

This is not relevant to CMake’s support of C++ modules. While they’re not everything I’d have wanted either, it’s what C++ got.

It’s relevant in the sense that the support in CMake is not warranted as support across vendors is basically in a raw state.

Is this true of C++ modules as implemented today, or C++ modules even in their final state?

I’m not sure how else you expect the chicken-and-egg problem to be broken here without build systems supporting C++ modules even as they are being developed. They’re certainly too complicated for anything that used to do g++ *.cpp -lsome_other_lib to handle at least.

I don’t know that C++ modules will ever be “in [a] final state” unless the C++ committee ever shuts down. But import foo; has absolutely zero relation to what is made available through the foo name. It could import Boost symbols, a reimplementation of the standard library (under some non-std namespace of course), or nothing. The foo name of the module is not referenceable anywhere other than an import line. It has no methods, the preprocessor is ignorant, and you cannot do export foo.*; to export foo’s symbols yourself.

Basically, you can think of named modules being a bag of symbols that have a given label (the name) and can be looked up by that name, but once you import it, the label is gone.

(I think this is what is being complained about here at least.)

I’d like to give it a shot. I tried copying this simple example, but I’m getting:

CMake Error at MyApp/CMakeLists.txt:21 (target_sources):
target_sources File set TYPE may only be “HEADERS”

I have …

set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 3c375311-a3c9-4396-a187-3227ef642046)
add_executable(Foo MACOSX_BUNDLE)
      Foo/ Foo/App/