If you’ve landed on this search phrase — “cmake cookbook pdf github work” — you’re likely a developer who learns by doing. You want more than just theory. You want recipes. You want downloadable code. You want integration with GitHub, and you want a PDF you can consult offline.
This article is your one-stop resource. We’ll explore:
The "CMake Cookbook" is a vital tool in a C++ developer's arsenal. To utilize it properly:
By combining the explanatory power of the book with the functional code on GitHub, developers can move from fighting their build system to mastering it.
The keyword “github work” reflects a critical reality: CMake is learned best by doing. The cookbook’s companion code is hosted on GitHub, allowing you to:
Without the GitHub component, the PDF is just theory. With it, you have a hands-on laboratory.
Abstract This paper presents a practical, example-driven "CMake Cookbook" focused on writing, organizing, and distributing CMake-based builds, producing PDFs (documentation), and integrating projects with GitHub. It covers core CMake patterns, modern best practices, cross-platform concerns, packaging, CI, and documentation generation (including producing PDF artifacts). Examples are provided throughout; code snippets are complete and ready to copy.
Contents
Introduction and goals
CMake fundamentals and project layout
Common cookbook recipes
Advanced recipes
Documentation and PDF generation
GitHub integration
Example projects (minimal, library, app, monorepo)
CI pipelines and publishing PDFs to GitHub Releases
Appendix: Useful CMake idioms and reference snippets
Introduction and goals
cmake_minimum_required(VERSION 3.24)
project(myproj VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)
3.1 Building libraries and executables
# src/CMakeLists.txt
add_library(mylib SHARED
lib.cpp
lib.hpp
)
target_include_directories(mylib PUBLIC
$<BUILD_INTERFACE:$CMAKE_CURRENT_SOURCE_DIR/../include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(mylib PUBLIC cxx_std_17)
add_executable(myapp app.cpp)
target_link_libraries(myapp PRIVATE mylib)
3.2 Header-only libraries
add_library(myheader INTERFACE)
target_include_directories(myheader INTERFACE
$<BUILD_INTERFACE:$CMAKE_CURRENT_SOURCE_DIR/../include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(myheader INTERFACE cxx_std_17)
3.3 Interface and modern targets
add_library(project_core INTERFACE)
target_compile_features(project_core INTERFACE cxx_std_17)
target_compile_options(project_core INTERFACE
-Wall -Wextra -Wpedantic
)
target_include_directories(project_core INTERFACE $CMAKE_CURRENT_SOURCE_DIR/../include)
Then link with target_link_libraries(mytarget PRIVATE project_core) or INTERFACE as appropriate.
3.4 Conditional compilation and options
option(BUILD_TESTS "Build unit tests" ON)
option(ENABLE_SANITIZERS "Enable ASAN/UBSAN" OFF)
if(ENABLE_SANITIZERS)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(myapp PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer)
target_link_options(myapp PRIVATE -fsanitize=address,undefined)
endif()
endif()
3.5 External dependencies
Example: FetchContent for GoogleTest
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
FetchContent_MakeAvailable(googletest)
add_executable(unit_tests test.cpp)
target_link_libraries(unit_tests PRIVATE GTest::gtest_main mylib)
include(GoogleTest)
gtest_discover_tests(unit_tests)
3.6 Tests and CTest
enable_testing()
add_test(NAME my_test COMMAND unit_tests)
3.7 Installing and packaging (CPack)
install(TARGETS mylib myapp
EXPORT myprojTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
)
install(DIRECTORY $PROJECT_SOURCE_DIR/include/ DESTINATION include)
install(EXPORT myprojTargets
FILE myprojTargets.cmake
NAMESPACE myproj::
DESTINATION lib/cmake/myproj
)
include(CPack)
set(CPACK_PACKAGE_NAME "myproj")
set(CPACK_PACKAGE_VERSION $PROJECT_VERSION)
4.1 Out-of-source and multi-configuration
4.2 Cross-compilation basics
# toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER /path/to/arm-gcc)
set(CMAKE_CXX_COMPILER /path/to/arm-g++)
Invoke: cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake
4.3 Custom commands and generated code Example: run code generator to produce a header and link it into build
add_custom_command(
OUTPUT $CMAKE_CURRENT_BINARY_DIR/generated.hpp
COMMAND $CMAKE_CURRENT_SOURCE_DIR/tools/gen_header.py
ARGS -o $CMAKE_CURRENT_BINARY_DIR/generated.hpp
DEPENDS $CMAKE_CURRENT_SOURCE_DIR/tools/gen_header.py
COMMENT "Generating header"
)
add_custom_target(generate_headers DEPENDS $CMAKE_CURRENT_BINARY_DIR/generated.hpp)
add_library(genlib $CMAKE_CURRENT_BINARY_DIR/generated.cpp)
add_dependencies(genlib generate_headers)
target_include_directories(genlib PRIVATE $CMAKE_CURRENT_BINARY_DIR)
4.4 Handling generated headers and parallel builds
5.1 Doxygen + Sphinx + Breathe
find_package(Doxygen REQUIRED)
set(DOXYGEN_IN $CMAKE_CURRENT_SOURCE_DIR/docs/Doxyfile.in)
set(DOXYGEN_OUT $CMAKE_CURRENT_BINARY_DIR/Doxyfile)
configure_file($DOXYGEN_IN $DOXYGEN_OUT @ONLY)
add_custom_target(doc_doxygen ALL
COMMAND $DOXYGEN_EXECUTABLE $DOXYGEN_OUT
WORKING_DIRECTORY $CMAKE_CURRENT_BINARY_DIR
COMMENT "Generating API docs with Doxygen"
VERBATIM)
Doxyfile.in: set GENERATE_XML = YES and XML_OUTPUT = xml
Sphinx project setup (docs/):
Build Sphinx HTML and LaTeX:
5.2 Producing PDF via Sphinx (recommended)
add_custom_target(doc_pdf
COMMAND $SPHINX_EXECUTABLE -b latex $CMAKE_SOURCE_DIR/docs $CMAKE_BINARY_DIR/docs/_build/latex
COMMAND $CMAKE_COMMAND -E chdir $CMAKE_BINARY_DIR/docs/_build/latex $MAKE_PROGRAM all-pdf
DEPENDS doc_doxygen
WORKING_DIRECTORY $CMAKE_BINARY_DIR
)
5.3 Doxygen direct LaTeX -> PDF
5.4 Integrating docs into CMake and CI
6.1 Repo structure and .gitignore
/build/
/*.cmake
CMakeCache.txt
CMakeFiles/
Makefile
*.mk
6.2 GitHub Actions: build, test, docs, package
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
build-type: [Debug, Release]
compiler: [gcc, clang]
steps:
- uses: actions/checkout@v4
- uses: lukka/get-cmake@v4
- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=$ matrix.build-type
- name: Build
run: cmake --build build --config $ matrix.build-type -- -j
- name: Test
run: ctest --test-dir build --output-on-failure
docs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install docs deps
run: pip install -r docs/requirements.txt
- name: Build docs PDF
run: |
sphinx-build -b latex docs/ build/docs/latex
make -C build/docs/latex all-pdf
- name: Upload PDF
uses: actions/upload-artifact@v4
with:
name: docs-pdf
path: build/docs/latex/refman.pdf
6.3 Releasing with GitHub Releases and artifacts cmake cookbook pdf github work
6.4 Using GitHub Packages
6.5 Dependabot and PR workflows
7.1 Minimal C++ app
7.2 Library with tests and examples
7.3 Monorepo with subprojects
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"$CMAKE_CURRENT_BINARY_DIR/myprojConfigVersion.cmake"
VERSION $PROJECT_VERSION
COMPATIBILITY AnyNewerVersion
)
install(FILES $CMAKE_CURRENT_BINARY_DIR/myprojConfig.cmake
DESTINATION lib/cmake/myproj)
install(FILES $CMAKE_CURRENT_BINARY_DIR/myprojConfigVersion.cmake
DESTINATION lib/cmake/myproj)
# In install tree, create myprojConfig.cmake that includes myprojTargets.cmake
Practical tips and pitfalls
Concluding example: Full minimal repo (files)
If you want, I can:
Which of those would you like next?
This paper examines the practical application of modern CMake through the lens of the CMake Cookbook
by Radovan Bast and Roberto Di Remigio. It explores how the book's GitHub-hosted recipes address real-world build system challenges like portability, modularity, and multi-language support. Optimizing Build Workflows with the CMake Cookbook Abstract
As software grows in complexity, the need for cross-platform, modular build systems becomes critical. The CMake Cookbook
provides a repository of "recipes" to streamline this process. This paper discusses the integration of these recipes into professional development workflows, focusing on automation with CTest, CPack, and CDash. 1. Introduction to Modern CMake
Unlike legacy build tools, Modern CMake operates as a build system generator rather than a direct builder. The official GitHub repository for the Cookbook serves as a live resource for developers to implement:
Target-based builds: Moving away from global variables to scoped properties.
System Introspection: Automatically detecting operating systems, processors, and library versions. 2. Key Recipes and Methodologies
The Cookbook organizes techniques into actionable chapters that can be directly applied to complex projects:
Modularization: Strategies for refactoring large codebases into reusable modules.
Superbuild Pattern: Managing external dependencies by building them alongside the primary project.
Multi-language Support: Integrating C, C++, and Fortran within a single unified build process. 3. Practical Implementation via GitHub
The accompanying dev-cafe/cmake-cookbook repository allows researchers to test and verify recipes in a controlled environment. Key features include:
Docker Integration: Pre-configured environments to ensure build reproducibility.
Testing Infrastructure: Utilizing CTest for automated validation of software builds.
Packaging: Using CPack to generate platform-specific installers (e.g., DEB, RPM, ZIP). 4. Best Practices and Common Pitfalls
Drawing from the Cookbook and community consensus, professional-grade CMake should avoid:
Global Variables: Use target_link_libraries and target_include_directories to maintain scope.
File Globbing: Avoid file(GLOB) as it prevents CMake from detecting new files without a manual re-run. Conclusion
The CMake Cookbook and its GitHub resources provide a standardized framework for modernizing software builds. By adopting these modular, target-oriented recipes, developers can significantly reduce maintenance overhead and improve cross-platform reliability. References Bast, R., & Di Remigio, R. (2018). CMake Cookbook . Packt Publishing. CMake Cookbook GitHub Repository CMake Official Documentation dev-cafe/cmake-cookbook - GitHub
Finding a reliable, working PDF of the CMake Cookbook on GitHub can be a bit of a scavenger hunt. While many repositories host code samples from the book, finding the full text requires knowing where to look and how to use the materials effectively.
This guide covers how to find working resources for the CMake Cookbook on GitHub and how to actually use them to master modern C++ build systems. Why the "CMake Cookbook"?
Written by Ken Martin and Bill Hoffman (creators of CMake), this book is the gold standard for moving beyond basic add_executable commands. It focuses on real-world recipes for: Managing complex dependencies. Cross-platform compilation. Integrating testing frameworks like GoogleTest. Packaging software with CPack. Finding the "CMake Cookbook" on GitHub
When searching for "CMake Cookbook PDF GitHub work," you will likely encounter three types of repositories. Here is how to navigate them: 1. The Official Code Repository
The most "working" resource you’ll find is the official PacktPublishing/CMake-Cookbook repository.
What’s inside: Complete source code for every recipe in the book.
Why it matters: Even if you have a PDF, the PDF text is often outdated compared to the GitHub code, which receives community bug fixes for newer CMake versions. 2. Community Study Notes and Forked PDFs
Many developers upload their study notes or converted Markdown versions of the book. To find these:
Use the GitHub search bar with: CMake Cookbook extension:pdf.
Look for repositories with recent "commits." If a repo hasn't been touched in five years, the CMake syntax (likely 3.5 or older) might not work with modern CMake (3.20+). 3. The "Actions" Workaround
Some users host "GitBook" versions or rendered documentation sites on GitHub Pages. Searching for topic:cmake combined with cookbook often reveals hosted documentation that is easier to read than a raw PDF. How to Make the GitHub Code "Work"
If you’ve downloaded a PDF but the examples aren't compiling, follow this modern workflow to get them running: Step 1: Clone the Repo
Don't just download the ZIP. Clone it so you can track changes: git clone https://github.com cd CMake-Cookbook Use code with caution. Step 2: Use a Modern Generator Mastering CMake: The Ultimate Guide to Using the
The book often references older generators. For the best experience on Windows, Linux, or macOS, use Ninja: cmake -S . -B build -G Ninja cmake --build build Use code with caution. Step 3: Check Version Compatibility
If a recipe fails, check the cmake_minimum_required version at the top of the CMakeLists.txt. If you are using a PDF from a 2018 repo, you may need to update the syntax to support modern features like target_link_libraries with PUBLIC/PRIVATE keywords. Troubleshooting Common GitHub Issues
Missing Submodules: Some recipes depend on external libraries. If the code doesn't work, run git submodule update --init --recursive.
Broken Links: Many older GitHub "PDF" links are flagged for copyright or moved. If a link is dead, check the "Releases" section of the repository; sometimes the files are tucked away there.
The most effective way to use the CMake Cookbook via GitHub is to use the Official Code Repo as your primary source and treat the PDF as a conceptual guide. CMake evolves quickly; the code on GitHub is "alive," while a static PDF is a snapshot of the past.
The CMake Cookbook by Radovan Bast and Roberto Di Remigio is widely considered one of the best practical resources for mastering modern build automation. Unlike theoretical manuals, it uses a recipe-based approach to solve real-world problems, making it highly effective for developers moving beyond basic scripts. Where to Find the Work (GitHub & PDF)
Official Code Repository: The full collection of examples and recipes is available on the dev-cafe/cmake-cookbook GitHub. This is the most "helpful" way to use the book because you can run the code directly.
Publisher Repository: Packt Publishing's GitHub also hosts the code samples.
PDF Access: While unofficial PDF backups exist on GitHub, the official eBook is hosted on platforms like Packt and O'Reilly. Helpful Review & Key Highlights
The book is praised for bridging the gap between "getting it to work" and "doing it right" using Modern CMake (version 3.5+).
Modular Learning: Each chapter is self-contained. You can jump straight to Chapter 7 for structuring projects or Chapter 9 for mixed-language support (C++, Python, Fortran).
Cross-Platform Focus: It provides specific tips for detecting operating systems and processors to ensure your code builds anywhere.
Beyond Compiling: It covers the entire lifecycle, including testing with CTest, packaging with CPack, and dashboard integration with CDash.
Portability: A major strength is its guidance on refactoring large, legacy codebases into clean, modular CMake structures. Alternative Resources
If you find the Cookbook too dense, these are highly recommended alternatives:
The curated list of awesome CMake scripts, modules ... - GitHub
The CMake Cookbook (2018), authored by Radovan Bast and Roberto Di Remigio and published by Packt Publishing, is a popular resource for mastering modern CMake through task-based recipes. GitHub Repository & Source Code
The official code repository for the book's recipes is hosted on GitHub. You can find the source code, including examples for C, C++, and Fortran, at:
Official Recipe Repository (dev-cafe): This is the primary location for the latest updates and bug fixes for the book's examples.
Packt Publishing Mirror: A mirror repository managed by the publisher. PDF & Access Options
Official eBook/PDF: You can purchase and download the DRM-free PDF version directly from Packt.
Free PDF Offer: If you have already purchased a physical copy or a Kindle version, you may be eligible to claim a free PDF through Packt's offer link.
Online Reading: The full text is sometimes available to read for free on the Packt website for users who sign up for a trial. Core Topics Covered The book is structured into recipes that cover:
Environment Detection: Detecting OS, processors, and external libraries.
Build & Test: Configuring projects and running tests with CTest.
Project Structure: Refactoring codebases into modular projects and using the Superbuild pattern.
Packaging & Distribution: Using CPack for installers and packaging. CMake Cookbook, by Packt - GitHub
CMake Cookbook , authored by Radovan Bast and Roberto Di Remigio and published by Packt Publishing
, is widely regarded as a practical, recipe-based guide for developers needing to manage C++, C, and Fortran build systems. Book Overview & GitHub Resources
The book is structured into 15 chapters that progress from basic executables to complex multi-language projects and packaging. Official Repository : The source code for all recipes is hosted on GitHub at dev-cafe/cmake-cookbook Content Coverage : It covers the full "CMake family," including (testing), (packaging), and (dashboards). Key Topics
Detecting operating systems, processors, and external libraries. Managing project structures and the "Superbuild" pattern. Cross-compilation and building documentation with Doxygen. Porting existing projects to CMake. Review Highlights Practicality : Unlike a dry manual, it uses a recipe format
("How to do X..."), making it highly searchable for specific dev-ops tasks. Accessibility : It is designed for both beginners and long-time users looking to modernize their workflow. Code Quality
: The GitHub repository is well-maintained, allowing users to clone and run examples directly, which is crucial for verifying the logic in different environments. Modern Practices
: While published in 2018, it remains a core recommendation in curated lists of CMake resources due to its focus on portable and refactorable code. Finding the Work
The curated list of awesome CMake scripts, modules ... - GitHub
The CMake Cookbook is a highly regarded resource for developers looking to master modern build systems. While the physical book is published by Packt, many of its practical examples, recipes, and related community-driven "cookbooks" are hosted on GitHub, making it an interactive, evolving guide for C++ developers. What Makes the CMake Cookbook Effective?
The core strength of the CMake Cookbook is its modular approach. Instead of long, theoretical chapters, it uses "recipes" to solve specific engineering problems:
Portability & Detection: Strategies for detecting operating systems, libraries, and compilers.
Project Refactoring: How to break large, monolithic codebases into manageable CMake modules.
Dependency Management: Modern techniques like "Superbuilds" using ExternalProject_Add to manage open-source dependencies directly from Git.
Advanced Tooling: Integration of testing (CTest), packaging (CPack), and dashboard reporting (CDash). Finding High-Quality PDFs and Guides on GitHub What the CMake Cookbook is and why it’s essential
GitHub serves as a repository for both the official code and community-curated "Modern CMake" guides.
Official Code Repository: The packtpublishing/cmake-cookbook repository contains the complete code for all recipes featured in the book.
Community Versions: Many developers host supplemental PDFs and simplified versions. For example, the dev-cafe/cmake-cookbook is a collaborative effort that provides searchable recipes for tasks like organizing Fortran projects and limiting scope with add_subdirectory.
Modern Standards: Modern guides, such as the Modern CMake PDF, emphasize treating CMake code with the same quality standards as production code (version 3.0+). Core Recipes for a "Good" CMake Project
If you are writing your own article or setting up a project, focus on these "Golden Recipes" often found in these GitHub repos:
Version Enforcement: Always use cmake_minimum_required(VERSION 3.10...3.30) to ensure compatibility with modern features.
Target-Based Configuration: Avoid global variables. Use target_link_libraries and target_include_directories to define dependencies locally to a target.
Clean Builds: Utilize CMAKE_EXPORT_COMPILE_COMMANDS to generate a compile_commands.json file, which is essential for external tools like clang-tidy and cppcheck.
Custom Build Goals: Use add_custom_command and add_custom_target to automate tasks like generating source files at configure time.
Feature: Automated PDF Generation & Release via GitHub Actions
This feature allows a GitHub repository hosting the CMake Cookbook content (LaTeX, Markdown, or RST source) to automatically compile a professional-grade PDF and attach it to a GitHub Release whenever a new version tag is pushed.
Key Capabilities:
v1.0.0, the workflow automatically starts..md or .rst) into a unified PDF using CMake's build system (cmake --build . --target cookbook_pdf).CMake_Cookbook.pdf as a downloadable workflow artifact.) for the README.md showing the latest PDF build state.Why this feature is valuable for "CMake Cookbook PDF GitHub work":
CMake Cookbook (2018) by Radovan Bast and Roberto Di Remigio is a highly-regarded, recipe-based guide for developers working with C, C++, and Fortran. It is particularly effective for those who need to manage complex build systems or modernize existing ones. Core Review Summary
: The book uses a "recipe" format, where each section addresses a specific task—from basic executables to complex multi-language projects. Educational Value : Reviewers on
note it functions as both a cookbook and a structured tutorial, with recipes building on one another. Accessibility : A major highlight is the official GitHub repository
, which provides all the code examples, and a pre-configured Docker image that allows you to run recipes in minutes. Pros and Cons Modern Practices
: Focuses on "Modern CMake" rather than outdated scripting methods. Comprehensive Coverage
: Includes advanced topics like CPack for packaging, CTest for testing, and CDash for dashboards. Platform Support : Examples are tested across Linux, macOS, and Windows. Windows Limitations : Some users on
found certain Windows-specific instructions difficult to verify or follow. Learning Curve
: While it starts simple, it is primarily intended for intermediate developers; some beginners may find the lack of deep pedagogical context challenging in later chapters. Resource Links Official Code Repository : Access the source code for all 15 chapters on the Packt Publishing GitHub Alternative Code Repo : A mirrored version is maintained by the authors at dev-cafe/cmake-cookbook PDF Version
: While some unofficial PDF backups exist on GitHub, the official DRM-free PDF is available directly from Packt Publishing for those who have purchased a copy. for a particular platform or language? dev-cafe/cmake-cookbook - GitHub
Chapter 1: From a Simple Executable to Libraries. Chapter 7: Structuring Projects. Chapter 9: Mixed-language Projects. Chapter 12: dev-cafe/cmake-cookbook - GitHub
CMake Cookbook is a comprehensive resource designed to provide modular "recipes" for managing build systems across various platforms. The most prominent version is the community-driven project originally hosted by
, which covers everything from basic compilation to complex multi-language projects. Core Repository and Resources Official Recipe Repository
: The primary source for the code examples and documentation is the dev-cafe/cmake-cookbook GitHub repository
. It is organized by chapters, covering topics like project structuring, testing, and distribution. Publisher Repository : For the professionally published version, Packt Publishing
maintains a repository containing the code samples corresponding to the book chapters. Community PDF Versions
: While official PDFs are usually paid, community-translated or archived versions sometimes appear on GitHub. For example, a Chinese translation project exists that previously provided PDF builds using GitBook. Key Sections of the Cookbook
The guide is structured to take you from a novice to an advanced user through practical applications: Project Fundamentals
Compiling single source files and switching between generators (like Unix Makefiles vs. Ninja). Building and linking static and shared libraries. Setting language standards (e.g., C++11, C++17). Advanced Logic & Portability
Detecting operating systems and processors for conditional compilation.
Using control flow constructs (if/else, loops) within CMake scripts. Finding and using external libraries (find_package). Structuring Large Projects add_subdirectory to manage nested modules. Encapsulating logic with functions and macros for code reuse. Refactoring large codebases into manageable modules. Testing and Distribution Integrating for automated testing and for packaging software for distribution. Expert-Recommended Alternatives CMake Cookbook
is a standard reference, community experts often suggest additional modern guides for a complete understanding: Professional CMake: A Practical Guide
: Frequently cited as the most thorough and up-to-date resource by Reddit community members , written by Craig Scott, a CMake co-maintainer. Modern CMake PDF : A highly regarded, concise guide available as a
that focuses on "best practices" and avoiding legacy "anti-patterns". Awesome CMake : A curated list of CMake resources
on GitHub, including tutorials, articles, and lectures like Daniel Pfeifer’s "Effective CMake". code example
for a particular task, such as linking a library or setting up a testing suite? README.md - onqtam/awesome-cmake - GitHub
The official GitHub repository for the CMake Cookbook contains the complete, runnable code for every recipe. You don’t need a PDF to learn from it. Clone the repo, read the README.md files, and build each example.
git clone https://github.com/dev-cafe/cmake-cookbook.git
cd cmake-cookbook
ls chapter-01/recipe-01/
Each recipe includes a CMakeLists.txt and explanatory notes. Combine this with the book’s textual explanations (if you buy it) or with the free annotated source code.
The official GitHub repository for CMake Cookbook is:
https://github.com/dev-cafe/cmake-cookbook