I have dabbled in cmake for years. I can usually get what I need working by googling for examples but I really don’t have any idea how cmake works. I was wondering if there is any document that describes the architecture of cmake and how it works. I see lots of documentation about the details, but I can’t find anything about the basics. Am I missing something?
The best reads, all from the CMake documentation, would probably be…
- cmake-buildsystem(7)
- cmake-language(7)
- The Using Dependencies Guide
- The Importing and Exporting Guide
- The
find_package
command documentation, which was fleshed out in 3.24 to give a much more complete picture of the package discovery process (in combination with the new-as-of-3.17 Using Dependencies Guide).
And, not from the docs:
- The now-classic Introduction to Modern CMake, a paradigm shift in how CMake users think about dependency inputs and project outputs. (Basically, targets targets targets! Imported and exported.)
- Might also be of some interest: The CMake chapter of The Architecture of Open Source Applications (Volume 1) — the thing is, though, the book was published in 2011 so it’s crazy outdated by now.
But beyond that, your best bet is probably reading the source. Whether it’s:
- the standard modules distributed with CMake (for examples of how to use the CMake language)
- the C++ source code to learn how various features are implemented behind-the-scenes.
(The modules source can also be found with your installation of CMake, in the Modules
directory of the install. They’re found in /usr/share/cmake/Modules/
on most Linux systems, for example.)
I know there are also commercial books written on CMake: There’s @bill.hoffman’s own Mastering CMake, or the recently-published Modern CMake for C++, but I haven’t personally read any of those.
(Edit: Added a few more.)
1 Like