CMake support in Qt Creator (and elsewhere?)
Kitware released CMake version 3.7 on Friday night. There is one feature mentioned at the very bottom of the feature list that makes this a really exciting release for people writing tools that integrate with CMake: The server-mode.
What is CMake server-mode?
The Qt Creator team has had contact with the CMake community for a long time now and was actively involved in discussions with CMake and other IDE and tools vendors. After many discussions the CMake community decided that the best way forward to support the use-cases of IDEs was to add a new interactive way to interact with CMake, the so called server-mode. There was some initial development started by Stephen Kelly, who made an impressive prototype.
At this point the Qt Creator team decided that this functionality is crucial to enable first class CMake support in Qt Creator. So I went ahead and jumped into CMake development. The result is a set of patches that implement a production-ready server-mode for CMake that was merged in time for the CMake 3.7 release. The server-mode currently focuses on core functionality like parsing the project structure, etc.
This development happened in close collaboration with developers from KDevelop and the CMake community.
I am committed to maintain CMake server-mode support going forward and hope to continue to develop this feature in close collaboration with all interested parties.
CMake version 3.7 is the first release that ships this code.
What does CMake 3.7 enable?
The first change in CMake 3.7 is that it now provides machine-readable output with basic information about the capabilities of the CMake binary (via "cmake -E capabilities").
This includes static information like version number or whether server-mode is available, but also details on the supported generators.
IDEs can use this information to provide a better UI for selecting generators.
CMake server-mode (started via "cmake -E server") allows IDEs to query a range of CMake settings and project information in a machine-readable form, many of which were not available to IDEs before. This enables a more detailed view of the CMake project.
The information is also taken from CMake directly, making sure to use the same code that is also used by the CMake generators to write the actual build-system files. So the information is more accurate than what was available before. This makes the code model more exactly represent what is actually going to be built.
When will we see these improvements in action?
I think the server-mode is the way forward for all tools that need to extract information from CMake. Interest in this topic seemed very strong in my workshop about CMake at QtCon this year. I hope to see CMake server-mode flourish going forward.
There is code that makes use of the new CMake 3.7 features in the master branch of Qt Creator. So this will be present in Qt Creator 4.3, planned for spring of 2017.
What will improve in Qt Creator?
Creator will continue to support any CMake version 3.0 (or later), just as current versions of Qt Creator do. But Qt Creator master does support CMake server-mode already and will make use of the better information. You will be able to switch between CMake binaries with and without server-mode support as needed.
Using CMake server-mode enabled binaries will have the following effects:
- Generator selection is no longer limited to those generators with support for the "CodeBlocks" extra generator. Any generator can now be used.
- The Generator selection UI now knows which options are available for each generator. E.g. the "Ninja" generator used above does not support Toolsets or Platform settings.
- The project tree is much improved and knows about projects and build targets defined in CMake.The screenshots show the project tree from Qt Creator 4.2 and from Qt Creator master -- with an old CMake and with CMake server-mode.
Qt Creator master adds all headers found in include paths of a build target and not listed in the CMakeLists.txt to the project tree (for all versions of CMake). These headers are printed with a grey text color so they can be distinguished from sources known to CMake.
In server-mode the project structure is more visible: The "scribus" project defined in the top-level CMakeLists.txt file is clearly visible. So are the different build targets. The "scribus_colormgmt_lib" build target is expanded and all files belonging to that target are listed.
- The code model has way more accurate information about all targets. This sounds very simple, but has not always been the case for CMake projects up to now.
What will happen next with CMake server-mode?
Stephen Kelly has pioneered interesting features in his CMake server-mode implementation prototype. Many did not make it into the new CMake release.
Going forward I would like to see more of these powerful features. This includes debugging of CMakeLists.txt files and syntax highlighting driven by CMake itself. These require deep integration into CMake and will require a much deeper understanding of CMake internals than I currently have. So I hope CMake developers find the server-mode interesting enough to help out a bit here and there:-)
I would like to say thanks to Aleix Pol (KDevelop) and Stephen Kelly (CMake community) for all the feedback they provided. Finally I have to thank Brad King from Kitware for his patience while reviewing my code.
Where can I get this?
Get CMake 3.7 here: https://cmake.org/download/
View the Qt Creator master sources: https://code.qt.io/cgit/qt-creator/qt-creator.git/
Or use git to clone the code:
git clone git://code.qt.io/qt-creator/qt-creator.git
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.
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