CMake Project Configuration in Qt Creator 4.13

Configuring medium-sized to large CMake projects in Qt Creator can be a challenge. This is due to the number of options that you would need to pass to CMake to configure the project in the right way.

Let’s take Qt Creator’s CMake build. Unlike its qmake build, the CMake build lets you configure which plugins you want to build.

Let’s say you would just want to build the CMake project manager, the Git source control, only C++ and only for the Desktop platforms.

This would mean the following CMake options will be set to OFF:


In the old days (prior to Qt Creator version 4.0) you could simply pass the CMake configuration command line and you would get a right configured project from the start!

Qt Creator up to version 4.13

There were three ways to configure CMake projects in Qt Creator with the above flags:

  1. Use a command line script which would configure the project and then import it in Qt Creator.
  2. Create a Qt Creator Kit, which would have all the settings in the CMake Configuration field.
  3. Manually select all the options in the CMake project settings. This would add the values in the CMakeLists.txt.user file.

If you used a script to configure the project (or cmake-gui), and then decided to change a setting Qt Creator, you could encounter the following dialog:


Qt Creator 4.13

The above dialog is gone in Qt Creator 4.13 since Qt Creator doesn’t use the CMakeLists.txt.user file to store individual CMake options. It only stores the Initial CMake parameters, the subsequently changed ones are passed via -D<option>=<value> to CMake, which stores the options in the CMakeCache.txt file.

This means that if you remove the build directory, all the custom settings that are not part of the initial CMake parameters are gone.

This configuration dialog looks like this:


You can configure the project from the Build menu and then Run CMake like this:


Notice the Clear CMake Configuration menu entry, which would remove the CMakeCache.txt file, which you need to do if you change the Initial CMake parameters field. This has the potential of doing a full rebuild.

Having less targets to build has an impact on Qt Creator build time (Windows 10, 10 core Intel i9 machine):

Build type CMake configure time  Ninja tasks Build time
Full 00m 27s 3404 07m 31s
Custom 00m 19s 2141 04m 30s


“Nuking” up the build

You can either delete the whole build directory, or from Qt Creator’s Build menu:

  1. Clean Project “Qt Creator”. This will execute the clean ninja target, which will remove the build artifacts (*.obj, *.dll, *.exe)
  2. Clear CMake Configuration. This will remove the CMakeCache.txt file.

Then you can Run CMake and Build Project “Qt Creator” and it should behave as having had nuked the build directory.

Auto-create build directories

Qt Creator by default sets the following options for CMake:

[x] Autorun CMake  
[ ] Auto-create build directories

This means that every time you type and save your CMakeLists.txt CMake will configure the project. I personally have the habit of pressing Ctrl-S without thinking and when CMake runs in the background for 30 seconds it becomes quickly annoying.

The second option means that Qt Creator will initially configure the project in a temp directory, and when you build the project, it will start from scratch and configure the project again with the build directory.

I like to have less CMake project configure runs and no surprise CMake configure runs by setting up CMake the other way around:



Blog Topics: