Run CMake executable targets via the cmake command
https://a4z.noexcept.dev/blog/2026/05/23/CMake-Run-Targets.htmlEvery time I use bazel for a while, and come back to CMake, I notice that I miss a cmake --run command. Bazel has a bazel run //target command.
We can not do that with cmake, but something similar.
21
Upvotes
View all comments
Show parent comment
1
u/13steinj May 24 '26
This is just so far out of left field this isn't worth debunking. The short version though, is if you're using
cmake --build <test target>, unless you're doing something I haven't seen before, it will build if necessary and run your tests. If you're usingctestwithout a sufficiently configuredCTestTestfile.cmake, then yeah, it won't build for you, because CTest is a sophisticated test harness that is effectively (if not literally) its own, separate tool.Totally agree that the defaults for both
cmakeandctestsuck, though.Not every, but nearly all of them, or you have separate problems with in-source builds and we've long since learned the issues there with original Make-style systems. Heaven forbid gasp two additional one time commands?
mkdirand the cmake configure step, which you generally don't have to rerun? If you're using the ninja generator, it's generally intelligent enough to only reconfigure-when-needed, whereas in Bazel not only is it a slow (from a responsiveness perspective) server-client model but its behavior is "slowly check if needed, then do the equivalent of a reconfigure." Waiting a minute in a large repo for "checking cached actions" always makes a small piece of me die inside.Firstly, you've severely edited your original comment since my reply. Secondly, what offends me isn't pointing out issues. All build systems have their problems! But something I've found distasteful over the past 2 years is: "How do you know someone uses Bazel? They won't shut up about it." Bazel has plenty of issues, from not supporting
runcorrectly depending on the current working directory, to inefficient analysis, to not being able to dynamically create nodes and edges in the build dag. It's still great for a large monorepo with true cross-language work (I think it's overused when all you have is some thin python or java bindings, and your true app core is C++).CMake has many problems, particularly regarding bad defaults and focusing too much on backwards compatibility of bad decisions. But I will constantly see Bazel (and less so, meson) zealots dump on it for non-existent issues, or worse yet things that don't matter in practice, while pretending that Bazel doesn't have its own limitations that forbid basic functionality (x-fail, compile tests, the --cpu=k8 vs config debacle, the mess that is the bazel prelude, build-dag tests).
I think the dichotomy of the two build systems can be seen simply as:
Kitware is a company that happened to make CMake, and now provides consulting for it. Google is a company that wanted a Python DSL for a cross-language build system, then quickly outgrew the actual need for it; the internal authors leaving and forming 4 different consulting companies, then laying off who was left inside Google maintaining it.
4+ different consulting agencies for a build system does not look like a healthy ecosystem to me, especially when their only non-consulting product / service is effectively "lets sell remote build compute at a premium."