The Modern CMake for C++ code repository is a book with thirteen runnable chapters
Modern CMake for C++, published by Packt
At a glance
- What is it?
- Packt's Modern CMake for C++ ships its example code as a public repository, one folder per chapter, with a Docker image that pins CMake 3.20 and pulls in clang-tidy, cppcheck, valgrind, lcov and protobuf so the examples build the way the book describes. It is teaching content with a toolchain attached, not a framework you depend on.
- Who is it for?
- The Modern CMake for C++ repository suits a C++ developer who is working through the book and wants every example to compile with the exact toolchain the text describes, since the pinned image removes the setup work that usually makes a book hard to follow.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 6 months ago.
- What is it written in?
- Mainly Dockerfile, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
A companion repository, not a library
The repository exists to support a book. The README says it is the code repository for Modern CMake for C++, published by Packt, and everything else in it follows from that. The primary language is recorded as Dockerfile, which is an odd thing to see in a language field and is an accurate description of what this repository actually contains. The top level listing is a build environment and a folder of examples, with a Dockerfile, a Dockerfile.examples, a build.sh, a .bashrc, a .gitmodules, a LICENSE, a README.md and an examples/ directory. There is no library, no gem, no package, and nothing here to depend on. The book itself argues the problem in the What is this book about section, and the argument is worth taking seriously, because it explains why a code repository exists at all. Developers researching the subject have difficulty determining which advice is up to date and which approaches have already been replaced by easier and better practices, and most online resources offer limited explanation while lacking proper context and structure. The repository is the answer to that, since it lets the reader run the exact examples rather than reconstruct them from prose.
One folder per chapter, and a snippet small enough to read
The organisation is deliberately flat. All of the code is organized into folders, for example Chapter02, and the examples directory in the repository carries one subdirectory per chapter from chapter01 through chapter12, with the book covering chapters 1 to 13. The README shows what a listing looks like, and the example is a CMake function, which is a fair sample of the whole repository in six lines.
function(Inner)
message(" > Inner: ${V}")
set(V 3)
message(" < Inner: ${V}")
endfunction()This is the kind of code the book teaches. A function that prints on entry, sets a variable, prints on exit, and demonstrates the scoping rules that trip people up. The value of seeing it in a repository rather than in a book is that you can change it, break it deliberately, and watch what CMake does, which is the actual learning objective of a build system book. The chapters are numbered and shallow, so a reader who wants the dependency management chapters can jump to the chapter that covers it without wading through the earlier chapters, and the example files also include a .sass-like build.sh at the root that presumably drives the whole tree.
The Docker image is the real deliverable for a learner
The Dockerfile is the part of this repository that does the most work, and it explains the software list in the README. It starts from ubuntu:latest and installs a specific set of tools in one layer: the certificate, vim, tree, wget and git packages, lcov and gawk, g++ and make, then pkg-config, clang-tidy, clang-format, valgrind, doxygen, graphviz and cppcheck, and finally protobuf-compiler with the protobuf and libpqxx development headers. The list is not arbitrary. clang-tidy and cppcheck are static analysis, valgrind is dynamic analysis, lcov is coverage, clang-format is formatting, and the book promises to cover code quality guaranteed with the help of tests and static and dynamic analysis, so the tools are present so the examples can actually demonstrate them. The libpqxx and protobuf packages are there for the chapters that need a database client and a serialization format. Then CMake is installed by hand, at a pinned version.
ENV version=3.20.0
RUN cd /tmp && \
mkdir /opt/cmake && \
wget https://github.com/Kitware/CMake/releases/download/v$version/cmake-$version-Linux-x86_64.sh && \
chmod a+x ./cmake-$version-Linux-x86_64.sh && \
./cmake-$version-Linux-x86_64.sh --prefix=/opt/cmake --skip-license && \
rm cmake-$version-Linux-x86_64.shThe last line symlinks the installed binaries into the path, so cmake, ctest and cpack are available on the command line. Cpack and CTest matter because the book covers packaging and testing, and the errata list even includes a confusion between the two at page 395, which is the sort of thing you only notice when you have actually run them.
The errata list is the most useful page in the repository
A book that has shipped has errors, and this README publishes them in detail, which is rarer than it should be. The list runs to around twenty entries and they are specific. At page 46 the description of multiline comments is wrong about the symbol, since they start with an # and an opening square bracket rather than just an opening square bracket. At page 75 a function name is given as main() where it should be endmacro(). At page 107 test_run() should be try_run(). At page 137 generation expression should be generator expression. At page 195 a path to a source file is corrected to a path to a CMakeLists.txt, which is the kind of mistake that would cost a reader an hour. At page 198 a shared library declaration is corrected to one without the SHARED keyword. At page 208 a FindPkgConfig heading has a stray zero appended. At page 213 two possible library variable names are corrected to one. At page 222 a comment refers to a mind-module where it should say find-module, and the sentinel variable for a missing library is corrected. At page 354 install(FILES) should be configure_package_config_file. At page 395 CPack should be CTest. Two of these are not typos but factual corrections about which tool does what, which is the sort of thing the book is trying to teach in the first place, and finding that a book about packaging mislabels a command is exactly the kind of detail that makes you trust the rest of it less. The README also notes that a PDF with the colour images of the screenshots and diagrams is available separately, and there is a free PDF download for people who have already bought the print or Kindle version.
Who the book is for, and what it deliberately leaves out
The audience is stated precisely. The book is for build engineers and software developers with knowledge of C or C++ programming who are looking to learn CMake to automate the process of building small and large software solutions, and the README names three kinds of reader: someone just getting started with CMake, a long time GNU Make user, or someone simply looking to brush up on the latest best practices. The feature list gives the shape of the coverage, with best practices for building C++ code, practical knowledge of the CMake language focused on the most useful aspects, tooling for code quality through tests and static and dynamic analysis, managing discovering downloading and linking dependencies with CMake, building solutions that can be reused and maintained in the long term, and optimising both the build artefacts and the build process itself. What is not promised is as important. There is no promise of a complete CMake reference, and the phrase focusing on the most useful aspects is the author's way of saying the book skips what a working project rarely needs. The software list is one line, CMake 3.20, on Windows, macOS or Linux, and it covers all thirteen chapters, which is a low bar for a reader and a low bar for the code.
How this differs from the official CMake tutorials and from a project template
The obvious comparison is with the official CMake tutorial documentation, and the difference in approach is mostly about selection and framing. The official documentation is organised around the reference manual and every command, which is the right shape for looking something up and the wrong shape for learning a way of working. This book is organised around decisions, and the repository is organised around running the decisions, so the reader is not asked to invent a project to try an idea in. The second comparison is with a project template, and this repository is not that. A template is a starting point you copy, with sensible defaults and no narrative. Here the code is organised by chapter, the numbering carries meaning, and the earlier chapters are not prerequisites for the later ones in the way a template's structure is. What a reader gets that a template cannot give is the reasoning, since the code exists to make a point and the point is usually about why a build file is shaped a certain way. The cost is that you cannot lift a folder out of this repository and use it in production without stripping out the teaching structure, which is a fair price for a repository that is meant to be read rather than depended on. The licence is MIT, so the code can be reused freely with attribution, and the last push was on 2026-04-22, which for a book repository means the examples are stable rather than frequently revised.
Editorial conclusion
The Modern CMake for C++ repository suits a C++ developer who is working through the book and wants every example to compile with the exact toolchain the text describes, since the pinned image removes the setup work that usually makes a book hard to follow. It is the wrong tool if you are looking for a reusable CMake project template, because the code is organised by chapter rather than by reusable module, and the wrong tool if your project needs a different CMake version, since the image pins 3.20. Before you build the image, check the errata list in the README, which records around twenty corrections including wrong function names and an incorrect file path, and read the software and hardware table, which asks for CMake 3.20 on Windows, macOS or Linux for chapters 1 to 13.
Frequently asked questions
What is in the Modern CMake for C++ code repository?
The code for the book, organized into one folder per chapter, with the examples directory carrying chapter01 through chapter12. There is also a Dockerfile and a Dockerfile.examples, a build.sh, a .gitmodules, a .bashrc and a LICENSE, with the primary language recorded as Dockerfile.
What do I need to run the examples in Modern CMake for C++?
The README's software and hardware list asks for CMake 3.20 on Windows, macOS or Linux, and says that with it you can run all the code files present in the book for chapters 1 to 13. The Dockerfile pins CMake 3.20.0 and also installs clang-tidy, clang-format, cppcheck, valgrind, lcov, doxygen, graphviz, protobuf and libpqxx.
Does the Modern CMake for C++ repository contain corrections to the book?
Yes. The README has an Errata section listing around twenty corrections with page and line references, including main() that should be endmacro(), test_run() that should be try_run(), generation expression that should be generator expression, a source file path corrected to a CMakeLists.txt, and CPack that should be CTest.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/packtpublishing-modern-cmake-for-cpp)Was this useful?