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
Minimal CMake
Minimal CMake

Minimal CMake: Learn the best bits of CMake to create and share your own libraries and applications

Arrow left icon
Profile Icon Tom Hulton-Harrop
Arrow right icon
$29.99 $33.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jan 2025 266 pages 1st Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Tom Hulton-Harrop
Arrow right icon
$29.99 $33.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jan 2025 266 pages 1st Edition
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Minimal CMake

Getting Started

The objective of Minimal CMake is to walk you through the development process of taking an application from its humble beginnings (starting with a simple console application) to a complete windowed application you can demo to friends and use as a template for future projects.

We’ll see how CMake can help throughout the entire process. Perhaps the greatest benefit CMake provides is how easy it is to integrate existing open source software to improve the functionality of your app.

Before we can start using CMake to create our application, we need to ensure that we have our development environment set up and ready to go. The setup will vary depending on which platform you’ve decided to use (Windows, macOS, or Linux). We’ll cover each system here. This will provide a good starting point to build on as we introduce CMake and begin assembling the core of our application.

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

    ...

Technical requirements

To get the most out of this book, we recommend that you run the examples locally. To do this you will need the following:

  • A Windows, Mac, or Linux machine with an up-to-date operating system (OS)
  • A working C/C++ compiler (a system default is recommended for each platform if you don’t already have this)

The code examples in this chapter can be found by following this link: https://github.com/PacktPublishing/Minimal-CMake.

CMake version

All examples in this book have been tested with CMake 3.28.1. Earlier versions are not guaranteed to work. Later versions should be safe to upgrade to, though it’s possible that there may be differences. If in doubt, use CMake 3.28.1 when running the examples from this book.

Installing CMake on Windows

In this section, we’ll cover how to install everything you’ll need to start building applications with CMake on Windows.

