Using C++ Modules in Makefile

Viewed 569

I want to use the new modules feature in C++20 and as far as I understand it, both gcc and clang seem to implement enough of it to be usable.

Now, basically all code-examples I see online compile all modules separately and manually specify their order. Is there a way for make to automatically find the dependencies between different modules?

I would love to write a Makefile that basically looks like this:

# ...

SRC    := $(find $(SRCDIR) -name "*.cpp")
OBJ    := $(SRC:.cpp=.o)
PCM    := $(SRC:.cpp=.pcm)

*.pcm: CXXFLAGS += -Xclang -emit-module-interface

# ...

$(EXE): $(OBJ)
  $(LD) $(LDFLAGS) -o $@ $^

$(OBJ): %.o: %.cpp %.pcm
   $(CXX) $(CXXFLAGS) -o $@ $<

$(PCM): %.pcm: %.cpp
   $(CXX) $(CXXFLAGS) -o $@ $<

But this obviously doesn't work because make does not know in which order the modules need to be compiled.

So:

  • What is the correct way to have a generic Makefile that works with C++ modules?
  • Is there a good example for a non-trivial project using C++ modules and make?

Additionally:

  • Is there a good example for a non-trivial project using C++ modules and cmake?
0 Answers
Related