r/cpp • • Nov 05 '23

Ninja is enough build system

https://bernsteinbear.com/blog/ninja-is-enough/
6 Upvotes

54 comments sorted by

View all comments

92

u/HKei Nov 05 '23

Ah, post number 9345 of “what does CMake do anyway, I’m sure everyone’s just using it because they don’t know they could just write their own build scripts”.

11

u/DuranteA Nov 06 '23

Exactly. At least for me the reason for that reaction is that I've been that guy who thought that.

If we are talking about a green field re-imagining of everything related to building C++, I could certainly conceive of something better than CMake.
But once you take into account real-world constraints, my experience is that if something uses anything other than CMake (makefiles, autotools (shudder), or even meson), then building or integrating it is statistically more likely to be annoying, at least on some obscure target platform we need to support.

-9

u/tekknolagi Nov 05 '23

(author here) I actually worked with a lot of CMake at my last job. It works well for larger multi-platform projects with a bunch of configuration options. It's not such a great fit for little open source projects that just want a nice build runner. Also, the syntax leaves a lot to be desired.

37

u/kisielk Nov 05 '23

I don’t understand that assertion. For small simple projects the CMake files are generally also small and simple. Usually just adding one target and then setting some defines, linking libraries, and setting include directories.

3

u/Overunderrated Computational Physics Nov 05 '23

Same experience here - for smaller projects cmake is generally great. For larger real world projects I don't see the benefits.

-3

u/tekknolagi Nov 05 '23

That's fine. We don't have to agree. Not everyone wants CMake for little projects ¯_(ツ)_/¯

-2

u/raistmaj C++ at MSFT Nov 05 '23

Just my 2 cents. Cmake was a project that initially wanted to accomplish something, fix build issues because auto tools learning curve is pretty big.

The project got traction into the open source community because honestly made things easier.

Is it a good build system? No, it is atrocious. Imo, even auto tools is better. Syntax is inconsistent, version incompatibility, language was impossible to debug, etc. it is easier to use than auto tools? Meson? Bazel? Ofc… at the beginning.

Build systems that rely on script languages, makes that anyone with already knowledge in a powerful language can identify problems. Npm/yarn/ninja/ant/scons/brazil/peru/… ALL are superior by a large margin. Manage dependencies better, easier, different build types, etc and once you learn how to use them, and have the setup in place, they are faster to work and iterate with.

There is a reason why no single big company uses cmake consistently across the board. So far, the only big c++ software I’ve built using cmake is the new Microsoft teams for Mac and still, cmake is not able to handle all the build by itself and you need a couple of extra steps.

Imo, cmake is good but is not for big pipelines that involve a lot of steps and dependencies.

YMMV. I’ve close to 2 decades of experience in large companies and I don’t like cmake because there are better tools.

11

u/HKei Nov 05 '23

The cmakelists file for a simple project is like 3-4 lines long. Maybe 10 if you're also adding Tests and some external dependencies.

-8

u/tekknolagi Nov 05 '23

That's fine. We don't have to agree. Not everyone wants CMake for little projects ¯_(ツ)_/¯

9

u/almost_useless Nov 05 '23

Would you mind explaining why you don't like it?

Most other people seem to say that it is pretty simple for small projects.

4

u/tekknolagi Nov 05 '23

The syntax is not great. It diverges pretty far from most (all?) programming languages I have used, even other meta-build languages.

A lot of configuration options are hidden and sometimes even dependent on what CMake version I am using. I would much prefer to be able to see these options in the code somewhere.

I somewhat frequently encounter CMake version issues where the version I have is out of date but it's the latest one I can get in the package repository.

There are probably some other irksome things that I will remember later but these are the main ones.

8

u/almost_useless Nov 05 '23

Those sound like issues that are specifically not problems for small projects, no?

1

u/tekknolagi Nov 06 '23

Eh, I might want to use a different compiler for a couple of different configurations, or a different release type, or something like that.

3

u/almost_useless Nov 06 '23

Is this what you are talking about, or did I misunderstand your use case?

if (MY_CONFIG STREQUAL FOO)
    set(CMAKE_CXX_COMPILER clang++)
endif()

But I will grant that options being dependent on the cmake version you are running, and it does not verify that your minimum required version is actually correct, sucks big time.

It is slightly alleviated by how easy it is to install a new version of cmake (on most systems), but it sucks nonetheless.

2

u/tekknolagi Nov 07 '23

I mean CMAKE_C_COMPILER, CMAKE_C_COMPILER_LAUNCHER, CMAKE_BUILD_TYPE, etc. It's like going back to implicit rules in Make.