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
-5
u/throw_cpp_account May 23 '26 edited May 24 '26
How to build the test.
It is remarkable to me that this is so heavily downvoted.
ctestdoes not build the tests for you, and there isn't even a default mechanism within CMake to build the tests for you by default, you have to write it yourself.By contrast:
I didn't realize pointing out that CMake is awful to use was so verboten in this community.
Bazel:
bazel test //targetboth builds and runs your test(s). Want to do it with a different configuration? Pass different arguments.CMake: Building your tests? Why would anybody want to do that? How about you figure that shit out. Different configuration? Different compiler? Make a different build directory first and then run cmake and then figure out how to build your tests first. The sheer amount of extra steps necessary is absurd. Not to mention that
ctestdoesn't just fail if you forgot to build your test(s), no... it tries to run them anyway.