CLion starts 2021.2 EAP: CMake Presets, New Project Templates, Lifetimes Analysis, and Cling support
The CLion 2021.2 EAP program has now begun! The first EAP build is ready for you to try out. If you want to know what we are working on in particular during this release cycle, please read this roadmap blog post.
EAP builds are free to use, but might be unstable and of lower quality. The main goal of these builds is to let our users evaluate the features which will be added to the next release and share their feedback at early stages. These builds also can be used to test the changes in rare and very specific environments, which are hard to cover from our side.
Build 212.3116.34 is available from our website via the Toolbox App, or as a snap package (if you are using Ubuntu). Note that if you are on macOS, there is a separate build for Apple Silicon (M1 chip).
Check out the main highlights and read the post for more details:
- CMake enhancements:
- Support for v3.20
- Load CMake Presets action
- Templates for the new CMake projects
- Ability to execute CMake target before launching Run configuration
- Lifetimes analysis
- Cling support
- WSL enhancements:
- Removing requirement for SSH server inside a WSL distribution
- Support for custom WSL distributions
- Text search in Local History
CMake 3.20 is now supported and bundled in CLion. This version includes CMake Presets, major updates to CMake File API, support for C++23 compiler modes, and many updates for CUDA developers.
CMake Presets are a new way to configure CMake options and share them with others. It’s all thanks to two files:
- CMakePresets.json is meant to save project-wide builds, and may be checked into VCS.
- CMakeUserPresets.json is meant for developers to save their own local builds, and should not be checked into VCS.
CLion, on the other hand, operates with CMake Profiles – entities which are specific to CLion but have many settings in common with the CMake Presets and are also shareable via VCS. The major difference is that they reference CLion toolchains, which shouldn’t be mixed with the CMake toolchains. They serve different purposes and CMake toolchains can’t cover CLion use cases. The CLion toolchain serves other project models and contains information that is not present and not needed in the CMake toolchain, like the debugger and environment settings (remote host, WSL, etc.).
Now that we’ve explained the difference, we’d like to announce that CLion now supports importing information from CMake Presets. This is just the first step toward CMake Presets support in CLion and we are eager to hear your feedback on how we are doing.
The Load CMake Presets action (use Find Action via Ctrl+Shift+A/⇧⌘A to find it by name) searches through the existing Build Presets and shows them in the popup:
When selected, CMake Preset is imported into CLion CMake Profiles read-only mode. You can review the list of profiles in Settings/Preferences | Build, Execution, Deployment | CMake.
Known limitations and further plans:
- Imported presets are read-only. However, you can open the corresponding JSON files, edit them in CLion, save the file (currently, autosave is not supported – CPP-25076) and reload the preset in CLion.
- CLion at present supports only version 2 presets and only buildPresets.
- After importing, CMake Preset in CLion gets a link to the CLion toolchain. For now, it’s the Default toolchain, but later we’ll provide a way to configure it.
- Other issues logged as subtasks to this one.
- The general task for supporting CMake Presets in CLion is much wider (CPP-22906) and will likely include a way to update presets from CLion UI.
CMake Project Templates
In addition to the CMakeList.txt file template for a new file, CLion now also provides editable templates for new CMake projects. You can find them in Settings/Preferences | Editor | File and Code Templates | Other:
C and C++ libraries and executables, CUDA libraries and executables, and Qt projects are available there. These templates are used when you create a new project via the File | New Project wizard.
CMake targets as Before Launch tasks
In the Before Launch section of the Run/Debug configuration, users can specify the tasks to be performed before starting the selected target. By default, there is a Build step there. You can now add a CMake Target task in this phase to execute the CMake target:
Both built-in (like for example, all, clean, install) and user-specified (created via add_executable or add_custom_target) targets will be suggested:
According to the C++ Foundation Developer Survey, memory safety issues like use-after-free/delete are among the top points of frustration for C++ developers. The Lifetime Safety proposal is trying to address these issues in the C++ language. The idea is to diagnose common cases of dangling pointers and references (use-after-free, use-after-move) at compile time, by using local analysis. Local analysis uses the concepts of Owners, Shared Owners, and Pointers. The GSL library brings annotations to mark the code and help local analysis.
The proposal is still under discussion, but there is an experimental Clang branch supporting some ideas from the proposal, and Today Lifetime analysis comes to CLion!
For example, here CLion warns you about the string view referencing an invalid object after the temporary string is destroyed:
Various cases of local variables pointing to memory which is out of scope are also caught by CLion:
GSL annotations are also supported in the analysis:
The analysis runs in the scope of the function body. While it doesn’t catch all the issues, it can already help significantly with one of the most troubling C++ issues.
You might not expect it, but there is an interactive C++ interpreter, Cling (check out its GitHub page), built on top of Clang and LLVM. It’s really useful for prototyping and learning C++. You can find a short video here which explains the basics of working with Cling.
With this EAP, Cling is now supported in CLion! To start with Cling in CLion, download the cling executable for your platform or install it via your OS-specific dependency manager (like brew on macOS), and configure a path to it in Settings/Preferences | Languages & Frameworks | C/C++ | Cling. It will be autodetected by CLion if Cling is in PATH.
You are ready to go! In the Tools menu, you will find the related Cling actions, or you can call them from Find Action.
For lines of code, an intention is available that sends the current line to the Cling session:
You can select several lines, press
Alt+Enter, and send the whole selection to Cling. You can also just load a whole file to Cling, or simply type code directly in the Cling terminal:
There are a few known limitations worth mentioning:
- Users can’t add extra arguments to the Cling executable starting from within CLion for now, so you can’t really change the C++ language standard or other options.
- Project flags are not passed to the Cling session (CPP-25256). This might cause an issue with some included paths not known to Cling.
- The Cling session is started within the project directory or within the home directory (if no project is currently open). The relative paths might not be handled correctly when sending a current line to Cling from a file that is not in the project root..
CLion now supports WSL installed not only from the Microsoft Store, but also from custom distributions. The IDE shows all imported WSL distributions in the drop-down list on the dedicated Toolchains settings page (the list is the same as the one returned by the
wsl -l -v command).
Text search in Local History
If your project is not under version control, you are still safe from any bad changes (like deleted files). With Local History you can roll back to any past state of a file, even if no version control is enabled for your project. It allows text search through the file revisions so that you can locate the point you want to rollback to more easily.
- This build addresses several IDE freezes, specifically related to copy-pasting activities.
- A few new MISRA checks are added.
- Starting from this EAP, it is possible to navigate back and forth between open sections in Preferences/Settings. To do so, use the arrows in the right-hand corner of the window.
- The difference between the initial and changed files is now always displayed in the editor, regardless of how you invoke the Show Diff action. If you find it more convenient to track changes in a separate window, you can drag the desired file from the editor. If you do, the IDE will remember this and will open future diffs in a separate window.
- It’s now easier to code with the enabled screen reader mode on macOS – a list of available suggestions for code completion is now read out loud.
The full release notes are available here.
Your CLion team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
CLion 2023.3 Release Candidate
CLion 2023.3 is on its way, and the release candidate for v2023.3 is already available! To install CLion 2023.3 RC (build 233.11799.171), download it from the website, update via the Toolbox App, or use this snap package (for Ubuntu). You need an active subscription or a trial license to use CLi…
CLion Nova: A New Update With Various Bug Fixes
CLion Nova, a free preview of CLion with the ReSharper C++/Rider C++ language engine, was announced recently. We’re excited to see how well you liked the first build! There are about 3,700 users right now and the overall feedback is mostly positive, especially that which is related to performance an…
CLion 2023.3 Goes Beta
The Beta version of CLion Classic 2023.3 is now available with key improvements and changes that are expected in the upcoming release. Download build 233.11799.37 from our website, via the Toolbox App, or as a snap package for Ubuntu. If you are using CLion Nova, note that we do not plan to release…
CLion Nova Explodes onto the C and C++ Development Scene
TL;DR Today, we’re announcing a free early preview of CLion, which uses the ReSharper C++/Rider C++ language engine instead of the CLion "legacy" engine. The Preview build is available via our dedicated Toolbox App feed. At some point in 2024, depending on the results of the feedback coll…