65 points · by gumby · 3y ago · 118 comments
This deck does not address the drawbacks of doing this at all, and the only recognition of this problem is in "Stretch Goal: Research development of tool(s) to translate legacy CMake to new CMake language."
The current CMake language is fine. Nothing amazing, but good enough.
But every moment that I spend configuring CMake is a moment I don't spend doing something actually useful. I don't want to disparage the team's work--CMake is awesome software--but the way they see it is very different from the way typical developers see it.
Lol CMake was a huge reason I got out of C++ development almost a decade ago. I was tired of scripting my own shitty build systems, especially ones which couldn't even manage packages. I never actually need the power CMake offers, but the stuff I do need (reproducible package management) CMake punted on. 99.9% of the time, all you need is a build tool that takes a list of dependencies and a lockfile (or similar).
https://mesonbuild.com/Wrapdb-projects.html
Writing new wraps involves essentially porting the target project to meson though, so it's far from trivial.
You can just link all your files together in a single command without make
I'm very happy for you but almost all the C++ projects I've worked on have needed muuuuuuch more complex build system scripting than this.
That's funny. After thirty-odd years of C++ development, it's only in the last year or so that I've started to take CMake seriously, since a critical mass of other people seem to have (inexplicably) decided to treat it as something akin to an official C++ build system.
No. "Legacy cmake" has been made obsolete with the release of cmake 3.0, almost a decade ago. There is absolutely no excuse to use anything other than the declarative, target-based "modern cmake" style.
I'd go as far as claiming that 95% of all use cases boil down to simple straight-forward one-liners with modern cmake, with the remaining 5% corresponding to putting together custom cmake find modules, packaging, and deploying runtime dependencies.
> (...) now there need to be two more languages (slide 13) (...)
I'd argue that if anyone feels the need to write scripts to do something in cmake, they are already doing something awfully wrong to start with.
"made obsolete" != expunged from codebases. I'm sure there are plenty using cmake 2.x conventions that haven't been updated, and need maintaining. And in order to either maintain or upgrade, one needs to know both conventions.
No, not really. You only need to know the declarative, target-based modern cmake. Most of the ad-hoc nonsense done with legacy cmake is either features that since the 2.x days were added to cmake, or nonsense that should never have been written to start with.
I seems common for people to try to have CMake run Python scripts, install stuff on the system, and do all sorts of custom tasks. I'm sure other build systems also allow devs to make a mess if they want to. Maybe some are less powerful, so that people cannot make such a mess even if they want to. But "the tool is too powerful, I will shoot myself in the foot because I don't want to learn the basics" does not sound like a good argument to me.
> The current CMake language is fine. Nothing amazing, but good enough.
I'd argue these two statements are in conflict.
I came to c/c++ after several other languages and ecosystems -- the c++ dependency/build ecosystem is by far the worst.
CMake does work. It's underlying capabilities are great, even. But "modern cmake" is sort of a joke syntactically. Generator expressions are indecipherable. Semicolon delimited arrays, no distinguishing between input/output variables... I personally would love for a different DSL frontend to CMake.
> I don't want to disparage the team's work--CMake is awesome software--but the way they see it is very different from the way typical developers see it.
I have to agree with this. The underlying core of cmake is actually pretty awesome. Modern cmake is an improvement in capability. The team deserves credit for that.
Yeah. CMake works, it can do everything you want somehow, but it's a total mess, and the documentation isn't great.
Just a simple wrapper API (like libcurl-easy, for example) would go a long way.
I completely disagree, I almost always find what I need in the docs.
> Just a simple wrapper API
IMO, just spending a couple of hours learning the basics would go a long way. Usually that is not done.
But its biggest issue, arguably, is the extreme proliferation of bad information. Everything on StackOverflow and similar sites is outdated and bad practice for the most part. You're right that introducing a new language which deprecates the old will make this an even bigger issue.
No, CMake is terrible. It is in fact quite a feat how god damn terrible it manages to be.
I have built cmake systems from scratch and replaced others with vanilla make. I am currently stuck dealing with a cmake project that would make all of Byzantium blush.
I agree that cmake is terrible. The more I learn to use it properly, the more I hate it.
In addition:
If you think cmake is solving any problems that vanilla make does not handle better, then either (1) you don't understand how to build and package software, or (2) haven't spent an hour or two reading the gnu make manual and "recursive make considered harmful".
What am I missing?
If you ship a library, then you need to provide a way to install it somewhere, and ideally a way to find it (e.g. pkg-config, at least on Linux).
If you need to use CMake because your dependencies use CMake, you are doing something wrong. I typically build dependencies with all sorts of build systems, I just don't mind. I just need them to be installed somewhere such that CMake can find them.
The irony of using “hype” to describe make/CMake/autotools while referencing Zig as an alternative example.
Building a build tool written in C or C++ requires a build tool — hence the existence of make/CMake/autotools, which can bootstrap themselves from a minimal environment.
C/C++ compilers don’t have a scripting language built in to construct your build system on top of?
I mostly use distools to build python modules but I have a couple projects where there is code generation, building static libs, &etc… and I find it easier to use cmake to just pop out a python module.
Cmake can also be convinced to make distro packages, like rpms and debs, without too much trouble — not sure how to do that in any other build system.
Similarly there's things that have been ad-hoc standards forever, like "make clean" to remove all build and test artifacts, or "make test" for running tests.
Many of my coworkers only use it in this way and are unaware make looks at files/timestamps.
I ended up being fairly proficient with the "modern" CMake language after investing a ton of time into it, but as the size of the company grew, I ended up being a bottleneck. Every other team found themselves subject to CMake's many footguns, and I'd end up having to step in to help.
It was maddening, but I 100% get that other teams just wanted to focus on getting their work done, rather than fighting with a poorly-documented and frustrating build system.
I, for one, would be very happy to see a new CMake scripting language. Ideally, one that is a lot more friendly for beginners and occasional users.
Getting your project to build properly should be part of "getting the work done". Modern software is way too much about stacking up hacks to "get the work done" instead of writing proper code.
Sure, there could be a better way than CMake. But it's not that hard to learn the basics.
Eg, you'd think downloading a file in cmake would be fairly straightforward, but it's not really.
I also never got why we need DSLs for build systems. It seems like Turing completeness is often inevitable, no matter if people don't like it. There is no reason that a build file couldn't be mostly declarative with a general-purpose programming language though.
If you're still struggling with this, a solution is to use ExternalProject to create a "superbuild" top level project that has various subprojects being built with different toolchains.
The same reason they show up anywhere: to have the correct level of abstraction, or its cousin "signal/noise ratio." Trying to debug "gcc -o build build.cc && ./build" sounds like the 8th circle of hell to me. I can show a concrete example: https://github.com/facebook/sapling/blob/0.1.20221201-095354... So, when this raises OSError or FileNotFoundError due to some botched assumption, I guess one just attaches pdb to it and now your job is to be a python expert
Or, my other favorite "what is wrong with you:" https://hg.mozilla.org/mozilla-central/file/FIREFOX_NIGHTLY_...
Or, so as to not just be hating on python, this junk: https://github.com/brave/brave-browser/blob/v1.48.33/package... and its https://github.com/brave/brave-core/blob/master/build/comman... friend
All of those are in a general purpose programming language, and they require spelunking through thousands of lines of code to surface the actual commands and dependencies that are buried therein. And, if you become a domain expert in mach, where else are you going to apply that expertise?
Well, debugging cmake files is not any better, in my experience. And I can't even attach a debugger. I can rely on printf debugging or pray that cmake with --trace or --trace-source has the relevant information I need (often it doesn't).
edit:
Well, your disgust is justified against ad-hoc imperative build systems that happen to use a general-purpose programming language. It doesn't have to be like this. I liked the idea of scons, for example, unfortunately it had other problems.
$ cd mozilla-central
$ find python/mach python/mozbuild/mozbuild -name '*.py' -exec cat '{}' ';' | wc -l
83088
$ find keepassxc -name CMakeLists.txt -o -name '*.cmake' -type f -exec cat '{}' ';' | wc -l
866
I am on-board with something like Starlark, which is allowed to make reasonable build decisions with the information available to it, but is prevented from mutating my system. I try to be very disciplined about reading every .gradle file carefully, because jokers love to do whatever they want when they have a full-blown programming language available to themI'm curious: is there any way to estimate how much US taxpayer support went into creating CMake? Would CMake exist were it not for the DOE and/or NSF grants that Kitware got?
Getting that kind of support isn't a fault of CMake, but I think it's a meaningful property in considering and comparing different software development projects, and evaluating their long-term health.
I'm not impressed, for two reasons:
* Backwards compatibility for the CMake language is not desirable. It would be better to allow files to be translated to the new language completely. Sure, CMake could support having files in the old language and files in the new language, but the CMake language is so bad that a break from it is the best path forward.
* The CMake language is not the only drawback to CMake, unlike the claims in the presentation. CMake's model is hamstrung as well, in several ways.
Here are some ways in which the CMake model is hamstrung:
* Generating a build file for another build system. This means that CMake always gives up control of the build. It can only tell the other build system the dependency graph and then sit back and watch. It can't regulate the build itself.
* No dynamic dependencies. If you need dynamic dependencies, you need to call into CMake to generate a new and separate build file for the second build system and then call that. And because the two build files that CMake generated don't know anything about each other, it's hard to regulate the use of computing resources between them; you either have to complete the one and start the other, or you risk over-extending on your computing resources.
* No way to generate a target that doesn't call an outside process. More generally, the only way to generate a target (unless my CMake knowledge is old) is to have the second build system create a child process. This is strictly less powerful than having the same scripting language available during configure also available in targets. For example, LaTeX is only properly built with a loop that checks for a fixed point. If you can't loop in your target, you have to use an outside bash script or something of the sort to make up for it.
* No way to have targets that do not generate files and have other targets depend on those targets. If a target does not generate a file, CMake does not know how to make other targets depend on it (unless my CMake knowledge is old).
* The model of "configure in Turing complete language and then build" also means that configuring often has to happen more than once before a build. You see this if you use `ccmake`: you configure, and new options appear. You set the options and configure again. More options might appear. Using plain `cmake` hides this by using defaults, but that just means the user might end up with a build they didn't want because they didn't get a chance to set all of the options they might care about.
Anyway, rant over.
That's the critical selling point of CMake in my estimation. When I'm on Windows, I can generate a Visual Studio project and use its excellent debugger and code analysis tools. When I'm on Mac, I can generate an XCode project. Or a CLion project, or Makefiles, or...
Decoupling the build "recipe" from the build toolchain is critical for collaborative, cross-platform, cross-architecture projects, IMHO.
> No way to have targets that do not generate files and have other targets depend on those targets.
Isn't that exactly what an INTERFACE library is for? <https://cmake.org/cmake/help/latest/command/add_library.html...>
I've already addressed some of this in another comment ([1]), but you bring up more points, so I'll address it here.
CMake's model forces it to generate build files for other build systems. The better model does not force the build system to, but it also does not preclude doing so.
Separately from actually running a build (and that's important), my build system will be capable of generating files for VS, XCode, and other IDE's, but the files it generates will simply tell the IDE's how to integrate with my build system by telling them how to call it with the correct build profile. And yes, it will generate multiple possible build profiles, allowing VS users to select the solution the want to build from within VS.
But this means that my build system will not only integrate better with IDE's than CMake, it will still retain full control of actual builds.
This includes using debuggers and analysis tools, by the way. I wouldn't consider my work done on IDE integration until all of that is as easy as possible, and definitely as easy as CMake.
> Isn't that exactly what an INTERFACE library is for?
Maybe? It might be enough. At first glance (and I fully acknowledge that I could be wrong here), it seems like CMake expects the "target" to be a library of some sort. That's not the sort of thing I would personally want.
I would want to be able to depend on any target for any target.
But again, I could be wrong. I've never been able to understand the CMake docs.
CLion’s native support for CMake is the only thing that makes the IDE story palatable, but everything about CMake’s architecture resists treating CMake as a declarative format and performing that kind of intelligent integration.
Except that you don't need to, Visual Studio has support for CMake built in (since 2017).
That is a hard requirement to using Visual Studio and XCode, which I wager account for more than 90% of C/C++ projects.
Here's how my build system will do it: the programmer will list default build profiles. Then the build system will generate Visual Studio or XCode files that include all of those default build profiles, but those VS or XCode files will simply call my build system with the correct build profile.
Thus, when a build is run from VS or XCode, my build system is still in full control.
In essence, instead of generating build files for use by other build systems, my build system will generate files to tell VS and XCode how to call my build system. It will tell VS and XCode how to integrate it.
Anyway, CMake is terrible - for all the reasons you have identified - so I wish you luck!
Funny you should mention Bazel and Buck; I'm coming for them too! I'm also coming for Nix; I want its advantages to be easily accessible for mere mortals.
I think I can do better alone than those teams have because they have all made assumptions that weren't great. I'm learning from their mistakes.
Also, UX matters, and I'm putting a lot of effort into that.
But the other reason is that if you do Nix right, the capabilities of Bazel and Buck just appear.
Thank you for the encouragement!
I'm curious about that... Nix has no notion of "providers" AFAIK, but these are key for optimization and composition of targets in Bazel / Buck(2)
With CMake, the new stuff still sucks.
For me, Nim and Nimble work pretty well.
I don’t understand why people are surprised to see similar complexity creep in the “reborn” CMake ecosystem.
There has never been a one size fits all all purpose glue. It’s not surprising to me that neither is it possible to make a one size fits all “glue my software together” stack.
Plus the idea seems to be to add it on top, so if it flops, no big deal, the old stuff will still be there.
PROG=foo
SRCS=foo.c
MAN=
.include <bsd.prog.mk>
Very terse, super flexible and easily amenable to tooling (It's trivial to generate IDE project files from this).https://wiki.netbsd.org/tutorials/bsd_make/#index1h2 https://crufty.net/help/sjg/bmake.html
xmake.io
PS: I know that make has many shortcuts to compile a C/C++ codebase but in essence its targets as file system time stamps.
But to your question, the answer is kinda. There is support for a few other languages built in (off the top of my head, Ada and Fortran I believe) and you can provide a custom backend as well for your own language support but most people just use add_external_command
ada support in cmake is terrible. in the end you have to call gnatmake several times, if you want a build that always work. terrible.
There are much better alternatives:
That's been my favorite part of CMake (even before CLion used it as their defacto project format): if you can get a run of cmake to complete (which, granted ...), then you can open the project in a sane IDE and have library and build targets available