Live data from Hacker News

An Introduction to Modern CMake

cliutils.gitlab.io

11–20 of 43 posts

Re: An Introduction to Modern CMake

#12
post #8
post #5

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

Unfortunately even if you're starting a new project chances are that your dependencies are using cmake and they expect their dependencies to use cmake... in the end of the day you spend a lot of time fixing the upstream projects build files. More than that CMake at this point is the ""standard"" and there are many others with a similar share of the market and selling points, it makes it harder to pick one that is not…

If your dependencies use CMake or not doesn't really matter, you still end up writing some FindX.cmake file.

(Which is a whole other thing with this "modern CMake" by the way: only half of them that come with CMake are "upgraded" to modern and if you don't want to require the absolute latest version, you end up having to check what the FindX script did or redefine stuff manually)

Re: An Introduction to Modern CMake

#13
post #5

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

Doesn't meson bring in all of python3 as a dependency for a project? Similar to scons.

(It's been a while since I did semi-serious C++, maybe nowadays we're playing a bit more loose with deps and polyglot setups)

Re: An Introduction to Modern CMake

#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 newer than the target". Now, there are implications to learn, but that is the model, and it's obvious: make runs programs to create files when the stuff needed to create the file changes.

Now, how do I do that in cmake? It's almost not even here! It's all about C++ files and libraries and how to define variables and write functions and include other cmake files. But what is it going to do with that stuff? It's all just magic. Type it like this and it'll work. Cmake understands your compiler better than you do.

What docs there are on creating a custom target are buried in two paragraphs inside a subsection named "Running a command at build time". And it barely tells you how to do this at all (this being a topic I've actually struggled with in the past). In particular it fails to mention that a target is is not the same thing as a file in cmake, and that this has implications that are likely to be surprising to make experts.

Re: An Introduction to Modern CMake

#15
Excerpt:

"The --trace option will print every line of CMake that is run. Since this is very verbose, CMake 3.7 added --trace-source="filename", which will print out every executed line of just the file you are interested in when it runs. If you select the name of the file you are interested in debugging (usually by selecting the parent directory when debugging a CMakeLists.txt, since all of those have the same name), you can just see the lines that run in that file. Very useful!"

Re: An Introduction to Modern CMake

#16
Recent versions of CMake have also been growing the support for CUDA. There's still a number of edge cases (e.g. passing arguments to the device linker) that have open tickets on their bugtracker, but there's more than enough stable functionality now for CUDA projects and generally a number of relevant improvements with each new release.

We started using it about 6 months ago for a cross platform CUDA project, and have found it to be a big improvement over how we previously managed similar CUDA projects (e.g. manually). I'm especially a fan of it's ability to download external CMake project dependencies. As others have mentioned, some of the documentation is a little unclear for particular edge cases though so it takes some familiarisation.

Re: An Introduction to Modern CMake

#17
post #5

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

I will consider it when QtCreator, Visual Studio, Eclipse CDT, Clion give the same support as they offer currently for CMake based projects.

Re: An Introduction to Modern CMake

#18

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…

Not sure you want to tie yourself to a buggy inconsistent IDE and force that upon all developers.

Why wouldn't you do it with CMakes internal logic? Isn't that the point, especially since it is cross-platform.

Re: An Introduction to Modern CMake

#19
post #18

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…

Not sure you want to tie yourself to a buggy inconsistent IDE and force that upon all developers. Why wouldn't you do it with CMakes internal logic? Isn't that the point, especially since it is cross-platform.

I don't think I understand the question. Generators are CMake's way of creating IDE-specific build files, and I wish that people used them instead of writing their own scripts to create IDE-specific build files from CMake.

Generators are there so that you don't get tied to any one IDE; you select a different generator when you want to use a different IDE or compiler, but your CMake logic can largely stay the same besides that.

If I were a cynic, I would say that the vendors probably don't mind it being difficult to interoperate with their competitors' products, so there's little incentive to support things like that.

Re: An Introduction to Modern CMake

#20

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 debugger. And with modern CMake I feel like this got worse to some degree.

Post reply on HN