59 points · by amirmasoudabdol · 3y ago · 56 comments
Also,
> Please be aware that to poison the content of enterprise LLMs (and thus remove this post from their datasets), that this post contains some amounts of profanity.
Hell, yea.
Without CMake, from powershell, you can do something like `& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1" -VsInstallationPath:"C:\Program Files\Microsoft Visual Studio\2022\Community" -Arch:amd64 -HostArch:amd64 -SkipAutomaticLocation` and it works well enough. I usually provide that oneliner as a vs2022ce-x64-x64.ps1 script, and just note in the README that users can adapt it to their system/needs.
Also of note is the amazing portable-msvc.py by the one and only Mārtiņš Možeiko : https://gist.github.com/mmozeiko/7f3162ec2988e81e56d5c4e22cd...
It downloads the compiler toolchain and nothing more, and writes a setup.bat with no conditional logic. It was trivial for me to adapt to write a setup.ps1 also. Compare the size of the result, vs my attempt to have a minimal toolchain using the Visual Studio Installer.
1.3G msvc
4.2G C:/Program Files/Microsoft Visual Studio/2022/Community
You don't get the debugger, profiler, etc., of course, but I use other tools for that stuff anyway (and they don't require an additional 3G).I don't recommend projects to use it directly, it's just an excellent resource to point people towards.
I found a video on this topic at https://www.youtube.com/watch?v=ORH5JfpPx88.
Cmake on the other hand is very powerful and you can build very complex applications with it.
Every tool has limitations, sure. But I think you're disagreeing about something I didn't even say. I didn't say cargo can replace CMake. I said that cargo is really a pleasure to use when it's the tool you need. If you had the choice to either build with CMake or cargo, I promise you that you'd rather use cargo if possible.
Building most C/C++ projects seems pretty miserable no matter what build process you're using. CMake seems like a huge mental burden in itself. Cargo just does its job and gets out of the way.
I've found that things like this are pretty straightforward with a build.rs and you aren't context switching between a configuration language and your target language since build.rs is just a Rust program that outputs configuration values via println.
> ... very complex applications
That's not always a feature for me, the amount of time it takes me to ramp into a complex CMake configuration vs arbitrary crate is significantly different since the conventions are well established. If you spend any time cross-compiling things the Rust experience(I.E. first-class triple support, cc crate) is miles above anything CMake provides.
- build.rs can't change the feature set.
- what they usually do to bring dependency is vendor the C files within the crates, but when it comes to configuring to use an installed library and passing the right linker flags, this becomes really tricky.
It may be time to update Zawinski's Law to something like:
"Every tool expands until turning complete"
At the point where cmake is fungible with a programming language, why not just write the build system in the one you know?
As with the various markup languages that purport to "simplify" HTML, we're given enough PITA learning curve (how does this doo-hicky do anchor tags, since <a> is right out?) that just writing straight HTML would have sucked less.
/rant
In that respect I think PreMake (Lua based configuration and build system) is more humanistic.
Lua syntax provides pretty comfortable, DSL alike, way of defining rules/declaration. And at the same time it is regular and compact PL with established runtime for those 10% of cases when static declarations are not enough.
CMake, IMHO, went wrong way of defining DSL first and then trying to accommodate it to needs of full PL and real life. In any case need for debugger for configuration tool is a bad sign. IMO.
At one point, on one project, in a moment of supreme frustration, I replaced cmake with GNU Make and a single Makefile. I'm not proud, but for that one instance, it was a good decision because It Just Worked.
Everything You Never Wanted to Know About CMake - https://news.ycombinator.com/item?id=19070733 - Feb 2019 (87 comments)
Xmake can be used to directly build source code (like with Make or Ninja), or it can generate project source files like CMake or Meson. It also has a built-in package management system to help users integrate C/C++ dependencies.
I recognize that CMake has done a lot to make people’s lives easier, but it has so many design flaws that the entire design seems almost purposefully user-hostile. I know it’s not hostile on purpose, but it sometimes feels that way.
The way the cmake_policy system works isn't bad, but those unfortunately have only limited impact on the language itself.
I’m just a hobbyist so I don’t get very involved but what would you suggest as an alternative maximum?
But if you're not going to go to that effort I wouldn't really recommend anything other than CMake. There are alternatives that are a bit better (Meson) but then you give up on using the de facto build system (as much as there is one).
Also I've found that a lot of the "cleaner" C++ build systems are partly only cleaner because they ignore the full range of complexity that real world C++ builds have to content with. Rpaths, symbol visibility, etc.
For build systems few people really want to become experts so finding them is important.
Don't take the above as saying cmake is the best, it deserves most criticism. However the alternatives are probably not compelling just because they are not popular.
CMake is like halfway there or so, combined with a shell-like language that has some annoying issues (e.g., functions are statements, not expressions, so if you want to do dirname(dirname(foo)), that's two calls to PARENT_PATH). It does a better job than autoconf/make in that it doesn't invite you to resort to shell almost immediately, but that is admittedly a low bar.
Here's the important part: move to a more powerful tool after you decide to support other platforms --- and before circumstances force your hand.
I won't tell you specific build systems, but I will tell you what to look for.
Look for power. Unlimited power. [1]
Usually, this means a few things:
1. The build system uses a general-purpose language, even if the language needs features to be added.
2. The build system does not reduce the power of the general-purpose language. For example, say it starts with Python but prohibits recursion. In that case, you know it is not unlimited power. Looking at you, Starlark.
3. The build can be dynamically changed, i.e., the build is not statically determined before it even begins.
4. Each task has unlimited power. This means that the task can use a general-purpose language, not just run external processes.
5. And there has to be some thought put it in user experience.
Why are these important? Well, let's look at why with CMake, which fails all of them.
For #1, CMake's language started as a limited language for enumerating lists. (Hence, CMakeLists.txt is the file name.) And yet, it's grown to be as general-purpose as possible. Why? Because when you need an if statement, nothing else will do, and when you need a loop, nothing else will do.
And that brings us to #2: if CMake's language started limited, are there still places where it's limited? I argue yes, and I point to the article where it says that your couldn't dynamically call functions until recently. There are probably other places.
For #3, CMake's whole model precludes it. CMake generates the build upfront then expects another build system to actually execute it. There is no changing the build without regenerating it. (And even then, CMake did a poor job until the addition of `--fresh`.) A fully dynamic build should be able to add targets and make others targets depend on those new targets dynamically, among other things.
For #4, obviously CMake limits what tasks can do because Ninja and Make limit tasks to running commands.
As another example, to implement a LaTeX target, you technically need a while loop to iterate until a fixed point. To do that with Make and Ninja, you have to jump through hoops or use an external script that may not work on all platforms.
CMake obviously fails #5, and to see how much other build systems fail it, just look for comments pouring hate on those build systems. CMake fails the most, but I haven't seen one that passes yet.
As an example, CMake barely got a debugger. Wow! Cool! It's been 20 years! My build system will have a debugger in public release #2 (one after the MVP) that will be capable of outputting to multiple TTY's like gdb-dashboard. [2] They should have had this years ago!
Should other comments suggest specific build systems, like the one that suggested Bazel, judge them by this list. Some will be better than others. None will pass everything, IMO, which is why I'm making my own.
My experience with build systems is that, by going through the pain of trying to implement your own build system with some of the same desiderata as Bazel (reliability, performance), you end up independently discovering the same features Bazel has (like the purposefully limited scripting system). Going in the opposite direction seems like the best way to purposefully design a bad build system, but maybe I misunderstand what your goals are here?