CMake support

CMake remains the project model that’s most deeply integrated into CLion.

CMake project

Open CMake project

Any CMake-based projects can be opened easily in CLion, with no additional configuration needed:

  • point it to the root CMakeLists.txt file in your project sources, or
  • point it to the existing generation folder or CMakeCache.txt files (this works only for Makefiles generator).

Mark directory as

In case you'd like to mark directories manually as libraries or project sources/headers, or exclude some directories (i.e. independently from the CMake project structure), you can do this with the Mark directory as feature. This will affect indexing (for example, you can exclude build directories, binaries, logs and generated data from indexing), along with code generation, refactorings and navigation. Find more details.

CMake env variables completion

Detect CLion

If you need to detect that CMake command on your project was run from CLion (and if so, set special variables/paths or execute some additional scripts of your choice) use CLION_IDE environment variable. To make it easier to find it, CLion provides you with the environment variables completion.

Add/delete files

When adding a new file, CLion suggests to add it to the CMake target.

When deleting files from the project, CLion removes the file reference from the command arguments, or warns you about a possibly incorrect command after deletion.

CMake project

Import Project

You can also import non-CMake projects (File | Import Project...), for which CLion will generate a CMakeLists.txt file.

CMake generators

Support for the CMake File API lets CLion enable various CMake generators. Users can select Ninja, Xcode, Visual Studio, etc. This works for all platforms, in remote mode, and with WSL.

Learn more

CMake configuration

CMake Profiles

With CMake profiles (Build, Execution, Deployment | CMake) you have control over CMake generation directory, CMake configuration types, CMake options and environment variables, etc.

Create any necessary number of CMake profiles from scratch, or copy existing ones (with all the settings pre-filled). Store your project build configuration in new and universal CMake Presets, and CLion will automatically detect and import the necessary CMake Presets into CMake Profiles.

Switch between CMake profiles in the run configuration switcher on the toolbar or in the Run (Shift+Alt+F10)/Debug (Shift+Alt+F9) configuration switcher popup.

CMake tool window and CMake Cache

CMake tool window includes the CMake output logs, that can be used to track the progress and debug CMake scripts.

You can review CMake cache variables and update CMake options that are passed to the CMake command in a single table-based UI in Settings | Build, Execution, Deployment | CMake.

When the table is in focus, start typing to search for a variable or its value. CLion also shows the short description in tooltips for CMake cache variables.

CMake menu

Go to Tools | CMake for useful CMake-related actions:

  • Reload CMake Project can be used to apply the latest CMake changes and force CLion to reload the project to reflect them in the editor (automatic reloading can be enabled in Build, Execution, Deployment | CMake settings).
  • Change Project Root is useful in case your project root directory differs from the directory where the top-level CMakeLists.txt is located.
  • Reset Cache and Reload Project allows you to clear the CMake Cache without dropping all of IDE indexes and caches.

Smart CMake support

CMake Comments

Rename in CMake

If you use Rename refactoring Shift+F6 to rename user symbols in CMake (like functions or macros), all the usages will be updated automatically.

CMake Install

If you have any CMake install targets in your project, you can call Install from the CLion’s Run menu now. The cmake install command will be executed. Alternatively, you can add an Install step to any of your run configurations in CLion.

CMake Comments

CMake Comments

CLion supports CMake 3 bracket-arguments and block comments syntax. To quickly comment a line in CMake, you don’t need to select it — simply put the caret on it and press Ctrl+/ . To comment a block, select it and press Ctrl+Shift+/.

Code assistance in CMakeLists.txt

The CMake file editor in CLion helps you edit CMakeLists.txt files more easily. This includes:

  • CMake font and color settings.
  • The ability to expand and collapse various code regions in CMake.
  • Code completion for CMake commands and variables.
  • Code completion for find_package for packages bundled with CMake.
  • CMake command documentation in code completion.
  • CMake structure view.
  • Strikethrough highlighting of deprecated commands in CMake.
CMake completion, code generation and automatic actions

Code generation in CMake

Create frequently-used or custom code constructs in CMake and reuse them with live templates. Select between predefined templates or create your own.

To use the template, type its abbreviation (you can use auto-completion here as well) and then press Tab (or any non-default key you’ve configured) to expand the template.

After you finish editing, a banner shows up where you can choose to reload the current project manually, or enable automatic reload on every edit.

Quick Doc in CMake

Quick Documentation in CMake

The Quick Documentation popup is now available in CMake scripts. The documentation is shown for the standard CMake entities:

  • Commands
  • Policies
  • Modules
  • Variables
  • Properties

Documentation is always rendered for the currently bundled CMake version and is not available for the user-defined entities for now.

CMake debugging

CMake Debugger

Since CMake is a language of build systems, investigating errors and catching suspicious behavior in a CMake script is not always easy. You can debug CMake scripts in CLion as regular code. Set breakpoints, step through code, and watch CMake variables and targets. Learn more.

CMake profiling

CMake profiling

In CLion, you can visually inspect why it takes a long time to reload your CMake project. Starting with CMake 3.18, the new tracing can be enabled in the CMake settings. CLion will help you run the tracing and visualize the results. Learn more.