E-Book, Englisch, 504 Seiten
Swidzinski / Swidzinski Modern CMake for C++
2. Auflage 2024
ISBN: 978-1-80512-336-1
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
Effortlessly build cutting-edge C++ code and deliver high-quality solutions
E-Book, Englisch, 504 Seiten
ISBN: 978-1-80512-336-1
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
Modern CMake for C++ isn't just another reference book, or a repackaging of the documentation, but a blueprint to bridging the gap between learning C++ and being able to use it in a professional setting. It's an end-to-end guide to the automation of complex tasks, including building, testing, and packaging software.
This second edition is significantly rewritten, restructured and refreshed with latest additions to CMake, such as support of C++20 Modules.
In this book, you'll not only learn how to use the CMake language in CMake projects but also discover how to make those projects maintainable, elegant, and clean. As you progress, you'll dive into the structure of source directories, building targets, and packages, all while learning how to compile and link executables and libraries. You'll also gain a deeper understanding of how those processes work and how to optimize builds in CMake for the best results. You'll discover how to use external dependencies in your project - third-party libraries, testing frameworks, program analysis tools, and documentation generators. Finally, you'll gain profi ciency in exporting, installing, and packaging for internal and external purposes.
By the end of this book, you'll be able to use CMake confi dently at a professional level.
Fachgebiete
Weitere Infos & Material
Table of Contents - First Steps with CMake
- The CMake Language
- Using CMake in Popular IDEs
- Setting Up Your First CMake Project
- Working with Targets
- Using Generator Expressions
- Compiling C++ Sources with CMake
- Linking Executables and Libraries
- Managing Dependencies in CMake
- Using the C++20 Modules
- Testing Frameworks
- Program Analysis Tools
- Generating Documentation
- Installing and Packaging
- Creating Your Professional Project
- Writing CMake Presets
- Appendix
Preface
Creating top-notch software is no easy task. Developers researching this subject online often struggle to determine which advice is current and which methods have been superseded by newer, better practices. Moreover, most resources explain the process chaotically, lacking proper background, context, and structure.
provides an end-to-end guide that offers a simpler experience by treating the building of C++ solutions comprehensively. It not only teaches you how to use CMake in your projects but also highlights what makes them maintainable, elegant, and clean. The guide walks you through automating complex tasks common in many projects, including building, testing, and packaging.
The book instructs you on organizing source directories, building targets, and creating packages. As you progress, you will learn to compile and link executables and libraries, understand these processes in detail, and optimize each step for the best results. Additionally, you will discover how to incorporate external dependencies into your project, such as third-party libraries, testing frameworks, program analysis tools, and documentation generators. Finally, you’ll learn how to export, install, and package your solution for both internal and external use.
After completing this book, you’ll be able to use CMake confidently on a professional level.
Who this book is for
After you’ve learned C++, you’ll quickly discover that proficiency with the language alone isn’t enough to prepare you for delivering projects at the highest standards. This book fills that gap: it is addressed to anyone aspiring to become a better software developer or even a professional build engineer!
Read it if you want to learn modern CMake from scratch or elevate and refresh your current CMake skills. It will help you understand how to make top-notch C++ projects and transition from other build environments.
What this book covers
, , covers the installation of CMake, the use of its command line interface, and introduces the fundamental building blocks necessary for a CMake project.
, , cover the essential concepts of the CMake language, including command invocations, arguments, variables, control structures, and comments.
, , emphasizes the importance of Integrated Development Environments (IDEs), guides you through selecting an IDE, and provides setup instructions for Clion, Visual Studio Code, and Visual Studio IDE.
, , will teach you how to configure a basic CMake project in its top-level file, structure the file tree, and prepare the toolchain necessary for development.
, , explores the concept of logical build targets, understand their properties and different types, and learn how to define custom commands for CMake projects.
, , explains the purpose and syntax of generator expressions, including how to use them for conditional expansion, queries, and transformations.
, , delves into the compilation process, configure the preprocessor and optimizer, and discover techniques to reduce build time and improve debugging.
, , understands the linking mechanism, different types of libraries, the One Definition Rule, the order of linking, and how to prepare your project for testing.
, , will teach you to manage third-party libraries, add CMake support for those that lack it, and fetch external dependencies from the internet.
, , introduces C++20 modules, shows how to enable their support in CMake, and configure the toolchain accordingly.
, , will help you understand the importance of automated testing, leverage built-in testing support in CMake, and get started with unit testing using popular frameworks.
, , will show you how to automatically format source code and detect software errors during both build time and runtime.
, , presents how to use Doxygen for automating documentation creation from source code and add styling to enhance your documentation’s appearance.
, , prepares your project for release with and without installation, create reusable packages, and designate individual components for packaging.
, , applies all the knowledge acquired throughout the book to develop a comprehensive, professional-grade project.
, , encapsulates high-level project configurations into workflows using CMake preset files, making project setup and management more efficient.
- , serves as a reference for various CMake commands related to strings, lists, files, and mathematical operations.
To get the most out of this book
Basic familiarity with C++ and Unix-like systems is assumed throughout the book. Although Unix knowledge isn’t a strict requirement, it will prove helpful in fully understanding the examples given in this book.
This book targets CMake 3.26, but most of the techniques described should work from CMake 3.15 (features that were added after are usually highlighted). Some chapters have been updated to CMake 3.28 to cover the latest features.
Preparation of the environment to run examples is covered in , but we specifically recommend using the Docker image provided with this book if you’re familiar with this tool.
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Modern-CMake-for-Cpp-2E. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781805121800.
Conventions used
There are a number of text conventions used throughout this book.
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: “Mount the downloaded disk image file as another disk in your system.”
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
Any command-line input or output is written as follows:
Bold: Indicates a new term, an important word, or words that you see on the screen. For example: “Select System info from the Administration panel.”
Warnings or important notes appear like this.
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: Email , and mention the book’s title in the subject of your message. If you have questions about any aspect of this book, please email us at .
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.
Share your thoughts
Once you’ve read , , we’d love to hear your thoughts! Please click here to go...