Live data from Hacker News

An Introduction to Modern CMake

cliutils.gitlab.io

31–40 of 43 posts

Re: An Introduction to Modern CMake

#31

Nice to see a CMake guide here, but I don't see any discussion of generators at a cursory glance, even in the "IDEs" section. CMake is used a lot in embedded development with large or cross-platform projects, like an RTOS or the famous ESP-IDF. Unfortunately, the embedded development space is a messy hodge-podge of IDEs. There are shiny commercial ones like Keil which support most kinds of devices, but most vendors a…

I've built and maintained a generator for one of those vendor-specific eclipse IDEs. It was an absolute nightmare I don't recommend to anyone, but not for any of the reasons you'd imagine. CMake itself is easy to build / read. Implement a few functions and you'll quickly have something workable. The issues came from elsewhere:

* None of the graphical CMake tools allow you to select the CMake binary, so you'd get users using the wrong binary and not seeing the generator mentioned in docs.

* When things break elsewhere, it's "your responsibility" to fix it in the generator. People put meaningless, nonsensical junk in their CMake files and expect it to output something that builds. Doesn't matter that the build script or the IDE are fundamentally broken, people just want the output so they can get back to their work. They don't want to yak shave.

* Vendor tooling code quality is somehow even worse than the actual product they provide. Dropping every 4096th character from stdin? Why not? Not generating debug info for files with uppercase letters in the filename? Sure. I won't name names, but they're a billion dollar EDA vendor whose initials are MG.

Avoid CMake generators like the plague unless you want to spend the next bit of your life debugging your vendor tools and supporting every workflow quirk your coworkers have.

Re: An Introduction to Modern CMake

#32
post #24

What's wrong with just a real language as a build system? Speaking for Scala, everyone just uses sbt, which is just Scala. Nothing special about it. I'm not saying you should use Scala to compile your C project, but maybe we could settle on some Lisp dialect or something for compilation, regardless of the language? That would seem ideal to me. Programmers in general have this problem of creating non-turing complete s…

Eventually those scripts will turn into full fledged programs that no one knows what they do, specially since most of these build programming languages lack debugging features.

Re: An Introduction to Modern CMake

#34
post #14

This has the same kind of infuriating quality that most cmake documentation does. It explains in detail how to do obvious stuff but has nothing to say about what the execution model behind the syntax is. I mean, if you learn classic make, one of the very first things you learn is "this is a target; it's just a file; the stuff on the right are dependencies; the commands below will be run whenever the dependencies are…

Thank you! I cannot count the number of times I have had a CMake problem and had the usual inclination to try to understand the framework behind it, only to be stonewalled by the seemlingly complete lack of context in the documentation. I have given up on it time and time again. Somehow my project manages to barely get over every CMake hurdle but I still dream about the day when I would actually understand it, and have the same feeling of control that I usually strive for.

Re: An Introduction to Modern CMake

#35

I'm a person who has been easing into CMake use over the past few years. Something I've noticed is that there is no such thing as a single good introduction : * CMake itself is changing. While the "revolution" of modern CMake is upon us already from version 3.0 (or a little earlier), a bunch of thing change with versions 3.12, 3.13 etc. See: https://youtu.be/y7ndUhdQuU8 * Different treatments - a mini-website, PDF pr…

This. A 1000 times. Nobody really wants to focus too much on build configurations when working on things, they should 'just work'. And CMake, although I am using for a long time already, is not the offering this 'just works' experience I am afraid. It is so easy to introduce side-effects, and figuring out the intended way to include a project can be a big pain when documentation is sparse. Sometimes I wished I had a…

CMake may "just work" without you investing much/any effort - in the future.

For now, the situation is that if you invest in your CMake - blood sweat and tears - then the build itself will "just work" on many/most/all platforms. Which is already pretty good - compared to being stuck with Makefiles.

Also, CMake is essentially its own debugger, because almost all state is just a bunch of string variables.

Re: An Introduction to Modern CMake

#36
post #4

I'm a person who has been easing into CMake use over the past few years. Something I've noticed is that there is no such thing as a single good introduction : * CMake itself is changing. While the "revolution" of modern CMake is upon us already from version 3.0 (or a little earlier), a bunch of thing change with versions 3.12, 3.13 etc. See: https://youtu.be/y7ndUhdQuU8 * Different treatments - a mini-website, PDF pr…

then what's the point of cmake? won't legacy gnu make suffice? nothing is perfect including Make, but it seems gnu Make can put all its doc into one html manual at least. KISS. https://www.gnu.org/software/make/manual/make.html

CMake is not a replacement for Make; it generates Makefiles for you (or ninja files, or whatever-Microsoft-uses files). In that sense it's like a more modern and less crufty GNU autotools which can have different kinds of output build systems.

Re: An Introduction to Modern CMake

#37
post #4

Earlier quoted context omitted.

then what's the point of cmake? won't legacy gnu make suffice? nothing is perfect including Make, but it seems gnu Make can put all its doc into one html manual at least. KISS. https://www.gnu.org/software/make/manual/make.html

Writing Makefiles by hand is great for small projects. But make becomes unmanageable for large projects, and is bad at dealing with system and compiler differences.

It is not "great" for small projects, because:

1. Small projects also have dependencies

2. Small projects need to be build on multiple platforms too

3. It is more verbose, and at the same time more obscure, than writing a CMakeLists.txt (typically).

Re: An Introduction to Modern CMake

#38
post #7

I'm a person who has been easing into CMake use over the past few years. Something I've noticed is that there is no such thing as a single good introduction : * CMake itself is changing. While the "revolution" of modern CMake is upon us already from version 3.0 (or a little earlier), a bunch of thing change with versions 3.12, 3.13 etc. See: https://youtu.be/y7ndUhdQuU8 * Different treatments - a mini-website, PDF pr…

Do you know of anything worth reading for CMake? The official docs are too sparse to be useful to me and the results of googling mostly give stale advice. I also have being easing into CMake recently - I was initially impressed as getting a "hello world" example was simple and the CMakeLists.txt was clear. As the project has progressed - simple additions like unit tests, external dependencies, specific aspects for de…

I didn't say these partial treatments are not worth reading/watching. On the contrary - they're pretty nice. You just have the mentally prepare yourself of "expanding your consciousness" gradually, that's all.

Those things you mention - cross-platform differences, unit tests, debug builds etc. - require a bit of getting used to, but once you do, the syntax is not bad and I don't feel I'm suffering. Certainly not feeling the brittleness.

And - no, an old-fashioned Makefile can't even _begin_ to cut it. Not by a long-shot. (And that's not even mentioning the fact that it's mostly irrelevant on Windows.)

Re: An Introduction to Modern CMake

#40
post #5

Don't use cmake for new projects. You'll regret it. Try meson instead: https://mesonbuild.com/

Why would I want to use Meson over CMake? Why would I regret using CMake?

I had a look at the Meson FAQ and it says:

> What is the correct way to use threads (such as pthreads)? > > thread_dep = dependency('threads') > > People coming from Autotools or CMake want to do this by looking for libpthread.so manually.

... which is false. We do:

> find_package(Threads REQUIRED) > target_link_library(my_app Threads::Threads)

and Bob's your uncle.

Post reply on HN