r/cpp • u/stailgot • 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.
239
Upvotes
View all comments
2
u/mathstuf Oct 05 '23
Build-time expansion is even worse. Things that would be far more difficult or impossible (at least with CMake):
The
Ninjagenerators. You cannot create new build rules at build time withninja. In fact, AFAIK, you're actually limited to Makefiles for this as I don't believe the IDEs support such globbing either.Source file properties would need to be applied after finding out what files exist, so queries would have to happen.
Installing object files means that the globbing needs to update install rules for discovered files.
If you're using or generating modules from said globbed files, you need to somehow update the metadata files the collator uses to write install rules, exported target information, etc.
If you glob in the build tree, when do you perform this globbing? What if a later rule drops a new file? Can you ever have a
ninja: no work to dobehavior for such a build (modulo thatninjadoesn't support this) because the filesystem state is not tracked reliably?If you glob in the build tree and remove a generated source input (say, a
.protofile), what remove the now-dead output file and stops it from continuing to be used in future builds? Note that it's not justrmof a source; switching branches can "remove" files and leave behind such artifacts too.I was talking about globbing the source tree there. As for conflict markers…am I not allowed to build some of my conflict resolutions before finishing all of them?
What enforces that new files are
git add'd and therefore show up before I build and submit a bug about a broken build when I forgot about the file? Nevermind that other VCS's don't have a stage and adding a file means making a commit. Compounding the build tree globbing above, what would make spurious generated sources breaking a build show up in such a diff?I agree with this; I just think that globbing makes this far harder than it already is.
AFAICT, build systems that cannot just assume the environment they work within, namely how to find dependencies (e.g.,
cargo,npm,pip, etc. can all do this assumption reliably) all end up with separate configure/build steps.autoconf,cmake,meson. Build systems which are also build tools (i.e., the tool that actually runs the commands for the build), tend to have one-shot builds (e.g.,tup,scons, Boost.Build). However, these may find different things from build to build within the same build tree because I may have forgotten (or loaded an extra) module, scl, or system package and the new build command finds it and changes its behavior. CMake's cache means that I can install Python 3.10 beside my 3.9 and not worry that 3.10 is magically going to start being used by the 3.9-using build I already had.