To begin with, you will need a C/C++ compiler. If you don’t already have a compiler installed, a good choice to go with is Visual Studio (Visual Studio 2022 Community Edition can be downloaded from https://visualstudio.microsoft.com/vs/community/).

Visual Studio is an integrated development environment that comes with Microsoft’s C++ compiler for Windows (cl.exe). We won’t be covering Visual Studio directly, though you are more than welcome to use it if you prefer (see Chapter 11, Supporting Tools and Next Steps for a brief summary). We’ll cover how to generate Visual Studio solution files and invoke MSBuild to build our project. To keep things as consistent as possible, we’ll use Visual Studio Code for most of the examples. This is more for convenience than anything else, and if you...

Installing CMake on macOS

In this section, we’ll cover how to install everything you’ll need to start building the application on macOS.

To begin, you will need a C/C++ compiler. If you don’t already have a compiler installed, the safest bet is to go with Xcode, which can be downloaded from the App Store:

  1. Go to Spotlight Search by clicking the magnifying glass on the macOS menu bar.
Figure 1.10: Spotlight Search option on macOS menu bar

Figure 1.10: Spotlight Search option on macOS menu bar

  1. Search for App Store.
Figure 1.11: Searching for App Store from Spotlight Search

Figure 1.11: Searching for App Store from Spotlight Search

  1. From App Store, search for Xcode.
Figure 1.12: Xcode search results from the App Store

Figure 1.12: Xcode search results from the App Store

  1. Click the Get and then Install buttons.
Figure 1.13: Xcode application install

Figure 1.13: Xcode application install

It is also possible to install Command Line Tools for Xcode from https://developer.apple.com, specifically https://developer...

Installing CMake on Linux (Ubuntu)

In this section, we’ll cover how to get everything you’ll need to start building the application on Linux (Ubuntu).

To begin with, you will need a C/C++ compiler. If you don’t already have a compiler installed, an excellent choice is to go with GCC. This can be installed by using the standard Ubuntu package manager, apt:

  1. Open Terminal by using Show Applications from the desktop.
Figure 1.21: Ubuntu Show Applications menu option

Figure 1.21: Ubuntu Show Applications menu option

  1. Run sudo apt update and then sudo apt install build-essential (it is possible that your version of Ubuntu already comes with this installed, but it’s good to check).
Figure 1.22: Installing build-essential from Terminal

Figure 1.22: Installing build-essential from Terminal

  1. Run gcc --version to verify that the compiler can be found and is working as expected. You should see output resembling the following:
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 ...
...

Installing Git

To follow the examples provided in each chapter and retrieve the accompanying source code for this book (available from the book’s website https://github.com/PacktPublishing/Minimal-CMake), it is recommended to have Git installed on your system.

The easiest way to do this is to go to https://git-scm.com/downloads and download Git for your chosen platform if you do not already have it installed.

On macOS, Git is installed as part of the Xcode installation we walked through in Installing CMake on macOS. On Windows, download the 64-bit installer and run the installation. On Linux (Ubuntu), run sudo apt-get install git from the terminal.

Type git from the command line to verify that the tool is available.

Visual Studio Code setup (optional)

To ensure a consistent experience throughout the book, Visual Studio Code will be used along with the native terminal to walk through code examples, be that on Windows, macOS, or Linux. The following section outlines how to get set up with Visual Studio Code and configure your development environment. If you would prefer to use a different editor, that’s fine. All that is needed to follow along is a C/C++ compiler and CMake. Visual Studio Code is simply used as a cross-platform editor (it also comes with some excellent CMake support that is covered in Chapter 11, Supporting Tools and Next Steps).

To install Visual Studio Code, go to https://code.visualstudio.com/Download. There are links for Windows, Linux, and macOS there. Follow the installation instructions for your platform of choice. On Windows, choose User Installer and follow the setup instructions.

On Linux, either download the .deb package and use the Software Install application...

Summary

In this chapter, we walked through everything you need to begin development with CMake. We installed a C/C++ compiler on Windows, macOS, and Linux and installed CMake on each platform. We saw how to install Git and walked through how to install Visual Studio Code and enable several useful extensions. Having our environment configured correctly is important to ensure that the later examples we’ll work through behave as expected. We now have everything we need to start using CMake and can start developing our project to understand how CMake can accelerate how we build software.

In the next chapter, we will introduce CMake and look at the commands you will commonly run from the terminal. We’ll also look at some of the core commands that make up a CMake script. We’ll get a basic application up and running and learn about generators, build types, and more.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Unlock efficient cross-platform builds with streamlined CMake setups
  • Learn CMake's most powerful features for streamlined software development from a seasoned game and engine developer
  • Create and distribute an application with step-by-step instructions, practical examples, and working code
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Minimal CMake guides you through creating a CMake project one step at a time. The book utilizes the author's unique expertise in game and engine development to craft compelling examples of how CMake can be used to build complex software. The chapters introduce concepts gradually, each one building on the last. Throughout the course of the book, you will progress from a simple console application all the way through to a full windowed app. The book will help you build a strong foundation in CMake that will translate to future projects. You'll learn how to integrate existing software libraries to enhance your app's functionality, how to build reusable libraries to share with others, and how to manage developing for multiple platforms simultaneously, including macOS, Windows, and Linux. You'll also find out how CMake facilitates testing and how to package your application ready for distribution. The book aims to not overwhelm you with everything there is to know about CMake. Instead, it focuses on the most relevant and important parts that will help you become productive quickly. By the end of this book, you will be a confident CMake user and will have gained the skills and experience to build and share your own libraries and applications.

Who is this book for?

If you are a programmer skilled in C, C++, Swift, Objective-C, or C#, and keen on cross-platform development and open-source software, this book is for you. A solid grasp of CMake helps you to effectively utilize and create open-source libraries and applications. No prior knowledge of CMake is necessary, though familiarity with an imperative programming language (especially C and C++) is beneficial. While a basic understanding of the terminal is advantageous, comprehensive setup instructions will guide you across Windows, macOS, and Linux (Ubuntu).

What you will learn

  • Set up projects for seamless cross-platform development
  • Integrate external libraries to enhance your project's functionality
  • Create and share reusable libraries
  • Manage complex software dependencies for improved maintainability
  • Package and distribute applications efficiently
  • Utilize top tools to streamline your CMake workflow
  • Explore resources for continuous learning

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 03, 2025
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781835080658
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 03, 2025
Length: 266 pages
Edition : 1st
Language : English
ISBN-13 : 9781835080658
Category :
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 $5 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 $5 each
Feature tick icon Exclusive print discounts

Table of Contents

16 Chapters
Part 1: Starting Up Chevron down icon Chevron up icon
Chapter 1: Getting Started Chevron down icon Chevron up icon
Chapter 2: Hello, CMake! Chevron down icon Chevron up icon
Chapter 3: Using FetchContent with External Dependencies Chevron down icon Chevron up icon
Chapter 4: Creating Libraries for FetchContent Chevron down icon Chevron up icon
Part 2: Scaling Up Chevron down icon Chevron up icon
Chapter 5: Streamlining CMake Configuration Chevron down icon Chevron up icon
Chapter 6: Installing Dependencies and ExternalProject_Add Chevron down icon Chevron up icon
Chapter 7: Adding Install Support for Your Libraries Chevron down icon Chevron up icon
Chapter 8: Using Super Builds to Simplify Onboarding Chevron down icon Chevron up icon
Part 3: Wrapping Up Chevron down icon Chevron up icon
Chapter 9: Writing Tests for the Project Chevron down icon Chevron up icon
Chapter 10: Packaging the Project for Sharing Chevron down icon Chevron up icon
Chapter 11: Supporting Tools and Next Steps Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Lucien Erard Feb 21, 2025
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.