CLion 2019.3 EAP: Ninja or Another Generator of Your Choice in CMake
A new CLion 2019.3 EAP (build 193.4697.8) is now available! Get it from our website, via the Toolbox App, or as a snap package (if you are using Ubuntu). A patch-update for anyone using the previous EAP build will be available shortly.
CMake remains the most deeply integrated project model in CLion. However, from the very beginning, we supported only the Makefiles generator. This limitation was caused by the fact that CLion was parsing the output of CMake command run with parameters such as -G “CodeBlocks – Unix Makefiles”, -G "CodeBlocks – MinGW Makefiles", or -G "CodeBlocks – NMake Makefiles" to get information about the project, which made it impossible to change the generator used.
This obviously caused some problems:
- Ninja is known to be a much faster generator and is one of the most requested alternatives (CPP-2659).
- With the Visual Studio toolchain, CLion was using something very similar to Makefiles – NMake, but the community expected Visual Studio CMake generators (CPP-14730).
As a solution, we considered supporting the CMake server first, but later found a better alternative – the new CMake File API, which was added by the CMake authors as a new and better way to query project information. And now, we are happy to present to you the new CLion 2019.3 build with this new API supported!
In practice, this gives you an opportunity to use any CMake generator of your choice!
Let’s look at the details.
How can I change the generator?
A very simple action is required to change the generator – just go to the CMake Profile settings in Settings / Preferences | Build, Execution, Deployment | CMake and pass the generator name in the CMake options, for example, -G Ninja:
This works for all platforms, remote mode, and the WSL, and for all generators supported by CMake (Ninja, Xcode, Visual Studio, and Makefiles). And you can use different generators in different CMake Profiles if necessary.
There are, however, a few things to bear in mind:
- While CMake File API first appeared in CMake 3.14, CLion supports the feature only with CMake 3.15 or higher. (Currently, CMake 3.15.3 is bundled into the 2019.3 EAP builds, so you don’t have to install anything additionally, if you simply rely on a bundled version.)
- Make sure you have the generator itself installed on your machine (like Ninja, for example).
- Recompiling individual files is not supported in cases where the generator was changed as CLion can’t restore the build rules information easily (CPP-17622).
How do build type settings work for multi-configuration generators?
Xcode and Visual Studio are so-called multi-configuration generators, which means the project files for all build types will be generated by CMake. However, CLion will only use the build type specified in the CMake Profile settings for indexing and the actual building (in the build command line arguments, you can find the proper config is passed by CLion, for example: –config Debug).
That’s it for today! The full release notes are available here.
Your CLion Team
The Drive to Develop