A Practical Guide
Craig Scott

#CMake
#Qt
CMake is a very popular tool for defining how projects should be built, tested and packaged. Its maturity, breadth of features, broad platform support and toolchain flexibility have led to its widespread adoption among the software development community. In recent years, the 3.x release series has brought with it a whole new set of powerful capabilities and best practices, leading to the coining of the term Modern CMake. But “modern” is a moving target. Therefore, a key motivation for this book is to provide developers with an up-to-date, practical guide to learning CMake, paying particular attention to the latest best practices. As a CMake tutorial, it follows a logical sequence from basic concepts through to more advanced topics. Complementing that, the chapter structure also allows the more experienced user to quickly find and focus in on a particular area of interest.
The first part of the book introduces each of the fundamental areas of CMake. These early chapters are arranged to get the reader up and running quickly with a basic project, then progressively build up an understanding of CMake’s core concepts in manageable, structured units. These chapters not only present the key concepts, they also shape the reader’s understanding of how CMake can be used most effectively and how to avoid common pitfalls.
The middle part of the book goes into much greater detail about various key areas and has a more task-focused flavor. Much of the material addresses everyday problems frequently faced by developers, while many of the chapters cover features that are new or improved in the 3.x release series.
Some chapters go even deeper than discussing CMake alone. Topics covered include advanced linking techniques, how to structure libraries, managing versioning across platforms, and an in-depth treatment of Apple-specific technologies such as bundles, frameworks and code signing.
The many recommended practices in this part of the book demonstrate how developers can get the most out of CMake’s extensive feature set. They also draw attention to a number of common but discouraged practices and explain why they should be avoided.
The final part of the book expands the reader’s focus. It encourages looking beyond the project in isolation, seeing it from different perspectives and use cases. It tackles head on one of the more difficult tasks faced by developers, that of managing the complexities of inter-project dependencies. These chapters discuss CMake features for finding and providing dependencies, making a project consumable by others, how to robustly prepare packages in various formats and how to follow common platform conventions.
Other aspects that feature prominently in this part of the book include project integrity, ease of development, maintainability and onboarding new developers. Examples of this include a deep coverage of CMake’s extensive testing support, and the important topic of simplifying a developer’s workflow using CMake presets. Project organization is also covered in detail, providing a solid foundation for production-scale projects.
A separate chapter covers various aspects of build performance. The heavy focus on production-scale issues and functionality makes this one of the most valuable chapters of the book. The techniques presented can potentially give drastic reductions in build time and lead to more efficient use of build resources.
The final chapter covers the special area of Qt support. It includes discussion of features provided by both CMake and Qt, covering topics including moc, uic and rcc support, translation handling and using Qt’s deployment tools.
Table Of Contents
Part I: Fundamentals
1. Introduction
2. Setting Up A Project
3. A Minimal Project
4. Building Simple Targets
5. Variables
6. Flow Control
7. Using Subdirectories
8. Functions And Macros
9. Properties
10. Generator Expressions
11. Modules
12. Policies
13. Debugging And Diagnostics
Part II: Builds In Depth
14. Build Type
15. Compiler And Linker Essentials
16. Advanced Linking
17. Language Requirements
18. Target Types
19. Custom Tasks
20. Working With Files
21. Specifying Version Details
22. Libraries
23. Toolchains And Cross Compiling
24. Apple Features
Part Il l: The Bigger Picture
25. Finding Things
26. Testing
27. Installing
28. Packaging
29. ExternalProj ect
30. FetchContent
31. Making Projects Consumable
32. Dependency Providers
33. Presets
34. Project Organization
35. Build Performance
36. Working With Qt









