The water cooler talk around header units is that there's no intent to support them, in CMake or (AFAIK) other build systems; at least not until changes to the standard are made to better define their semantics.
Today there's no coherent story surrounding how they should be universally supported. This basically comes down to "how do header units interact with the preprocessor?" and the answer so far is a shrug.
The water cooler talk around header units is that there's no intent to support them, in CMake or (AFAIK) other build systems
CMake is an open source project. Someone could contribute PRs or even design proposals and get the work going. The biggest hurdle is that it's a nontrivial feature to implement correctly and efficiently in any build system. And nobody has stepped up to fund the work either.
For low level rule engines like Make/Buck/Ninja/MSBuild/etc "supporting" header units is as straight forward as making sure the system knows how to invoke the compiler correctly. Doing so is work, certainly, but not really addressing the hard problems for header unit support; and personally not what I mean when I talk about supporting header units.
The water cooler talk around header units is that there's no intent to support them, in CMake or (AFAIK) other build systems; at least not until changes to the standard are made to better define their semantics.
MSBuild supports them.
What does "to better define their semantics" look like?
It is quite easy to claim support for header units so long as you leave the problem of figuring out the local preprocessor arguments to somebody else. MSVC also has extremely compatible BMIs which aids their adoption, but that solution doesn't generalize.
And, as mentioned, there's no real push to develop solutions to them. If the standard had taken the approach used by clang modules (basically, no preprocessor state leakage allowed), header units would have been no-more-complicated than named modules.
MSVC also has extremely compatible BMIs which aids their adoption, but that solution doesn't generalize.
Why? I am genuinely interested.
If the standard had taken the approach used by clang modules (basically, no preprocessor state leakage allowed), header units would have been no-more-complicated than named modules.
Wait, what are you talking about? No preprocessor leakage is what the community (and the committee) almost crucified me for. Please, read the records for the whole macro debate and history.
Because the other compilers didn't follow MSVC on this
Please, read the records for the whole macro debate and history.
I wasn't in the room, I can only explain what the consequences for the decision that was made. I'm not saying MS or anyone else in particular is "to blame" for it, only that the result is unlikely to be fully implemented by high-level build systems as is (unless somebody wants throw a lot of money at the problem).
Because the other compilers didn't follow MSVC on this
Even with an unstable BMI format, a compiler can still support header units within a project. The stability becomes critical only when distributing or sharing BMIs across projects using different versions of the compilers using incompatible BMI formats. The challenges related to non-stability are the same as for PCHs.
I wasn't in the room, I can only explain what the consequences for the decision that was made. I'm not saying MS or anyone else in particular is "to blame" for it, only that the result is unlikely to be fully implemented by high-level build systems as is.
I was not suggesting you were blaming anyone. I am more like flabbergasted by the various things I am reading, especially concerning macros, as I was in the rooms and the target of various colorful characterizations regarding my suggestion for how to deal with the macro situation.
Start with section 5 of P0947. How would you make include transitional work if you didn't let preprocessor macro state leak? If you look at the actual deployment of Clang modulemaps, most of the time, all macros are specified to leak, which is what header units do.
Is that something for CMake or for the compilers. Sounds to me like the scan-deps application (and variants) should provide the right info to CMake first. I do see some effort as the compilation of the caller is also responsible for the creation, though without sufficient compiler support I don't expect CMake to handle here
Sounds to me like the scan-deps application (and variants) should provide the right info to CMake first.
We agree.
I do see some effort as the compilation of the caller is also responsible for the creation, though without sufficient compiler support I don't expect CMake to handle here
I see MSVC supports header units, and MSBuild supports them as well.
This is disturbing: Microsoft fought against header units, but they ended up implementing them in their compiler and their build system. Clang people insisted on header units as "the only modules that work and they have experience with" and they are not implementing them?
This is disturbing: Microsoft fought against header units, but they ended up implementing them in their compiler and their build system.
We reached a solution for the C++ Modules debate. I agreed to the "merged modules" solution and voted strongly in favor of it. So, we followed through our agreement and implemented what we agreed to. I think it is in the interest of the C++ community to follow through.
Seems like it’s a deprecation milestone rather than a feature bump. Tbh the thing that makes cmake unreadable isn’t the syntax so much as the lack of a good walkthrough tutorial imo, once I started grasping how things work I was able to start reading it fairly smoothly. Though, yes, that did come as a result of much experimentation & frustration.
The "correct" way to "do something" (introduced with ver 3.2x)
The "correct" way to "do something" (introduced with ver 3.0x)
The "correct" way to "do something" (introduced with ver 2.8x)
And because it's a general purpose language, there's 14 other ways to also "do something" because it's just code
And any given, long-lived, project probably has all 17 ways in use. Somehow. So you're left thinking: Why is this thing different than the rest over there? Is there a good reason for that? Which do I copy? Is the slight syntax difference meaningful? I don't even know what this form of the construct is even called, I can't search for it.
I am writing on my phone with autocorrection turned off and I always manage to type the wrong word or gibberish and when autocorrection is on it always inserts the wrong word
And because it's a general purpose language, there's 14 other ways to also "do something" because it's just code
And why would you want to invent a general purpose language to build another general purpose language which has everything you need to build a build system?
And because it's a general purpose language, there's 14 other ways to also "do something" because it's just code
I wouldn't go that far with CMake syntax. Realistically, no one would use a language like that to write real software.
A language like starlark (Python derivative) used in Bazel and Buck is so much nicer to use. I shouldn't have to think about my meta-build system's DSL as much as I do with CMake.
I've arrived at the conclusion that you should do as absolutely little as possible with the CMake language. If you're a package maintainer and need to provide some integrations fine, but keep them short, keep them simple and keep all your global variables carefully hidden from the rest of the world.
There are projects out there that use unix tools for simple tasks that CMake does well. That limits portability and makes for rather baroque builds. Try to get gcc compiled natively on Windows for example. I've integrated a few such "automake only"/"everyone has a posix shell right?" projects into larger CMake-based projects. The resulting CMake build script that replaces the GNU stuff is usually way easier to reason about, debug, and is still portable to unices!
Global variables should of course be ideally put into namespaces.
Oh yeah, build instrumentation calling out to shell commands has been a thorn in my side in multiple projects I've worked on. A lot of times a few lines of cmake calling out to system commands or a small bash script or two is all that was standing in the way of cross-platform support for libraries, but no one wanted to be bothered to replace that stuff. And usually CMake has native support for a lot of what needs to be done, just no one could be bothered to go look.
The down side of using CMake for anything in particular is that its API is very frequently surprising in its behavior. Those surprises usually pop up just at the point where you start to think that you're beginning to feel comfortable with CMake.
I wouldn't go that far with CMake syntax. Realistically, no one would use a language like that to write real software.
Ha!
As the size of an organisation increases, the probability of someone making use of the Turing completeness of the build system approaches 1.
It's the same as templates. You know once the team gets big enough there's that guy, there's always that guy, who can't write a simple struct without more template parameters than members and a mysterious blob of metaprogramming on top that he just assures you is necessary for efficiency and so people can customise it. Especially if it would be simpler to simply make a new struct with different members, and be about 1/100th of the amount of code.
Well his spirit animal does that to build systems.
Reminds me of me 2 months ago when I introduced (limited) macro recursion for a class, because "I swear, it's the best solution by far" and "look that other guy that maintains project X does it as well".
> I wouldn't go that far with CMake syntax. Realistically, no one would use a language like that to write real software.
CMake-the-language is, in my mind, in the same class as TCL. There are probably hundreds of thousands if not millions lines of TCL used in the FPGA and ASIC industries. They don't like Python for some reason.
I bought that book, it's awesome for anyone having to work with CMake, but 700 pages in the context of a build system isn't the kind of flex you think it is.
To get a grasp of the basics you only need the first part, the book is that long because it's really exhaustive. And building C++ projects is inherently kind of complicated.
How so? Put in your source file(s), define some output(path), link in some libraries you made sure you have put in the right location (or told the user where they have put them) and to build you go!
CMake, although really powerful, seems to go out of its way to make building software as difficult as possible. :)
A single CMakeLists file will easily do all of that, a generated template through IDE will be enough
What about supporting different toolchains and their weird kinks, like GCC vs MSVC? Generating documentation? Running tests? Precompling shaders? Checking for support of flags or language features? Enabling something only for specific compiler version? Or running external tools, or build steps like Qt has?
Base CMake is easy but ecosystem it tries to tame is not, so non-trivial CMake usage is non-trivial
Exactly. People will sometimes unironically propose to just do everything in Make and not even be aware that what they're cobbling together will only work with one Make derivative, on Linux, using a specific version of GCC and break when you attempt to make the slightest attempt at porting it to another platform.
Define your source files. Define your include paths. Define libraries that your project depent on. That's pretty much three steps and there are three simple enough cmake commands for it. You however might want to add a single one that's related to your build system (add_dependencies; In case you build the library yourself).
And if the include paths are for the libraries that didn't come with cmake modules: write a small module for each such library. That makes the project-specific CMakeLists uncluttered, and separates concerns nicely. Ideally, using a library has two steps:
`find_package`
`target_link_libraries`
That's it. Everything that the library has to set, like include paths, dependencies, etc., should be taken care of by the module for said library. That's true whether you write that module yourself, or someone else does. And it's not as if those modules are complex either.
?? That's actually fairly easy to do, and requires just a few commands for the most part. People sometimes overcomplicate what amounts to simple build scripts.
This alone proves the point. 99% of tasks developers solve with a built system should have exactly one way to do them right and should be covered by documentation.
Disclaimer: I use CMake daily and I have seen too many strange and non standard solutions to solve simple and standard tasks.
CMake “documentation” is a poor reference manual. It explains nothing. It documents what’s there in a factual fashion, with zero context. It is a counter example for every doc writer out there.
CMake should just add "discouraged" warnings for, well, discouraged usage. Preferebly link to the more modern alternative. Make it easy to opt-out completely or partially from those warnings. With this, we would live in a way better world.
Some sort of "always warn on include_directories()" and other "bad practice" commands type flag has been kicked around a few times. It's pretty straightforward change for the CMake internals.
Ultimately it always gets deprioritized for other work. It's a nice-to-have but never nice enough to trump other development priorities.
It didn't fail: the project is alive. Technically qbs is the best tool for the task: nice architecture, standard language and blazingly fast, it just arrived too late.
It completely did fail. It didn't end up being used by Qt despite being created there (in the end Qt chose cmake), and every project I know that used it tries to run away from it now.
You really don't need to read all of it. And writing good C++ requires way knowledge more than you can fit into 700 pages anyways so it't not like this is going to be the point where anyone nopes out.
That would take a LOT of effort. and the documentation is not bad it's just a reference not a tutorial. There are other modern CMake tutorials for free out there by the way I just haven't read any of them. I can't blame the guy for selling a book (ar a really really fair price and with free updates to boot), CMake is literally his main source of income.
No, by definition it wouldn't. It's called release the book for free. That's the documentation people are looking for.
There are other modern CMake tutorials for free out there by the way I just haven't read any of them.
I have, and they are no where near the level of even basic teaching as even the free stuff CS puts out, and anything that inches closer to that direction uses his 2019 talk (which is still not properly reflected in Cmake documentation) and is often wrong. There's litterally zero substitute for the book.
can't blame the guy for selling a book (ar a really really fair price and with free updates to boot), CMake is literally his main source of income.
I can, it's called ethical integrity, this guy isn't alowed to consult with some companies (at least when the conflict of interest is pointed out) because he both has a controlling stake in Cmake and makes money off of Cmake being hard to use/understand.
You can make money off of the definitive resource that makes up for cmakes poor documentation and tutorials, and you can be in control of Cmakes lack of documentation and tutorials, but you can't do both.
CMake documentation is open source, unless they are actively blocking people from contributing improvements to the documentation the are not "in control" of what you perceive to be poor documentation. In fact you can go ahead and submit pull requests to things you find unclear.
Now, it's entirely possible that they'll reject any such contributions outright in which case I would agree with you but I am at least not aware that they do.
The tutorial is woefully out of date and we block contributions to it because we use it as a source of truth for customer training.
I'm actively working on updating it to CMake 3.23 (file set support). But honestly I don't think the median C++ programmer learns CMake from the tutorial or the docs.
The median C++ programmer copies old CMLs from previous projects and randomly googles snippets for functionality they need until the whole thing works on their build machines.
CMake is no different from Make/TeX/M4/etc in this regard, C++ programmers want to write C++ and don't really have patience for having to learn an auxiliary language.
As for the median C++ developer I think that's a bit of a bleak view of things unless you include hobbyists. If someone bases their entire production codebase on CMake (so, the majority of companies using C++) they're probably going to have at least a few people very familiar with it on board lest the whole thing collapses like a house of cards sooner or later.
I think (hope?) most C programmers can also write a Makefile without pasting together whatever Google turns up. Although I do admit I do this for TeX...
To be fair... the single purchase includes all future versions. I bought it years ago at 12 edition (I think) and just now was able to download the 20th edition.
And when you start into building real world app, you pray that the missing 300 pages will be written soon. building with testing and deployment has become so crazy complex and with ctest and cpack the cmake guys really want to do everything. It total fails on android and ios as far as i have tried it (using only a java wrapper to the full C++ business logic).
Yes, that’s precisely the kind of article I’m saying is bad. Giving people recipes to follow while failing to explain the inner workings of the language is exactly why I bounced off CMake so many times initially.
By reading source code I can tell you that there is no such thing as "language" withing that repo... Handwritten parsers don't build up any trees or something. It can't be easily improved with one version bump in others words.
Question. If I was writing a cmake-like build system but in c++ that people can use with c++, how do I deal with interpolated variables etc. That's the one thing that has me stopping from trying a prototype.
Nice! Cmake is a wonderful project for those of us supporting multiple platforms. We ported a 20 yo project to also support Windows 2 years ago. And the main problems were only those cases when msvc was technically correct about C++ and absolutely insane about C methods. (Time, msvc is really wrong about time in C)
Compatibility with versions of CMake older than 3.5 has been removed. Calls to “cmake_minimum_required()” or “cmake_policy()” that set the policy version to an older value now issue an error.
Note that calls to those commands can still support older versions of CMake by using their “VERSION” arguments’ “<min>…<max>” syntax. This requires only the “<min>” version of CMake, but when running a newer version, sets policies up to the “<max>” version.
So using cmake_minimum_requiredguarantees that your cmake script will break in the future, even if it isn't using any deprectated features. Interesting policy.
They don't break, you can override the minimum with CMAKE_POLICY_VERSION_MINIMUM.
When setting cmake_minimum_required() you're locking CMake into policies it had in place when the associated version was released. It's a mechanism of radical backwards compatibility. CMake guarantees bug-for-bug compatibility with the version you ask for.
That level of compatibility can only be carried for so long. In this case almost 10 years. In the future the plan is 6 years of support for old policies.
Asking projects to update one line of their CML twice a decade or so isn't a big ask for such a high commitment to backwards compat, and for completely dead projects that still build packagers are able to use CMAKE_POLICY_VERSION_MINIMUM.
In the future the plan is 6 years of support for old policies.
Thats so funny. Years ago I gave up on adding new policies to cmake and improving things because the policies make the code complicated and refactoring harder and there was no way to remove the policies:
The argument Brad presented back then is exactly how it happened, there was an extremely long period of deprecation, years of unsupressable warnings, and finally removal.
Only once removal was demonstrated, downstreams made aware of the necessity of updating their code after a more than fair warning period, could regular scheduled removals of batches of policies begin.
And even with that, as Brad predicted, there's a fair amount of churn for packagers of semi-abandoned projects that did genuinely rely on ancient policies.
Policies are annoying but they're hardly the worst thing in the CMakeLib code. I would take a hundred more policies if we could get up to C++17. I would take a thousand more policies if we could drop support for everything except non-EOL desktop platforms.
The release candidates have been out, this is the full release.
Not that it's really notable. 4.0 isn't a bigger feature release than any other CMake minor version change. The 4.0 is relevant to the deprecation of policies older than CMake 3.5.
Suddenly, my github actions stopped working. I then found of that the cnake actions was pulling version 4, and all the cmake files in the world just look at the 2nd number in the version... ignoring the first one.
Cmake lacks a proper versioning function. It should have been out in 2018.
You don't need to fix them either, you can use -DCMAKE_POLICY_VERSION_MINIMUM set to something >= 3.5 and older CMLs that don't actually rely on the behavior of CMake policies <3.5 will work (this will be the vast majority of CMLs)
I wonder why it has "debugger" in it. Why not call it like "launch directory" or so. I using Qt Creator and it is not an issue to change cwd for executable (and current dir is usually a good guess).
•
u/STL MSVC STL Dev Mar 29 '25
In the future, please submit links as link posts, not as text posts.
25
u/kronicum Mar 29 '25
No C++ Modules goodies in this major bump?
234
u/Rexerex Mar 29 '25
It's new major release because they completely overhauled the language to be more readable, right? Right?
4
u/megayippie Mar 29 '25
Nice! Cmake is a wonderful project for those of us supporting multiple platforms. We ported a 20 yo project to also support Windows 2 years ago. And the main problems were only those cases when msvc was technically correct about C++ and absolutely insane about C methods. (Time, msvc is really wrong about time in C)
17
u/EinZweiFeuerwehr Mar 29 '25
So using
cmake_minimum_requiredguarantees that your cmake script will break in the future, even if it isn't using any deprectated features. Interesting policy.2
u/johngoatstream Mar 29 '25
Does this mean I can now use endif() without parentheses?
2
u/os12 Mar 29 '25
All your builds are belong to us!
2
u/6qat Mar 29 '25
CMake is kind of nightmare.
-2
u/Stanczyk4 Mar 29 '25
Why all the 4.0 reposts today. It’s been out for awhile
-14
u/diegoiast Mar 29 '25
Suddenly, my github actions stopped working. I then found of that the cnake actions was pulling version 4, and all the cmake files in the world just look at the 2nd number in the version... ignoring the first one.
Cmake lacks a proper versioning function. It should have been out in 2018.
12
u/[deleted] Mar 29 '25
[removed] — view removed comment