New features in CMake 3.17

On 20th of March, Kitware released CMake 3.17. The release notes contain the list of changes.

Below you have some changes that should improve the life of a Qt developer using CMake.

Ninja Multi-Config Generator

This generator is similar to the Ninja generator but it can be used to build multiple configurations at once.

This feature is similar to qmake’s debug_and_release feature.

The reference documentation of Ninja Multi-Config generator has all the nitty-gritty details.

The debug_and_release usage would be:

cmake -G"Ninja Multi-Config" \
  -DCMAKE_CONFIGURATION_TYPES=Release;Debug \
  -DCMAKE_DEFAULT_CONFIGS=all \
-DCMAKE_CROSS_CONFIGS=all \ -S source_dir \ -B build_dir cmake --build build_dir

This feature was tracked at Kitware’s side at #20161

iOS multi-architecture for Ninja / Makefile generators

Now it is possible to compile “fat” (multi-architecture) binaries for iOS at once.

The command line usage would be:

cmake -GNinja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=iOS \
  -DCMAKE_OSX_ARCHITECTURES=arm64;x86_64
  -S source_dir \
  -B build_dir
cmake --build build_dir

This feature was tracked at Kitware’s side at #19534

AUTOGEN uses moc-generated dependency files

Qt 5.15 brings us an updated moc which can generate a dependency file, which will be used by Ninja to (re)build only the necessary bits.

This means that for a project like Qt Creator the null build will be executed faster, since all the AUTOGEN targets will no longer have to be built.

On my Windows 10 machine I’ve tested CMake 3.17, Ninja 1.10, Qt 5.15.0 with Qt Creator and the null builds (average from 5 runs) went from 4.6 seconds with CMake 3.16 to 2.4 seconds with CMake 3.17!

Qt Creator still has a few custom targets which need to be executed (copying shared files, clang include files etc) and these fill up those 2.4 seconds.

This feature was tracked at Kitware’s side at #18749

Ninja doesn’t re-run CMake after configuration

You might have noticed that after opening a CMake project in Qt Creator and then hitting the Build button Ninja would re-run CMake on the already configured project.

Depending on the size of the project or platform this can be very annoying. Qt Creator’s CMake configuration could take up to 30 seconds on my Windows 10 machine.

With Ninja version 1.10 and CMake version 3.17 this annoying behavior is gone!

The Qt  SDK has Ninja and CMake bundled, unfortunately Ninja version 1.9 and CMake version 3.16. I’ve opened up QTBUG-83006 and QTBUG-83007 suggestions for the Qt Release Team.

This feature was tracked at Kitware’s side at #15830

ccache and precompile headers

For the projects that are using a header file to speed up compilation via precompiled headers, and are using ccache to cache the build artifacts, now ccache will have a 100% cache hit rate!

CMake will now copy the timestamp of the header for its internal precompiled headers machinery, and ccache will not think that the PCH artifact is too new.

Qt Creator uses such a header src/shared/qtcreator_gui_pch.h.

ccache will need to have include_file_mtime specified for its sloppiness option. This was suggested by ccache maintainer at #549

At the moment this works only with GCC. CMake’s Clang precompile headers configuration is not supported by ccache, see #539

This feature was tracked at Kitware’s side at #19923

Valid zip and 7zip archive generation

CMake via cmake -E tar command line can extract tar.gz, tar.bz, tar.xz, tar.zstd, zip, 7z archives, or create archives.

This could be useful on CI systems where you might not have necessary tools installed on all platforms, but do have CMake installed.

The Zip and 7zip archives would contain the current directory . in the archive. While this poses no problems for tar archives, the Zip archive could not be opened on Windows with Windows Explorer, and the 7zip archive would cause problems (crashes) on KDE.

This feature was tracked at Kitware’s side at #20238 and #20297.


Blog Topics:

Comments