Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Modern CMake for C++
Modern CMake for C++

Modern CMake for C++: Discover a better approach to building, testing, and packaging your software

Arrow left icon
Profile Icon Rafał Świdziński
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (23 Ratings)
Paperback Feb 2022 460 pages 1st Edition
eBook
Can$42.99 Can$47.99
Paperback
Can$59.99
Subscription
Free Trial
Arrow left icon
Profile Icon Rafał Świdziński
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (23 Ratings)
Paperback Feb 2022 460 pages 1st Edition
eBook
Can$42.99 Can$47.99
Paperback
Can$59.99
Subscription
Free Trial
eBook
Can$42.99 Can$47.99
Paperback
Can$59.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Modern CMake for C++

Chapter 1: First Steps with CMake

There is something magical about turning source code into a working application. It is not only the effect itself, that is, a working mechanism that we devise and bring to life, but the very process or act of exercising the idea into existence.

As programmers, we work in the following loop: design, code, and test. We invent changes, we phrase them in a language that the compiler understands, and we check whether they work as intended. To create a proper, high-quality application from our source code, we need to meticulously execute repetitive, error-prone tasks: invoking the correct commands, checking the syntax, linking binary files, running tests, reporting issues, and more.

It takes great effort to remember each step every single time. Instead, we want to stay focused on the actual coding and delegate everything else to automated tooling. Ideally, this process would start with a single button, right after we have changed our code. It would be smart, fast, extensible, and work in the same way across different OSs and environments. It would be supported by multiple Integrated Development Environments (IDEs) but also by Continuous Integration (CI) pipelines that test our software after a change is submitted to a shared repository.

CMake is the answer to many such needs; however, it requires a bit of work to configure and use correctly. This is not because CMake is unnecessarily complex but because the subject that we're dealing with here is. Don't worry. We'll undergo this whole learning process very methodically; before you know it, you will have become a building guru.

I know you're eager to rush off to start writing your own CMake projects, and I applaud your attitude. Since your projects will be primarily for users (yourself included), it's important for you to understand that perspective as well.

So, let's start with just that: becoming a CMake power user. We'll go through a few basics: what this tool is, how it works in principle, and how to install it. Then, we'll do a deep dive on the command line and modes of operation. Finally, we'll wrap up with the purposes of different files in a project, and we'll explain how to use CMake without creating a project at all.

In this chapter, we're going to cover the following main topics:

  • Understanding the basics
  • Installing CMake on different platforms
  • Mastering the command line
  • Navigating the project files
  • Discovering scripts and modules
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand and automate compilation and linking with CMake
  • Manage internal and external dependencies easily
  • Add quality checks and tests as an inherent step for your builds

Description

Creating top-notch software is an extremely difficult undertaking. Developers researching the subject have difficulty determining which advice is up to date and which approaches have already been replaced by easier, better practices. At the same time, most online resources offer limited explanation, while also lacking the proper context and structure. This book offers a simpler, more comprehensive, experience as it treats the subject of building C++ solutions holistically. Modern CMake for C++ is an end-to-end guide to the automatization of complex tasks, including building, testing, and packaging. You'll not only learn how to use the CMake language in CMake projects, but also discover what makes them maintainable, elegant, and clean. The book also focuses on the structure of source directories, building targets, and packages. As you progress, you’ll learn how to compile and link executables and libraries, how those processes work, and how to optimize builds in CMake for the best results. You'll understand how to use external dependencies in your project – third-party libraries, testing frameworks, program analysis tools, and documentation generators. Finally, you'll get to grips with exporting, installing, and packaging for internal and external purposes. By the end of this book, you’ll be able to use CMake confidently on a professional level.

Who is this book for?

The book is for build engineers and software developers with knowledge of C/C++ programming who are looking to learn CMake to automate the process of building small and large software solutions. If you are someone who's just getting started with CMake, a long-time GNU Make user, or simply looking to brush up on the latest best practices, this book is for you.

What you will learn

  • Understand best practices for building C++ code
  • Gain practical knowledge of the CMake language by focusing on the most useful aspects
  • Use cutting-edge tooling to guarantee code quality with the help of tests and static and dynamic analysis
  • Discover how to manage, discover, download, and link dependencies with CMake
  • Build solutions that can be reused and maintained in the long term
  • Understand how to optimize build artifacts and the build process itself

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 28, 2022
Length: 460 pages
Edition : 1st
Language : English
ISBN-13 : 9781801070058
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 28, 2022
Length: 460 pages
Edition : 1st
Language : English
ISBN-13 : 9781801070058
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 195.97
Modern CMake for C++
Can$59.99
C++20 STL Cookbook
Can$59.99
C++ High Performance
Can$75.99
Total Can$ 195.97 Stars icon

