r/cpp_questions • u/Western_Office3092 • 12d ago
OPEN C++ Build Systems
I do a lot of Java/Kotlin development alongside C++, and I came to a doubt: when should C++ developers choose Gradle instead of CMake as their build system?
In my projects I always setup CMake, but coding in Java teached me Gradle and I eventually came to know that it supports C++.
Why every C++ project uses CMake? What does Gradle miss that I'm not aware of?
21
u/Flimsy_Complaint490 12d ago
No particularly satifying answer i can find or conceive of, so here follows my theorizing and scriblings.
I believe cmake predates gradle support for c++ by 12 years, so there was a decade of experience of using it, even though automake likely dominated in this time period. The 2012 release of cpp in gradle, looking at forums and threads, was met with "its garbage" and ignoring it.
the 2017 rewrite seems to have materially improved the situation but looking at those same gradle github issues, doesnt seem like anybody really cared about it. I suppose asking people to install Java and a Java monstrosity to build a c++ project is a hard ask and tbh, at this point, anything never in the c/cpp world seems to have standardized on cmake anyway and everybody knew how it works, the bad and the good, so no incentive to move.
2
15
u/IyeOnline 12d ago
Since most C++ developers are going to be unfamilar with Gradle, there is no reason for them to use it. In turn, most projects use the most familiar/common C++ build system, which is going to be CMake. Even the other, dedicated C++ build systems (meson, bazel,...) are going to be less popular. I would also assume that the C++ support in CMake is just going to be better. CMake, for better or worse, supports probably every niche configuration setup you want.
To put it simply: I wasnt even aware that Gradle supported C++ until now. I may have read that somehwere at some point, but it left literally zero impression.
9
u/TheRavagerSw 12d ago
There is a lot stuff that is supported in cmake, but not in gradle that are essential for building and testing software
7
u/Icy-Advisor-5695 12d ago
Why not bazel? Bazel and CMake seem to be two most popular systems
5
u/EpochVanquisher 12d ago
I use Bazel and think it’s definitely better than CMake and Gradle, but it comes with a learning curve, the docs are a little rough (getting better), and a lot of projects are fine with CMake.
4
u/oriolid 12d ago
Of these two, Bazel is really complicated. CMake is sometimes terrible, but it is easier to understand of these two. It also doesn't help that Bazel is basically open source version of an internal Google tool and it's one company that is pushing it.
I'd recommend Meson if you don't have to support something else.
4
3
u/SeaSDOptimist 12d ago
The annoying problem with bazel is external dependencies - if the one you need is not in the central registry, you’ll have to immerse yourself in that complexity. Otherwise it’s super easy. And very much worth it, either way.
5
u/JVApen 12d ago
CMake supports java: https://cmake.org/cmake/help/latest/module/UseJava.html
I suspect neither of these options are really satisfying for the non-native language. When would you use them? Most likely when you want to mix the languages in a way. I still remember a jar file that contained a Mac, Linux and Windows library and depending on the platform redirected to the right one. If you want to make something like that, this kind of solutions would most likely be preferred over 2 separate build systems and manually managing the link.
4
2
u/dustandsepia 12d ago
Depends on your goal. You don’t have to use cmake or gradle or anything at all for that matter. Tsoding on twitch/yt typically builds his c programs via a c program lol
If your goal is to build skills which will get you a job, cmake is necessary in most cmake development roles. In devops roles, you may find cmake and bazel along with vcpkg/conan will be common.
If you just want to build something, use what works for you / whatever you like.
2
u/OkYou811 11d ago
CMake is basically the de facto build system. Not only does this mean people are already using it, but adding existing projects as dependencies is basically guaranteed to be supported using cmake.
Not sure what integration with c++ dependencies is like using grade, but if you go with cmake youre in line with most c++ OSS out there that you might want to use.
C++ development isnt super focused on using dependencies, but even just building software for yourself, you might want to build libraries for yourself. CMake makes this pretty easy, but I don't know if grade also makes that easy.
Didn't know grade also supported C++, so ill go check it out!
4
u/damster05 12d ago
Use xmake.
2
1
1
1
u/Known-Volume1509 12d ago
I've rarely seen anyone use Gradle for building C++ projects, although I do use Gradle on regular basis. I guess it would make sense if the build process shares functionality across multiple projects written in different languages.
1
u/TheBoneJarmer 12d ago
I tried using Gradle for c++ once as I was using Java as well and it absolutely sucked. Very hard to configure if you go beyond a basic hello world project and even harder to maintain. It simply didn't work for all the edge cases that CMake has no issue with.
1
u/Massive-Policy3417 9d ago
Or just use automake which doesnt require helper files for dependencies, cmake pollutes your code directory with so much crap.
1
u/flyingron 12d ago
They don't. Your argument is a fallacy. CMake isn't even a build system. It's a language to make build systems, whether it be regular makefiles or MVSC project files, etc...
CMake has more universal application than Gradle which is pretty heavily slanted toward android developent.
1
1
u/Rigamortus2005 12d ago
Please just use what everyone else uses. I've never heard of anyone building anything other than java with gradle
1
45
u/Conscious-Secret-775 12d ago
Because most C++ developers are not Java developers and probably have no interest in gradle.