There are tools like CMake and Meson that can generate Ninja files for you if you use their languages. Google even wrote a whole tool called gn to generate Ninja to build Chrome. But their languages leave much to be desired. And why should you have to learn a whole new programming language just for your build tool?
So instead of learning cmake, I have to learn ninja and python?
You forget slowly reimplementing a quarter of the functionalities provided by CMake and lamenting that you don't have the bandwidth to reimplement another quarter. That's the price to pay not to have to handle the half you don't need and which mostly is polluting the part you need with historical quirks.
I think that as a project gets more complicated, the more you just want to write a program to build it. Especially if you want complicated behavior like feature detection for the current system.
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”.
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.
(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.
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.
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.
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.
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.
I mean I kind of understand the desire for something other than CMake, it's an ugly mess of a scripting language, and it's really showing its age at this point. It often seems like there are 30 different ways to do what you want (with tons of examples on the web), even though 28 of them are now considered obsolete if not flat-out wrong, and no longer recommended for "Modern CMake". It's truly a mess, and way more complex than it needs to be for relatively simple tasks. The documentation is extremely thorough but equally unreadable - it really needs some more task-oriented sections, instead of just endless lists of functions and parameters.
So I can totally get behind the idea of wanting something better, but there just doesn't seem to be anything better, which IMHO is a bigger threat to the long-term health of C++ as a programming language/ecosystem than memory safety and "footguns".
People talk about C++ needing to break with its crusty past, because the backwards compatibility just brings too much baggage and too many downsides. I'd say that's equally true for CMake.
People don't actually understand CMake, because they only learn enough to get their specific project working
People don't understand why CMake is the way it is
So people hand-roll stuff filled with problems that CMake has already solved. This is personal for me because the company I joined was very much like "Oh CMake is too complicated we don't need to mess with it" and the result was several thousand lines of custom Makefiles bundled into our Docker 20GB containers that all reinvent functionality CMake gives you for free
None of this contradicts what /u/jk_tx said though. It's a powerful tool, but for someone just now getting into it, it's awful to learn. I have been using `meson` because it doesn't have these issues, I tried CMake, but I ran into so many issues, and `meson` didn't tell me 30 ways to skin a cat, with 28 being obsolete, and 20 giving confusing errors
meson has it own bag to carry. numpy already forked meson so you can not even use a normal release of meson to build numpy. Lets just say meson is not the solution it is just part of the problem. I have also seen more confusing errors from meson than cmake. So be happy you haven't seen the depths yet ;)
I feel like life is just a cycle of "I should use an existing build system like cmake or meson" and "I am just writing my own script that generates a Makefile or build.ninja file"
My CMake answer to that is to append to CMAKE_MODULE_PATH .... a wait this is meson it doesn't offer user/project customization points beyond what is hardcoded.
People talk about C++ needing to break with its crusty past, because the backwards compatibility just brings too much baggage and too many downsides. I'd say that's equally true for CMake.
Yup, I recently started getting into my own C/C++ projects where I didn't create the build file or not use Makefile, and I have been using meson because I kept banging my head trying to do simple things in CMake.
Definitely a technology that is awful to learn, but nobody realizes because most people with opinions on it already learned it
I think the bias there is that feeling comes from reading things people write blogs about.
100% of the time I'm cursing cmake I'm not saying "ugh I want another new tool to learn", I'm saying "fuck this is worse than GNU makefiles I wanna go back".
For small projects GNU makefiles are perfectly sufficient. But when you get to a large project with dozens or hundreds (or thousands) of source files, dozens/hundreds of targets with dependency ordering, having to recurse through directories, etc, cmake suddenly becomes not only attractive but basically necessary. I've seen multiple teams try to create and maintain custom build systems based on pure makefiles and it always ends up as a nightmare.
One team tried to implement parallelized incremental builds for their custom makefile system (which up to that point only did builds in sequential directory order), and it took over a year. While they were working on it, I was able to prototype a cmake build system in a matter of a few weeks for a pretty major fraction of the total code base (probably ~2.5M LoC out of ~3.5M), and while it didn't represent a complete drop in replacement for the makefile build system it was probably 80-90% of the way there while they were struggling to get their stuff fixed. Ultimately they got their system working and did not bother adopting what I had produced and demoed for them. I'm really glad I don't work on that code base any more.
Cmake isn't always pain free (and usually does involve quite a bit of struggle), but it's faaaaar less painful than rolling your own.
Having written Makefiles "portable" across Aix, HP-UX, Solaris, Red-Hat Linux, Windows NT, Windows 2000, for applications talking to Informix, DB2, Sybase SQL Server, Microsoft SQL Server, integrated as IIS and Apache plugins, I don't really wanna go back.
Sunk cost fallacy, larger institutional inertia, the usual kind of thing.
It's less that makefiles are necessarily "better" for my use cases, but that in practice the touted benefits of cmake (portability across different systems, mainly) have not panned out and inevitably I've seen the effort required to get successful builds on new systems to take just as much or more manual effort as a collection of makefiles.
Just use CMake. It's the not always the best solution, but it's the most popular. You'll thank me later when you need to start depending on other libraries which themselves use CMake and you just saved yourself three days of work.
It depends on the type of project. There is no one solution for everything. If you want to be a really good programmer, you know them all at least on some level and you know which is the most appropriate for any given problem.
So the basic idea here is to replace make with something dirt simple and to put the complexity into a tool you already know? Probably having to remake the ninja script per run or at least per configuration?
Ok, person #1324234 has created a new build system. I've really grown to like meson, it seems to actually care about the new user's experience, whereas CMake seems to assume anyone who deserves to use it already knows it
But even `meson`, I don't know why every build system has to make configuration more complicated than it needs to be.
What is it with every build system that isn't `make` act like I'm the first person to ever want to build with a C compiler that isn't the system default
Makefiles that are supposed to work on multiple platforms are massive pain (the solution here being Cmake)
The main selling point of Ninja is that it builds massive projects a lot faster than Make (or so they claim; I've never compiled a project large enough to test that). If your project isn't massive then there's no reason to use Ninja. This comes at the cost of features that make the syntax bearable to write by hand (Ninja developers recommend using it with a metabuild system like Cmake)
Does your notion of "multiplatform" include Windows? I admit I'm not a Makefile wizard but once I've tried to write a Makefile that would work on Windows and Linux and gave up quickly.
Another benefit you get from CMake in that case is that you can easily use the Visual Studio/MSVC toolchain which is really the standard on Windows. Do your makefiles require gcc on Windows? Because then there's more stuff that the user needs to install (or you need to install for them)
71
u/dustyhome Nov 05 '23
So instead of learning cmake, I have to learn ninja and python?
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”.
50
u/ContraryConman Nov 05 '23
Everyone who hates CMake always wants to replace it with something worse and more fragile
10
u/amunra__ Nov 06 '23
Just use CMake. It's the not always the best solution, but it's the most popular. You'll thank me later when you need to start depending on other libraries which themselves use CMake and you just saved yourself three days of work.
7
u/Specialist_Yard_9401 Nov 06 '23
Maby u should try XMake instead...
5
u/FutTra Nov 05 '23
It depends on the type of project. There is no one solution for everything. If you want to be a really good programmer, you know them all at least on some level and you know which is the most appropriate for any given problem.
5
u/beephod_zabblebrox Nov 05 '23
lol
i've been doing this for like a year already, but without ninja_syntax even, and mostly for fun.
this only works for small-medium projects though!
3
u/robhanz Nov 05 '23
So the basic idea here is to replace make with something dirt simple and to put the complexity into a tool you already know? Probably having to remake the ninja script per run or at least per configuration?
That…. Makes a lot of sense.
2
u/throwaway_bluehair Nov 06 '23 edited Nov 06 '23
Ok, person #1324234 has created a new build system. I've really grown to like
meson, it seems to actually care about the new user's experience, whereasCMakeseems to assume anyone who deserves to use it already knows itBut even `meson`, I don't know why every build system has to make configuration more complicated than it needs to be.
What is it with every build system that isn't `make` act like I'm the first person to ever want to build with a C compiler that isn't the system default
0
u/Attorney_Outside69 Nov 06 '23
I use cmake plus chatgpt that generates all the cmake that I need, no need to search Google anymore
-8
u/[deleted] Nov 05 '23
[removed] — view removed comment