Professional CMake:

A Practical Guide

Learn to use CMake effectively with practical advice from a CMake co-maintainer. You can also have the author work directly with your team!

Professional CMake: A Practical Guide 11th Edition

Release Date: 7th December 2021

This is part of the change history for the book Professional CMake: A Practical Guide. The 11th Edition has been updated for the CMake 3.22 release. Compared to previous releases, CMake 3.22 was a relatively small update. The 11th Edition is therefore also correspondingly smaller than usual. The most significant change for this edition is a rewrite of the section covering Android. The new environment modification test property is also noteworthy. As usual, a range of smaller updates and clarifications have also been made. The main changes in this edition are listed below.

Flow Control chapter:

  • Added a note to highlight that if(ENV{some_var}) always evaluates to false.

Build Type chapter:

  • CMake 3.22 added support for initialising the build type from a CMAKE_BUILD_TYPE environment variable for single configuration generators.
  • CMake 3.22 added support for initialising the set of build types from a CMAKE_CONFIGURATION_TYPES environment variable for multi configuration generators.

Language Requirements chapter:

  • Updated and clarified the CMake versions that first supported various CUDA language standards (the CMake documentation had previously been somewhat incorrect and was also updated). CUDA 23 was also added by CMake 3.22.
  • CMake 3.22 now honours <LANG>_EXTENSIONS fully independently from <LANG>_STANDARD. In previous CMake versions, the latter had to be set for the former to have any effect. This relates to a new CMP0128 policy, which also has other effects related to setting the language standard and enabling compiler extensions.

Working With Files chapter:

  • Fixed an error in one of the earlier cmake_path() examples to do with setting the path variable from a string.

Toolchains And Cross Compiling chapter:

  • The example section for Android was lifted out to its own proper section and was almost entirely rewritten. It now focuses on using NDK r23 or later with CMake 3.21 or later. The previous discussion for earlier NDK and CMake versions has mostly been removed, apart from some historical context. The new section is more focused and easier to follow. Discussion of the unmaintained Nvidia Nsight Tegra Visual Studio Edition has also been removed.

Finding Things chapter:

  • CMake 3.22 added support for a new CMAKE_REQUIRE_FIND_PACKAGE_<packageName> variable to turn optional packages into required ones.
  • CMake 3.22 updated the FindPkgConfig module to allow passing arbitrary arguments to the pkgconfig executable.

Testing chapter:

  • CMake 3.22 added a new ENVIRONMENT_MODIFICATION test property which allows a test’s environment variables to be modified at test time instead of only being able to specify values based on details available at configure time.
  • With CMake 3.22, tests can now add test labels dynamically by including appropriate tags in the test output. These are made available in CDash dashboard results.
  • Memcheck dashboard steps now also submit their test results to CDash (new behavior in CMake 3.22, previously those test results were lost and only the memory check results were submitted).
  • The gtest_discover_tests() command now supports a new TEST_FILTER keyword which can be used to filter the set of discovered tests (new in CMake 3.22).

Installing chapter:

  • Added a recommended practice related to the support for a new CMAKE_INSTALL_MODE environment variable added in CMake 3.22.

Packaging chapter:

  • CMake 3.22 added a new CPACK_NSIS_IGNORE_LICENSE_PAGE variable to turn off the license page in NSIS installers.

Working With Qt chapter:

  • Added some very brief comments regarding Qt 6, but the chapter still focuses predominantly on Qt 5.