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
-DBUILD_PLUGIN_ANDROID=OFF -DBUILD_PLUGIN_AUTOTEST=OFF -DBUILD_PLUGIN_AUTOTOOLSPROJECTMANAGER=OFF -DBUILD_PLUGIN_BAREMETAL=OFF -DBUILD_PLUGIN_BAZAAR=OFF -DBUILD_PLUGIN_BOOT2QT=OFF -DBUILD_PLUGIN_CLEARCASE=OFF -DBUILD_PLUGIN_CVS=OFF -DBUILD_PLUGIN_EMACSKEYS=OFF -DBUILD_PLUGIN_FAKEVIM=OFF -DBUILD_PLUGIN_GENERICPROJECTMANAGER=OFF -DBUILD_PLUGIN_HELLOWORLD=OFF -DBUILD_PLUGIN_INCREDIBUILD=OFF -DBUILD_PLUGIN_IOS=OFF -DBUILD_PLUGIN_MARKETPLACE=OFF -DBUILD_PLUGIN_MCUSUPPORT=OFF -DBUILD_PLUGIN_MERCURIAL=OFF -DBUILD_PLUGIN_MESONPROJECTMANAGER=OFF -DBUILD_PLUGIN_NIM=OFF -DBUILD_PLUGIN_PERFORCE=OFF -DBUILD_PLUGIN_PYTHON=OFF -DBUILD_PLUGIN_QBSPROJECTMANAGER=OFF -DBUILD_PLUGIN_QMLDESIGNER=OFF -DBUILD_PLUGIN_QMLJSEDITOR=OFF -DBUILD_PLUGIN_QMLJSTOOLS=OFF -DBUILD_PLUGIN_QMLPREVIEW=OFF -DBUILD_PLUGIN_QMLPREVIEWPLUGIN=OFF -DBUILD_PLUGIN_QMLPROFILER=OFF -DBUILD_PLUGIN_QMLPROJECTMANAGER=OFF -DBUILD_PLUGIN_QNX=OFF -DBUILD_PLUGIN_QTQUICKPLUGIN=OFF -DBUILD_PLUGIN_REMOTELINUX=OFF -DBUILD_PLUGIN_SERIALTERMINAL=OFF -DBUILD_PLUGIN_STUDIOWELCOME=OFF -DBUILD_PLUGIN_SUBVERSION=OFF -DBUILD_PLUGIN_WEBASSEMBLY=OFF -DBUILD_PLUGIN_WINRT=OFF -DBUILD_EXECUTABLE_QML2PUPPET=OFF -DBUILD_EXECUTABLE_QTPROMAKER=OFF -DBUILD_EXECUTABLE_WINRTDEBUGHELPER=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:
- Use a command line script which would configure the project and then import it in Qt Creator.
- Create a Qt Creator Kit, which would have all the settings in the CMake Configuration field.
- Manually select all the options in the CMake project settings. This would add the values in the
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
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:
- Clean Project “Qt Creator”. This will execute the
cleanninja target, which will remove the build artifacts (*.obj, *.dll, *.exe)
- Clear CMake Configuration. This will remove the
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:
Subscribe to our newsletter
Try Qt 6.1 Now!
Download the latest release here: www.qt.io/download.
Qt 6 was created to be the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu