CMake remains the project model that’s most deeply integrated into CLion.
Any CMake-based projects can be opened easily in CLion, with no additional configuration needed:
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.
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.
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.
You can also import non-CMake projects (File | Import Project...
),
for which
CLion will generate a CMakeLists.txt file.
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 moreWith 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 includes the CMake output logs, that can be used to track the progress and debug CMake scripts.
It also allows to open a CMakeCache.txt file right in the editor for further editing, like for example adding new variable to it.
Go to Tools | CMake
for useful CMake-related actions:
Build, Execution, Deployment | CMake
settings).
If you use Rename refactoring Shift+F6 to rename user symbols in CMake (like functions or macros), all the usages will be updated automatically.
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.
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+/.
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.
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.