Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Modern CMake for C++
  • Toc
  • feedback
Modern CMake for C++

Modern CMake for C++

By : Rafał Świdziński
4.7 (12)
close
Modern CMake for C++

Modern CMake for C++

4.7 (12)
By: Rafał Świdziński

Overview of this book

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.
Table of Contents (20 chapters)
close
17
Other Books You May Enjoy
18
Index

Building and managing dependencies

All build processes follow the same procedure. We begin with the top-level listfile and progress downward through the project’s source tree. Figure 15.4 illustrates the project files involved in the build process, with numbers in parentheses indicating the order of CMake script execution.

Figure 15.4: Files used in the build stage

The top-level CMakeLists.txt (1) listfile configures the project:

ch15/01-full-project/CMakeLists.txt

cmake_minimum_required(VERSION 3.26)
project(Calc VERSION 1.1.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(NoInSourceBuilds)
include(CTest)
add_subdirectory(src bin)
add_subdirectory(test)
include(Packaging)

We start by specifying essential project details and setting the path to the CMake utility modules (the cmake directory in our project). We then prevent in-source builds using a custom module. Following that, we enable testing with the...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete