Qt Creator 4.15: New CMake Features

Qt Creator 4.15 comes with a bunch of features and bug fixes for the CMake Project Manager.

Below, you have a list of what’s new and a few tips and tricks which would hopefully improve your CMake experience in Qt Creator.

Multi-config support

Multi-config generators like Xcode, Visual Studio and Ninja Multi-Config are now supported. This means that you only have to configure CMake once, have only one build directory, and are able to switch faster between build types.

Prior to Qt Creator 4.15, only the first CMake file-api json export was parsed. Now, Qt Creator needs to match the right configuration.

In the CMake project settings, there is a “Build type” field that needs to match the CMAKE_BUILD_TYPE variable for the single configuration generators (Ninja, Makefile).

Qt Creator - CMake - Build type

Qt Creator is using only the Xcode generator for iOS with Qt 6.

Re-configure with initial parameters

Configuring a CMake project in Qt Creator can be a bit confusing. Below, you have a diagram with the places where the CMake variable values are stored.

Qt Creator - CMake Settings

The initial CMake parameters values are used before the project gains a CMakeCache.txt file. Afterwards all the changes in the project setting will result in cmake command line calls with -D<variable>:<type>=<value> or -U<variable> arguments, which will be stored in the CMakeCache.txt and made available to Qt Creator via the file-api json files.

Qt Creator 4.15 gained a button called “Re-configure with initial parameters”, which does a “Clear CMake configuration” and then runs cmake with the values of the “Initial CMake parameters” list.

You will be able to add / edit CMake variables only if the initial cmake configuration succeeds.

Copy and Batch Edit CMake variables

After the project has been initially configured and Qt Creator could read the CMake file-api json files, one could add / modify CMake variables.

With the “Copy” and “Batch Edit…” features, you can configure a CMake project faster than before.

Qt Creator - CMake - copy - batchedit-1

Note that the variables will be sent to cmake and will be persisted in the <BuildDir>/CMakeCache.txt. If you want to keep the values around, save them into the “Initial CMake parameters” list.

Automatic backup of CMake configuration

Qt Creator 4.15 will make a copy of CMakeCache.txt and .cmake/api/v1/reply json directory before running CMake with -D<variable>:<type>=<value> or -U<variable> arguments.

If CMake fails for some reason, the backup will be restored so that you get the previous working configuration. Also the changes will still be present in the dialog and you will have the chance to adjust them.

Quick access to CMake targets definition

In the locator, one could open the corresponding CMakeLists.txt file for a target by typing Ctrl + K and then “cmo ”.

This was working fine if you had created targets directly via add_library, add_executable, but if you had a CMake API and created the targets using a function call, then you would get the CMake API cmake file definition and not the CMakeLists.txt file that called that function.

Qt Creator 4.15 has fixed this issue, see it in action with Qt Creator sources:

Qt Creator - CMake - cmo-1

Package manager auto-setup

The “Initial Parameters list” gained a new entry:


This will cause CMake to inject the auto-setup.cmake script before loading a CMake project. auto-setup.cmake will call conan install or vcpkg install depending on project’s conan or vcpkg package manager configuration.

For more details about this feature and how to disable it if you don’t need it, see: Qt Creator: CMake package-manager auto-setup

Build import source directory relaxation

Qt Creator will allow the import of command line builds where the CMAKE_HOME_DIRECTORY variable points to a path different than the path to the project’s CMakeLists.txt.

This is the case of Qt6’s tests that have been configured by the qt-cmake-standalone-test script, which does a bit of magic that allows the tests not to be CMake standalone projects.

Faster import project loading

Qt Creator needs CMake’s file-api json project export in order to load the project structure.

If a project doesn’t have this structure then Qt Creator will setup the file-api json query and run CMake to do the export.

Depending on the project size and platform this can take a while, wouldn’t it be better if the project would also get this json export?

This can be done by placing a PreLoad.cmake next to the CMakeLists.txt or in the build directory.

This PreLoad.cmake:

foreach(file cache-v2 cmakeFiles-v1 codemodel-v2)
  file(WRITE "${CMAKE_BINARY_DIR}/.cmake/api/v1/query/${file}" "")

will setup the files needed for CMake to generate the file-api json files.

Note that this can’t go into the above auto-setup.cmake file, since Qt Creator creates these files itself. This case is just for the projects configured and built from command line and afterwards imported in Qt Creator.

Debugging the CMake Project Manager

Lastly, if your project doesn’t work with Qt Creator 4.15 anymore, you can find out what the CMake Project Manager is doing by enabling its logging mechanism:


This environment variable will trigger CMake Project Manager’s logging.

On Windows in order to see this log you either need to install DebugView or actually start Qt Creator from Qt Creator.

Qt Creator captures the OutputDebugString Windows debugging output of the programs that it launches.

You just need to have a C++ hello world program and add in the run dialog a custom executable with:


Blog Topics: