Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Craig Scott

Rating No ratings yet

The handbook for every CMake user, providing structured learning, the latest best practices and real-world advice from one of the CMake co-maintainers. Attempting to use any tool before understanding at least the basics of what it does and how it is meant to be used is most likely going to result in frustration. On the other hand, spending all one’s time learning the theory about something without getting hands-on makes for a rather boring experience and often leads to an overly idealistic understanding. This first part of the book follows a logical progression through CMake’s more fundamental features and concepts and is structured to enable the reader to immediately experiment and to do increasingly useful things with each chapter. The goal is to incrementally build up the base knowledge needed to use CMake effectively, with an emphasis on being able to put that knowledge into practice right away. The initial focus in the first few chapters is on building a basic executable or library, covering just enough to give a new developer a quick introduction to CMake. Subsequent chapters expand that knowledge to demonstrate how to get the most out of what CMake has to offer. The techniques presented are aimed at real world use, with the intention of establishing good habits and teaching sound methods which scale to very large projects and can handle more complex scenarios. The later parts of the book all rely heavily on the material covered in this first part. Those who have already been using CMake for some time may find the topics relatively familiar, but the material also includes hard-won knowledge from real world projects and interaction with the CMake community. Even experienced users should find at least the Recommended Practices section at the end of each chapter to be a us

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Professional CMake: A Practical Guide — Reading Guide ## 【One-Line Pitch】 The definitive hands-on handbook for anyone who writes or maintains CMake build systems, written by a CMake co-maintainer and covering everything from first executable to cross-compiling and packaging. If you've been copy-pasting CMake snippets without truly understanding them, this book will turn you into someone who can design clean, scalable build configurations. ## 【Book Arc】 - **Opening (~0%–9%)**: Introduces the philosophy of learning by doing, then walks through a minimal project — managing CMake versions, the `project()` command, and building your first executable and library targets. Establishes the "Recommended Practices" pattern that closes every chapter. - **Early (~9%–25%)**: Covers the core language: variables (normal, environment, and cache), string and list handling, control flow with `foreach()`/`while()`, subdirectories and scope, functions and macros, properties, and CMake policies. This is the foundation everything else builds on. - **Early–Middle (~25%–38%)**: Dives into build configuration in depth — build types (single vs. multi-configuration generators), compiler and linker flags, language standard selection (both direct and feature-based), file manipulation, version details, and library creation including shared library versioning and symbol visibility. - **Middle (~38%–47%)**: Covers toolchains and cross-compiling, Apple platform specifics (frameworks, bundles, code signing), then moves into the "bigger picture" of finding things — files, paths, programs, libraries, and packages via `find_package()` and package registries. - **Middle onward (~47%+)**: Introduces testing with CTest, and the excerpts indicate continued coverage of the broader ecosystem (the table of contents suggests packaging, installation, and exporting targets follow in later chapters). ## 【Key Takeaways】 - **CMake is a build system generator, not a build tool** (Opening): Understanding this distinction — CMake configures, then delegates to Make, Ninja, or Visual Studio — prevents fundamental misconceptions. The book's early chapters make this mental model explicit before any syntax is taught. - **Targets are the central abstraction** (Early): Modern CMake is target-based, not variable-based. Defining executables and libraries as targets and linking them with `target_link_libraries()` propagates usage requirements automatically, which is the key to scalable, maintainable build files. - **Cache variables are the user's interface** (Early): Unlike normal variables, cache variables persist across configure runs and can be set from the command line or GUI tools. Mastering the distinction between normal, cache, and environment variables is essential for writing configurable projects. - **Scope rules are subtle but critical** (Early): Subdirectories create variable scopes, functions create their own, and macros do not. Understanding how values flow (or don't) between scopes prevents a whole class of "why doesn't my variable exist" debugging sessions. - **Properties are metadata attached to targets, directories, and sources** (Early): Properties like compiler flags and include directories can be set at different levels with different inheritance rules. Knowing when to use a property versus a variable is a hallmark of idiomatic CMake. - **Build types differ between single and multi-config generators** (Early–Middle): Makefiles and Ninja are single-configuration (you pick Debug or Release at configure time), while Visual Studio and Xcode are multi-configuration (you pick at build time). This distinction affects how you set flags and structure your project. - **Language standards should be set by feature, not by version number** (Early–Middle): Using `target_compile_features()` with requirements like `cxx_std_11` lets CMake pick the right compiler flags automatically and fails early if the compiler is too old — more robust than hardcoding `-std=c++17`. - **Finding dependencies is a skill in itself** (Middle): The book covers the full spectrum — `find_file()`, `find_path()`, `find_program()`, `find_library()`, and `find_package()` — including package registries and pkg-config integration. This is where real-world projects often get messy, and the guidance here is practical. ## 【Reading Tips】 - **Skim the first two chapters if you've used CMake before**, but don't skip the "Recommended Practices" sections — they contain hard-won community wisdom that even experienced users will find valuable. - **Deep-read Chapters 5–8 (variables, control flow, subdirectories, functions)** — these are the language fundamentals that everything else builds on. Work through the examples interactively; CMake is a tool you learn by running, not just reading. - **Pay special attention to Chapter 20 (Libraries)** if you maintain libraries for others — shared library versioning, symbol visibility, and interface compatibility are topics rarely covered well elsewhere. - **Use the book as a reference, not just a tutorial**: the table of contents is detailed enough that you can jump to specific topics (e.g., "cross-compiling" or "Apple frameworks") when you hit a real problem. - **Keep a CMake project open while reading** — the book explicitly encourages experimentation, and the examples are designed to be tried immediately. ## 【Coverage Limits】 This guide is based on excerpts covering roughly the first half of the book (through testing). Later chapters on packaging, installation, exporting targets, and advanced generator expressions are not covered in detail here. ##
Page 2
IG SCOTT Professional CMake: A Practical Guide Version: 1.0.3 © 2018 by Craig Scott This book or any portion thereof may not be reproduced in any manner or f...
View in text
Page 3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  59 8.2....
View in text
Page 5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  128 15.3. Recommended Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
View in text
Page 6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  244 23.2. Finding Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
View in text
Page 3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  357 26.4.8....
View in text
Page 11
idoctor, the software used to compile and prepare this book. Despite the size, complexity and technical nature of the material, I have been constantly amazed...
View in text
Page 15
ary directory. The source directory is where the CMakeLists.txt file is located and the project’s source files and all other files needed for the build are o...
View in text
Page 17
can be loaded into an IDE, read by command line tools, etc. Alternatively, cmake can invoke the build tool on the developer’s behalf like so: 8 cmake --build...
View in text
Tags
AI categories
ProgrammingC++C#
Publish Year: 2018
Language: English
Pages: 429
File Format: PDF
File Size: 4.1 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…