CMake support

All work in CLion is done within the context of a project, which serve as the basis for coding assistance, bulk refactoring, coding style consistency, and other smart features. CLion uses the CMake project model.

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).

Import Project

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

CMake project

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.

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.

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:

CMake env variables completion

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). In case you have custom build types created by the setting CMAKE_CONFIGURATION_TYPES, they will appear in the Build type drop-down as well.

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:

CMake Window

It also allows to open a CMakeCache.txt file right in the editor for further editing, like for example adding new variable to it.

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

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 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+/:

CMake Comments

CMake completion

While editing CMake files in CLion, you can use auto-completion for CMake commands and variables (only for variables with static names). Auto-completion for CMake variables works in set/unset commands or after ${ and supports both Middle matching and Snake matching, as usual:

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:

CMake completion, code generation and automatic actions

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.