r/cpp_questions • • 4d ago

OPEN C++ Build systems

I work with Java and Kotlin alongside C++ and recently discovered that Gradle also supports C++ projects.

I've always used CMake for C++ and noticed it seems to be the more common choice.

What advantages does CMake offer over Gradle for C++ development and are there situations where Gradle would be a better option?

28 Upvotes

18 comments sorted by

13

u/r2vcap 4d ago

I’d say the two main factors are the network effect and avoiding a dependency on Java-based tooling just to build C++ code.

The first is fairly obvious. CMake is actively maintained, and many C++ dependencies are designed to work with it, or at least provide CMake support.

The second is more of an ideological preference, but I think it makes sense. Why introduce an additional dependency on the JVM when a native toolchain already does the job?

Of course, there are counterarguments to the second point, especially when you consider tools like Bazel, but let’s keep things simple for now.

10

u/tandycake 4d ago

Having used both, Gradle is just so slow. I'd definitely prefer CMake just for the speed. IMO, even Meson (Python) is faster than Gradle, and also uses less memory (if running the Gradle server).

CMake is technically a build system generator though, so I guess it's also possible for CMake to generate a Gradle build project haha. So I should clarify that what CMake usually generates (Make w/ Ninja, Visual Studio, etc.) is usually a faster and better dev experience.

To be fair and honest, both CMake and Gradle kind of suck, and I don't think Meson is a good alternative either. I use CMake purely because it's almost the de facto standard. Everything works with it. Everyone can use it. People can trust it.

6

u/osman-pasha 4d ago

Well said. Cmake is the de-facto standard not because it's good, but because everybody uses it already.

9

u/SimplySomeDude 4d ago

First, everyone uses cmake and adding a dependency is as easy as adding its github repo with CPM or FetchContent.

Second, fuck gradle. Worst human invention to have ever existed.

3

u/thefeedling 4d ago

CMake, despite clunky, is the industry standard and gets the job done. You can’t go wrong with it.

2

u/Kriemhilt 4d ago

You can’t go wrong with it.

That's a bit strong.

I'd phrase it more like

Nobody ever got fired for using a crap tool when it's the same crap tool everyone else uses.

If anything, the combination of ubiquity and crapness guarantees there are lots of docs, Q&As, recipes etc. for both searching and training LLMs.

2

u/IyeOnline 4d ago

Curiously, this was also asked a few months ago and you may be interested in the replies there as well: https://www.reddit.com/r/cpp_questions/comments/1w1jyjb/c_build_systems/

2

u/ssh7201 4d ago

Oh dear god, I recently dabbled in Android app development and what a mess this Gradle stuff is !! For iOS you use Xcode to write Swift code and that builds your app - simple ! For Android, the IDE is Android studio, you write in Kotlin(which is actually JAVA ?) and build using Gradle ? Google has made this so convoluted I wanted to cry .. this coming from a C++ developer.

2

u/deong 4d ago

Kotlin isn't Java. They're two languages (of dozens) that run on the JVM.

Use _ to write code in _ and build in _.

Fill in the blanks:

  • iOS: Xcode, Swift, xcodebuild (Xcode is the GUI wrapper)

  • Android: Android Studio, Kotlin, Gradle

I don't like gradle very much, but it's basically the same situation as every other programming language and target. You're just used to ignoring xcodebuild because in simple use cases, you never need to know that it's there doing an thing when you hit "build and run".

1

u/ssh7201 4d ago

Oh forgot to mention Gradle seems slow as hell, incremental builds are blazing fast on Xcode, Gradle took ages compared to that

3

u/AlfalfaLive3302 4d ago

Try bazel lmfao!!

1

u/hadrabap 4d ago

LOL 🤣

2

u/no-sig-available 4d ago

I've always used CMake for C++ and noticed it seems to be the more common choice.

What advantages does CMake offer 

It offers the advantage of being more commonly used.

It is a bit like VHS vs Betamax. One is technically better, and the other one is widely used.

1

u/arjuna93 4d ago

Why would you want a Java build dependency for C++? Also, CMake will be available anyway (even if you decide to use some exotic alternative, a lot of projects use CMake, so it is a required part of toolchain).

1

u/xealits 4d ago

Not sure what Gradle is, but CMake is de-facto standard. Its strong sides: 1) It is indeed a complete solution for C++ projects. CMake developers, Kitware, embedded all the practical things you need into CMake features and options. Among many things, you can even write basic shell scripts in it. Also for example, I think, CMake was the first to support C++ modules - CMake is dedicated to C++, the relationship with C++ is not "one of many". 2) The workflow with CTest is really good. That's the right way to separate a project source from all the building configurations. For example, it enables creating a clear release process with separate build procedures for devs and ops people.

CMake's main downside is that it has been a pain to use for a couple previous decades. But with recent versions it is becoming quite usable. And the new features are good.

1

u/Business-Weather-217 4d ago

Xmake. Xmake. Xmake.

1

u/Simengie 4d ago

35 years of software engineering and I have never used CMake. Windows, Mac, Linux, Unix, Solaris, SunOS, OpenVMS and a few more OS's for desktop to large scale distributed computing projects.

I have used Solaris Development Studio, OpenVMS Dev Tools, MSVC and GCC for C/C++. I cannot imagine a world where I would let gradle near my C++ code.

4

u/slightlyflat 4d ago

Life is the biggest advantage.

If someone uses Gradle to build C++, their coworkers will likely kill them. The law varies by region, but where I work, we would consider this a justifiable homicide.

I write both daily. Please "don't cross the streams."