Tobias Hunger

Update on CMake project support in Qt Creator

Published Tuesday July 30th, 2019
10 Comments on Update on CMake project support in Qt Creator
Posted in QtCreator | Tags: ,

I have been busy improving the CMake support in Qt Creator for the last couple of weeks and thought I should take the time to highlight some of the new features.

Fileapi support

The CMake project has announced a new IDE integration mechanism with their 3.14 release called fileapi. It provides about the same level of information as the previous recommended mechanism (server-mode), but does not require a long-running cmake process. This makes the new approach use less resources while being more robust in the face of users running cmake on the command line.

“fileapi” is now supported in Qt Creator (master branch).

Demo of CMake releated features in Qt Creator master

Demo of CMake releated features in Qt Creator master

CMake support in the Locator

Creator has allowed to trigger the build of CMake targets via the locator for a while now. Simply do Ctrl-K to focus the locator and then type cm <target> to build that target.

In master branch this got a small extension: Typing cmo <target> will open the definition of a target in the editor. This works best when your CMake binary supports fileapi: It will then take you to the exact line the target is defined at. Older CMake binaries will just open the CMakeLists.txt file in the target’s source directory instead as there is no information on line numbers available.

Open targets via the Context menu

The same information that is used by the cmo locator is used to populate a Open... menu in the target’s context menu. That allows to jump straight to lines relevant to the target definition.

Note that this feature has been available for one specific CMake version with server-mode support before, but the necessary support in CMake got removed again and only returned in the fileapi.

That is all I have to show today:-) Please test Qt Creator with CMake 3.14 or later and provide feedback and report bugs. Unfortunately there are currently no snapshots of Qt Creator taken from the master branch, those will only become available after Qt Creator 4.10RC release.

Thanks to Alessandro for demoing these features in a short video!

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in QtCreator | Tags: ,


Juergen says:

Hi Tobias
thanks for the overview.
In the gif it says QtCreator 4.11.
Seems to me that you skipped version 4.10 πŸ˜‰

Cheers Juergen

All the code hit the Qt Creator master branch after 4.10 was already branched off. Since there are quite a few changes involved I do not feel comfortable to backport this into 4.10 this close to release.

So sorry for missing Qt Creator 4.10.

Carl says:

Anything you can do to build things faster is super.

I am trying to convert users from qmake to cmake and speed seems to be the biggest issue.

I check for a blog post announcing it release frequently. Looking forward to playing with the RC version πŸ™‚

Philip S says:

QBS is super speedy compared to cmake. To bad support for it is being dropped.

Richard W says:

Qbs support in QtCrearor is not being dropped, but Qt Company stopped to actively develop it. It will only be removed if it causes build issues. Since both Qbs and QtCreator are open source, everybody can contribute. Please do so if you like Qbs and make sure that it keeps working and becomes even better. Thanks.

The merits of one build tool over the other is not too relevant here: Qt Creator needs to support all the major tools out there.

And whether or not you like CMake, you surely will agree that it is a major tool in the C++ world.

Carl says:

My intent was not to start a flame war. Is it time to finally let this feud go to bed?

For me CMake seems to be the most universal of all build systems across all platforms I deal with. With CMake I can couple it with Conan (C++ package manager) and compete with Python and Pip/Conda. Yes I know QMake and QBS do this too … but spreading resources cuts down on overall progress.

Frankly CMake may not be the best, but it does get the job done. I can take somebody who is working with FORTRAN 2005, teach them CMake… and when they transition to C++. Their CMake comes with them.

Yes the world still uses FORTRAN ….and be grateful for that, the next time you board and aluminum tube that goes 525 MPH at 30k feet … the heavy lifting of CFD is often done in FORTRAN

Philip Schuchardt says:

@Carl and @Richard W, I would rather see this discussion go in a more positive direction. I guess I’m sorta frustrated at the current build system landscape. Originally, at our company, we used Makefiles and QMAKE to build our software. It was painful. And required multiple build steps to create our software. I set off to create something better. CMAKE was the clear choose, but unfortunately at that time, it had no QtCreator support. I ported it anyways. It worked, but I wouldn’t say I enjoyed working on it. The syntax is painful and if I wanted to do anything custom, it took so long to develop. Perhaps I was using it wrong. Then QBS came out, I was pretty excited about how it worked and the syntax. QML declarative nature is prefect for implementing a build system. Also the Artifact {} and Rule {} are amazing for setting up some custom build pipeline. I wouldn’t say using it over the years has been perfect. Most new versions of QBS required changes to our build system and the documentation has been lacking, but it seemed to get better. Currently QBS is in a much better state. I just recently upgrade our build system from QBS 1.9.1 to 1.13.1 and it was pretty smooth. The documentation is much much better. I’m just afraid that QBS support will eventually be dropped from QtCreator. I really like QBS, but I’m not sure if time to support it in QtCreator or help make new QBS releases. I also compile FORTRAN using QBS. I’ve even had the green light to contribute our Fortran module to the QBS project. I haven’t done it since I just don’t have time. It’s really cool that there’s better CMAKE support. I’m just not looking forward to porting our build system back to CMAKE. The last time I opened a CMAKE project in QtCreator, it was super slow, but that looks like it’s getting fixed! Which is awesome! I do personally hope that QBS continues to live on.

filcuc says:

Amazing work as always!! CMake support is getting better at every release!! Thumbs up from me!! Regarding this new file api approach by quickly reading the cmake doc it seems that client must do a reconfigure step for submitting a new query. Isn’t it too heavy for big projects? In theory the cmake server solution seemed a more lightweight solution but I could be wrong…your thoughts? Thank you again!!!!

CMake must be run again to refresh the data. That is usually pretty fast since it most data will be cached — just like when you run a plain “cmake” on the command line. Note that running cmake on the commandline will also refresh the data, so Creator should not need to run cmake again (currently it probably will though, I need to fix that).

In server-mode you also need to redo the configuration and generation steps whenever creator suspects something has changed. You just need to send the relevant commands to to the already running server so that it does exactly the same thing — or you have to restart the server altogether to make it pick up e.g. changes in the environment.

Server-mode has more complex error conditions: You need to have code to handle crashing a crashing cmake server and to handle cmake going into an endless loop (you want the user to be able to break out of that somehow instead of freezing the UI forever;-). File-api allows for more robust handling of these error conditions.

Overall the potential for problems is much smaller with file-api than it is with server-mode. CMake does not lock the build directories it writes into, so running a cmake on the command line while the cmake server is running might actually break build directories. That risk is much smaller with file-api since there is no more long-running process.

Commenting closed.

Get started today with Qt Download now