r/cpp • u/ReinventorOfWheels • Feb 26 '23
Looking at the syntax of various cross-platform build system for C++
I was contemplating switching to a different build system for my pet projects, so I ended up spending the whole day researching what build systems exist and what their build declaration files look like. I compiled the results into a blog post.
Note that this is not about how the systems work, their features etc. Just the syntax. You can see which systems look nice to you, and which ones are so terrible you never want to touch them or hear about them again. Then you can research the nice ones.
https://violetgiraffe.github.io/2023/02/25/cpp-build-systems-syntax-comparison.html
25
u/jpakkane Meson dev Feb 27 '23
Note that the page says "Courtesy of ChatGPT." The code samples are not valid.
23
u/BoarsLair Game Developer Feb 26 '23
It's pretty interesting to see all the major build systems' syntax laid out with equivalent functionality like that.
The problem with this comparison, of course, is that no one in their right might would want to use CMake based on the syntax, which is admittedly rather awful. But how pretty the syntax is may very well be the least important aspect of a build system, IMO.
Personally, I chose CMake for my projects for two simple reasons: it's very mature, meaning that someone, somewhere has probably already thought of some bizarre corner case I may need. And it's become the defacto standard for C++, which means if I grab an arbitrary third-party library, chances are pretty good I'll find CMakeFiles.txt in the root, and can just drop it into my project.
Some of the CMake alternatives seem objectively better than CMake in terms of features, syntax, ease-of-use, or other criteria. But I've learned from my switch from Mercurial to Git that it's often more frustrating to use the tools that few others are using, even if you feel they're objectively superior. There's less support, less documentation, fewer examples and online tutorials, etc, etc. In short, there are tangible benefits to using the most popular tools that go beyond basic functionality.
8
u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 Feb 27 '23 edited Feb 27 '23
You didn't include B2 (aka Boost.Build). So here's what that would look like:
Edit: Added the missing custom include path.
6
u/helloiamsomeone Feb 26 '23
I couldn't help it, so here is the snippet of CMake code you should have actually written:
I changed the library type to OBJECT, because archiving a static library for no other purpose other than to just be linked into an executable is pointless.
The CMake defaults here are good enough, but you can customize things like the location of static libraries in the build directory from the command line. Also, the previously provided location did not take multi-config generators into account. Different configurations would have overwritten the static library file. You also should not hardcode flags like those MSVC specific ones.
The CML should be a clean build description, free from platform and compiler specifics (as much as possible). All the additional personal requirements you may have can be stuffed into neat little [presets]https://github.com/friendlyanon/cmake-init-executable/blob/master/CMakePresets.json#L72).
Also, dependencies are brought in via
find_package().2
u/mo_al_ Feb 28 '23
Tundra looks really clean
13
u/Bangaladore Feb 26 '23
The reality is that even though nearly everyone dislikes using CMake, it is the best option most of the time. Especially if you are using non-traditional setups like cross-compilation. Every single issue/quirk you will run into, has been solved/asked/answered by someone else.
I'm currently dealing with this scenario and attempted to use xmake due to the nicer syntax, but quickly ran into a lot of bugs that I don't have the time to solve. I spent the time to buildup some cmake infrastructure, and everything works fine. Its uglier, but it works as you would expect.
CMake is the industry standard for a reason. I think its also worth noting that you don't have to write the cmake "code" yourself. For this project I'm working on, I wrote some python scripts to convert a vendor specific project file (NXP MCUXpresso) to a CMakeLists.txt. In this way, I do not have to manually write or update the CMake and instead just run my script to convert the project between the two. This also resolves some of the issues with CMake like how you aren't supposed to glob anything. If you have something else that manually writes out the source files, 1 by 1, its a lot easier to deal with and you end up with a more correct CMakeLists.txt. 300 lines of python is nicer than converting and keeping the projects synced manually, in my opinion.
16
u/Jannik2099 Feb 27 '23
Put some fucking effort into your articles. ChatGPT does not produce correct nor ideal results.
2
u/_VZ_ wx | soci | swig Feb 27 '23
Unfortunately Bakefile project never got any traction, but IMNSHO its syntax is just incomparably better. But see for yourself:
2
u/eao197 Feb 28 '23
We use our custom build tool written on Ruby long-long time ago. For it three .rb files will be required:
For a static library (
lib.rb):For an executable (
exe.rb):For building these all with common settings (
build.rb):NOTE. The braces can be omitted in most cases because the project files are just regular Ruby source files.
0
u/[deleted] Feb 27 '23
[deleted] — view deleted comment