Table of Contents

16 Chapters
Section 1: Introducing CMake Chevron down icon Chevron up icon
Chapter 1: First Steps with CMake Chevron down icon Chevron up icon
Chapter 2: The CMake Language Chevron down icon Chevron up icon
Chapter 3: Setting Up Your First CMake Project Chevron down icon Chevron up icon
Section 2: Building With CMake Chevron down icon Chevron up icon
Chapter 4: Working with Targets Chevron down icon Chevron up icon
Chapter 5: Compiling C++ Sources with CMake Chevron down icon Chevron up icon
Chapter 6: Linking with CMake Chevron down icon Chevron up icon
Chapter 7: Managing Dependencies with CMake Chevron down icon Chevron up icon
Section 3: Automating With CMake Chevron down icon Chevron up icon
Chapter 8: Testing Frameworks Chevron down icon Chevron up icon
Chapter 9: Program Analysis Tools Chevron down icon Chevron up icon
Chapter 10: Generating Documentation Chevron down icon Chevron up icon
Chapter 11: Installing and Packaging Chevron down icon Chevron up icon
Chapter 12: Creating Your Professional Project Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(23 Ratings)
5 star 60.9%
4 star 17.4%
3 star 8.7%
2 star 8.7%
1 star 4.3%
Filter icon Filter
Top Reviews

Filter reviews by




Christian Albaret Feb 16, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought 5 books at once and could only give a fast glance at this one in order to write he review. It seems I have to write the reviews in order. I am using CMake on my project, but most of the CMake has been written by others. Writing CMake is usually a pain because you get lost in the heavy reference documentation. The book goes through the steps useful to set up a project build.
Feefo Verified review Feefo
Peter Zettler Feb 13, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good overview with practical and helpful samples.
Feefo Verified review Feefo
Devinder May 07, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Packt asked me to review a book on CMAKE for them, which, honestly, I wasn’t expecting, because I gave the last book they asked me to review, a 3 out of 5 (I promise it was fair). The book today is: Modern CMake for C++, by Rafal Swidzinski.The short version of my review is:If you are getting started with CMAKE or just don’t feel confident about your knowledge, get this book. It is a solid 5/5.A bit about me: I started using CMAKE in some capacity in 2019. Since then, I’ve had to grow into learning a bit more about it, because turns out that a good CMAKE strategy that uses a modern approach, is important if you want less pain in your complex C++ projects.I own a copy of the professional CMAKE book. I’ve gone through the various adoption strategies that have evolved recently and become talks or articles. I occasionally stalk slack channels like CppLang to learn as much as I can from the heavy weights. I developed the CMAKE strategy at Ebots, and have been fairly involved in making sure the code build/installs/updates become relatively painless.More on the book:I think Rafal Swidzinski's book condenses everything you need to know about CMAKE and does it well. His approach is clear, and practical.For beginners, who are just starting their search on getting started, the first seven chapters will walk you through the basics and make you capable of writing manageable software with CMAKE.If you feel somewhat comfortable with CMAKE already but aren’t too sold on the Testing/Installing bits of it, you will get a practical guide on that in the last few chapters. The final project, if you follow through with it, has all the supporting tools you need to be successful. There’s also his source code in github.Far as I know, I don't get any money if you buy it =) , or at least haven't seen any ::hmpfh:: Though I did get a copy of the book to review. Note that the amazon review is pretty identical to my review on linkedin.
Amazon Verified review Amazon
H Zhu Apr 06, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book covers the basics and advanced usage of CMake. I really like the book with high-level diagrams and detailed examples, that well explains the usage of CMake, the concepts behind it, and the best practices. And I enjoyed the flow of the book, from basic concepts to advanced topics like how CMake can work with different platforms, protobuf, docker, GitHub, testing and performance analysis etc.
Amazon Verified review Amazon
GFisher Nov 15, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Can't recommend this book enough. After working as an embedded software developer for over a year without any formal training on C++ or CMake, I've constantly finding myself fighting tooth and nail against our build system. It's been a long, frustrating experience to ssy the least. Due to the senior team members I work closely with being stubborn in their ways, and obsessed with meeting deadlines (which we have been consistently missing by the way), I've been met with nothing but push-back when expressing the desire fir formal training on the technology none of us know how to use. I finally got fed up enough to buy and read this in my free time. It has been a life saver! Any professional using CMake needs to learn how it works from the basics to the advanced level, and how to use it the right way, if they are to be of any value to their employer and/or coworkers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.