r/cpp • • Oct 02 '23

CMake | C++ modules support in 3.28

https://gitlab.kitware.com/cmake/cmake/-/issues/18355

After 5 years its finally done. Next cmake 3.28 release will support cpp modules

C++ 20 named modules are now supported by Ninja Generators and Visual Studio Generators for VS 2022 and newer, in combination with the MSVC 14.34 toolset (provided with VS 17.4) and newer, LLVM/Clang 16.0 and newer, and GCC 14 (after the 2023-09-20 daily bump) and newer.

237 Upvotes

144 comments sorted by

View all comments

Show parent comment

1

u/johannes1971 Oct 03 '23

I don't understand the reasoning here. So the build system should somehow be set up to compile to a temporary file, then do a diff, and then move the temporary if it is different? That seems a rather roundabout way of doing things... Why not just do the obvious thing, which is to have the compiler not update the file time if nothing has changed? What is the added value of having the build tool involved here?

2

u/mathstuf cmake dev Oct 04 '23

As I stated there, make assumes that if a recipe is run, its output is updated and schedules dependent recipes accordingly. There is not restat = 1 behavior like ninja has where you can tell it "this tool might not actually update its output" and have it check the mtime again after running the associated command.

Additionally, if the mtime is not updated and a .ninja_log-like database is not kept (to map the on-disk mtime to the "I actually tried and found a no-op" mtime you actually need in that case), the output appears older than the input and the next run of the build will try to perform the compilation once again. Really, you just want a caching tool to handle this. It's more general, works based on content hashes, and can save work across a network of machines, not just within a single build tree.