11 ms·
Allowing CMake functions to return(value)
- rumanator 6y ago> Most part of my career I used Visual Studio and when switched to Linux I was slightly shocked. Compared to MSVS, makefiles felt like bows and arrows against machine gun. I honesty have no idea how some people come up with these absurd comparisons. I mean, who in their right mind feel is appropriate to compare a Makefile with a build system? And how clueless about things are "in the Linux world" do you need to be to claim that Makefiles are how people build software in Linux? I mean, I've been using Linux for a couple of decades now and I can't remember the last time I saw a project that relied on Makefiles to build. At best projects use some kind of Makefile generator. The ancient ones use autotools and even those are going the way of the dodo. > CMake allows us to handle almost all those things right except one - it doesn’t have return values This is a red flag. If you're hoping to write functions with cmake... You're doing it wrong. Very wrong. You add targets, and you add rules to the target. If you find yourself wanting to do anything other than this then you should take a step back and read a modern cmake tutorial again, because odds are you're doing it wrong.
- dlivingston 6y ago> I've been using Linux for a couple of decades now and I can't remember the last time I saw a project that relied on Makefiles to build. Makefiles, at least in my corner of the industry, are exceedingly common for projects with a build process of medium-to-low complexity.
- sebastos 6y agoLink to a free and open modern cmake tutorial?
- rumanator 6y agoYou can pretty much google for "modern cmake tutorial" to get a long list of tutorials on how to write target-based cmake projects.
- moonbug 6y agospoiler: they're all crap.
- nickez 6y agoAnd worse, they all achieve the same goal in different ways...
- mlvljr 6y agoNot to mention, target outdated ways of doing things with CMake (there is always 3-4 at least).
- MaxBarraclough 6y agoA great point. There should a single standard and well-documented way to do things. The documentation should be official, the user should not be expected to trawl the blogosphere and piece together the knowledge they need. There should be plenty of complete examples. Ideally the official Find... packages should not make use of deprecated CMake functionality, they should be actively maintained to follow the current best-practices, so that they can serve as examples of the right way to do it. As I rambled about in my longer comment yesterday, this kind of work shouldn't require you to think, it should just be an exercise in applying boring, samey, dependable boilerplate.
- sebastos 6y agohttps://cliutils.gitlab.io/modern-cmake/chapters/basics.html https://cliutils.gitlab.io/modern-cmake/chapters/basics.html ^ Is that a good one?
- 1ris 6y agoI would love to use makefiles and git submodules instead of this msbuild/nuget contraption. That would be way less sophisticated, but I would welcome it. msbuild seems like a good example of microsofts tendency to overengineer simple things. But sometimes its suprisingly simple. different build configuration are just strings stiched together like "x64|Debug", and then are are conditionals to that value. Msbuild it's kind of a CLR language, but you can't debug it. The xml sytax and the syntax you use in the attributes feels arkward but sometimes limited for no good reason. Is <Message Text="Backup files: @(Compile->'%(filename).bak')" /> what i would want, if I'm used to linq? No, not me. @ and % are not intuitive for me. I usually have to try out what works. Accessing members of objects is odd. Calling System.String.Format feels like I'm supposed to do it. Anything interesting has to be done with custom task, and these are hard to debug aswell. For example studio would unload the .dlls, so you have to close it every time. That thing feels like a classic turing tarpit. A very complicated turing tarpit. Then again, if your build should output a .nupkg, the whole infrastructure seems to be lacking. You are left alone doing things that seem like they should be part of a package manager. e.g. handling of the version number. The whole build system knows the build output, but you have to specify it by hand again, in a different file.
- deleted 6y ago[deleted]
- kazinator 6y ago> I can't remember the last time I saw a project that relied on Makefiles to build I don't know what GNU/Linux you're using, because in my experience, most packages going into a distro use make. Oh, and then there is that whole denominator in the GNU/Linux fraction that's built with GNU Make. Maybe you don't see Makefiles because you're relying on binary packages?
- jcelerier 6y ago> I don't know what GNU/Linux you're using, because in my experience, most packages going into a distro use make. no, they use autotools or cmake, which happens to generate makefiles. the package authors themselves definitely don't write any makefiles by hand except maybe for trivial packages (and frankly I'm not sure)
- kazinator 6y agoAutotools generate a Makefile project, and nothing but a Makefile project. All the buiding in the development cycle is done by typing "make". Autotools projects include a template makefile: Makefile.am. Make is not concealed in any way. Also note that not all Autotools-based projects use Automake. Using only Autoconf, with a hand-maintained Makefile, is a thing. The goal of Autotools is to produce a software distribution that doesn't require the end user to have Autotools. The end user has a shell to run the configure script, and that's it. If that works, they run "make". About the most sophisticated generation the user will see is that some Makefile.in template is passed through sed to substitute @@XYZ@@ variables.
- anand-bala 6y agoThis is true for Autotools projects, but isn't true for CMake, Bazel, Meson, and others. Let's take CMake for example, which is IMHO the most popular build tool: most modern CMake projects prefer to use the Ninja build system over Make. And coming back to Autotools, some of the largest Autotools projects (see the GNOME ecosystem) has been moving/moved to Meson, which can also be used to generate Ninja rules instead of Makefiles. CMake Generators: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html https://cmake.org/cmake/help/latest/manual/cmake-generators.... Meson: https://mesonbuild.com/ https://mesonbuild.com/ Bazel: https://bazel.build/ https://bazel.build/ GNOME and Meson: https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting
- bluGill 6y agoI use modern cmake as much as I can, but I often run into things that cmake cannot do without a function. Most of our custom code generation tools for example, cmake doesn't know how to turn them into c++ without a function (which is in turn a wrapper of add custom command /target I've gotten rid of several of our pre modern cmake functions, but more remain.
- jcelerier 6y ago> This is a red flag. If you're hoping to write functions with cmake... You're doing it wrong. Very wrong. You add targets, and you add rules to the target. If you find yourself wanting to do anything other than this then you should take a step back and read a modern cmake tutorial again, because odds are you're doing it wrong. so how do you propose to do code generation, parsing stuff like /etc/lsb_release to work around a bug for people building under ubuntu 16.04, or that kind of thing ?
- MaxBarraclough 6y agoA semi-relevant rant about CMake, for those interested in that kind of thing: The CMake scripting language is just awful. It breaks with convention to do things in its own unintuitive way. (Who though the endfunction() syntax was a good idea? Or the bizarre function-call syntax?) It's error-prone, it shows cryptic error-messages, it's able to break in subtle ways, much of the documentation is for deprecated functionality, and worst of all, it lacks a consistent design pattern. One shouldn't have to think when making a Find... CMake script so that CMake can find an installed package. It should be a very boring task of adapting existing boilerplate. But it's not so. It's an agonising uphill battle with this atrocious language. Subtle bugs like [0] wouldn't even be possible in a well-designed build-system, but CMake lets you shoot yourself in the foot as punishment for not knowing its every subtlety. It's unfortunate that CMake is the least bad build system we have. You should probably still use CMake for multi-platform code. You shouldn't expect people to learn some obscure rival build-system just to work on your code. I'll certainly continue using CMake for what little C++ I write myself. Once you've beaten your CMake scripts into submission (generally thanks to the extensive body of knowledge on StackOverflow, in my experience), CMake works a treat on a bunch of different platforms. It's just a pity the language is so terrible. [0] https://github.com/dankamongmen/notcurses/issues/711 https://github.com/dankamongmen/notcurses/issues/711
- Arnavion 6y ago>It's unfortunate that CMake is the least bad build system we have. You should probably still use CMake for multi-platform code. You shouldn't expect people to learn some obscure rival build-system just to work on your code. What little C I write I compile with Makefiles, but I've seen many new C projects on Github using meson. It look better than cmake at a glance, and at this point in time isn't obscure either.
- kabdib 6y agoThanks for the pointer to meson. Ten minutes into it and it's already far less broken than other build systems I've been test driving recently. I'm sure it will let me down soon, but so far ... :-) (My reaction to CMake's scripting language was unprintable).
- lalaland1125 6y agoI personally find it surprising that so many people are still stuck on old, outdated build systems like CMake. Modern alternatives like Bazel (https://bazel.build/ https://bazel.build/) are light years ahead.
- hoseja 6y agoRight now, CMake is being actively integrated into QtCreator and Visual Studio where they previously had their own bespoke defaults. It might be shit but it's also becoming more and more "standard" as one DSL you need for cross-platform builds, instead of fifteen xkcd-927 style.
- fluffy87 6y agoThe claim that CMake is the least worst C++ build system that we have is pure BS. In my last 3 professional C++ projects I’ve actually used Rust’s cargo tool as my build tool for C++ code. Infinitely better than CMake, plus you use Rust as your scripting language for your build system, which has great libraries for it like the cc crate, and pretty much a crate for whatever it is you want to build (eg ispc? no problem).
- Firecracker 6y agoFluffy, could I ask you to give a few more details about how you set this up? Sounds interesting!
- MaxBarraclough 6y agoDoes it support a variety of operating systems and IDEs, the way CMake does? Can it handle package-detection across all those platforms? CMake has a terrible scripting language, but its backends are very good. Being able to generate Unix makefiles when working from GNU/Linux, and then generate Visual Studio solution files when working on Windows, is pretty great.
- bob1029 6y agoI've given up on these sorts of build systems. If I ever had to screw with a C/C++ codebase again, I would just write my entire toolchain in C#. I know for a fact that modern C# 8.0+ will not bite me in the ass with inconsistent ideologies. I also have extreme confidence that I could add in complex build concerns such as communication with other systems for obtaining dependencies or logging important information.
- saghm 6y ago> CMake allows us to handle almost all those things right except one - it doesn’t have return values One of my former bosses once quipped "CMake is confusing until you realize it's just a shitty version of BASIC that only has global variables"
- earthboundkid 6y agoMakefiles combine the expressivity of Bash with the clarity of Bash.
- wyldfire 6y agoIs there a dialect of BASIC that has scoping/namespaces or even locals?
- AlphaSite 6y agoVisual Basic was ok from what I remember.
- s_gourichon 6y agoTechnically yes, also VB.net . Reminds me that old joke that any language can run on .Net runtime (a.k.a. CLR) as long as that language is C#. Somehow VB.net is kind of C# with VB syntax and some corners cut that they could not fit.
- amedvednikov 6y agoSo glad that new languages don't need build systems. go build .
- rfoo 6y agoI'm sure you can find people ranting about how their "xxx_windows.go" files got silently ignored by go build. Just like every part of Go, everything ugly is hidden and "just works" until it can't, and major WTF moments strikes after that.