# CMakeLists.txt

`CMakeLists.txt` file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both).

When you [create a new project](creating-new-project-from-scratch.html), CLion generates `CMakeLists.txt` file automatically and places it in the project root directory. To [open](creating-new-project-from-scratch.html#open-prj) a project, you can point CLion to the top-level `CMakeLists.txt` and choose Open as Project.

Example below shows the `CMakeLists.txt` file of a simple "Hello, World" project:

```CMAKE
cmake_minimum_required(VERSION 3.20)  # CMake version check
project(simple_example)               # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14)            # Enable c++14 standard

# Add main.cpp file of the project root directory as a source file
set(SOURCE_FILES main.cpp)

# Add executable target with source files listed in SOURCE_FILES variable
add_executable(simple_example ${SOURCE_FILES})
```

> **Note:**
> CMake versions earlier than 3.15 are not supported. If you switch from the bundled CMake to a custom installation, make sure it is version 3.15 or newer.

You can edit `CMakeLists.txt` files right in the editor. Make sure to [reload](reloading-project.html) the project after editing. Automatic reload feature is disabled by default, you can turn it on by setting the Automatically reload CMake project on editing checkbox in `Settings | Build, Execution, Deployment | CMake`.

## Subdirectory CMakeLists.txt files

For projects with complex structure, you can create subdirectory `CMakeList.txt` files to describe the build, contents, and target rules for the subproject.

The type of the target added by the subdirectory `CMakeLists.txt` can vary depending on the role of the module.

![CMakeLists.txt files in subdirectories](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmakeListsFiles.png)

## CMakeLists.txt file templates

When you create a CMake or CMake-based ([CUDA](cuda-projects.html), [Qt](qt-tutorial.html)) project via the New Project wizard, CLion uses different templates to generate `CMakeLists.txt` depending on the project type and settings. You can fine-tune these templates in `Settings | Editor | File and Code Templates`, the Other tab:

![File templates for new CMake projects](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_templates_newprj.png)

When editing a template text, you can use common [predefined variables](file-template-variables.html) and the following CMake-specific variables:

| ${CMAKE_DEFAULT_PROJECT_FILE} | the `main.cpp`/`main.c`/`libary.cpp`/`library.c` file of the project. |
| ${CMAKE_LANGUAGE_VERSION} | the selected language standard. |
| ${CMAKE_MAJOR_VERSION} | the major number of the minimum supported CMake version. For example, if the version if `3.20`, this variable corresponds to `3`. |
| ${CMAKE_MINOR_VERSION} | the minor number of the minimum supported CMake version. For example, if the version if `3.20`, this variable corresponds to `20`. |
| ${CMAKE_LIBRARY_TYPE} | `SHARED` for shared libraries. |
| ${QT_VERSION} | the selected Qt version. |
| ${REQUIRED_LIBS} | the Qt libraries required for the selected project type. By default, they are `Core` for Qt Console Executable and `Core`, `Gui`, `Widgets` for Qt Widgets Executable. |

There is also a template for CMake scripts that you can add to an existing project via `New | CMakeLists.txt` in the context menu of the project view. By default, this template is empty. You can edit it using the same variables in `Settings | Editor | File and Code Templates`, the Files tab:

![File template for a new CMakeLists.txt file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_template_newcmakelists.png)

## Coding assistance in CMakeLists.txt

### Code completion

CLion provides code completion for most of the elements in your `CMakeLists.txt`. For example, you can get the list of the packages bundled with CMake when writing a `find_package()` command:

![Completion in CMake](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_findpackage_completion.png)

### Quick fix for CMake minimal version

You can quickly adjust the minimal required version of CMake. Locate the warning in CMake output and click Fix:

![Quick fix for CMake minimal version](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_version_quickfix.png)

CLion will change the version in the `cmake_minimum_required()` command:

![CMake minimal version changed](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_version_fixed.png)

### Adding targets via the Generate menu

Procedure:

1. Press `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Alt+Insert` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `⌘ N` (Xcode), `Alt+Insert` (Visual Studio), `⌘ ⌃ N` (Visual Studio (macOS)), `Alt+Insert` (ReSharper), `⌘ ⌃ N` (ReSharper (macOS)), `Alt+Insert` (QtCreator), `Alt+Insert` (QtCreator (macOS)), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)) and select the target type:

![Generate menu for CMake](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_generatemenu.png)

2. Choose the files to be added to the new target:

![Choose target files](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_generate_choosefiles.png)

3. CLion will add an `add_executable` or `add_library` command:

![The result of adding a library target via the Generate menu](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_generate_lib_result.png)

### Live templates for CMake

Use [live templates](using-live-templates.html) to quickly insert a structure or a command. For example, type `exe` and press `Tab` (Windows), `⇥` (macOS), `⇥` (IntelliJ IDEA Classic (macOS)), `⇥` (macOS System Shortcuts), `Tab` (XWin), `Tab` (GNOME), `Tab` (KDE), `Tab` (Emacs), `Tab` (Sublime Text), `⇥` (Sublime Text (macOS)), `⇥` (Xcode), `Tab` (Visual Studio), `⇥` (Visual Studio (macOS)), `Tab` (ReSharper), `⇥` (ReSharper (macOS)), `Tab` (QtCreator), `⇥` (QtCreator (macOS)), `Tab` (NetBeans), `Tab` (Eclipse), `⇥` (Eclipse (macOS)) to add an executable target:

![CMake live template for add_executable](https://resources.jetbrains.com/help/img/idea/2026.2/cl_livetemplates_cmake_exe.png)

![add_executable template inserted](https://resources.jetbrains.com/help/img/idea/2026.2/cl_livetemplates_cmake_exe_result.png)

Find the full list of CMake live templates in `Settings | Editor | Live Templates | CMake`.

### Parameter info popup

The Parameter Info popup shows signature variants for CMake commands as you type:

![Parameter info for CMake](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_paraminfo.png)

By default, the popup appears within 1 second (1000 milliseconds) after you type an opening bracket. You can change this in the [Parameter Info settings](viewing-method-parameter-information.html#configure-parameter-info-popup).

To invoke parameter info manually, press `Ctrl+P` (Windows), `⌘ P` (macOS), `⌘ P` (IntelliJ IDEA Classic (macOS)), `⌘ P` (macOS System Shortcuts), `Ctrl+P` (XWin), `Ctrl+P` (GNOME), `Ctrl+P` (KDE), `Alt+Shift+P` (Emacs), `Ctrl+P` (Sublime Text), `Ctrl+P` (Sublime Text (macOS)), `⌘ ⇧ P` (Xcode), `Ctrl+Shift+Space` (Visual Studio), `⌘ P` (Visual Studio (macOS)), `Ctrl+P` (ReSharper), `⌘ P` (ReSharper (macOS)), `Ctrl+P` (QtCreator), `Ctrl+P` (QtCreator (macOS)), `Ctrl+P` (NetBeans), `Ctrl+P` (Eclipse), `⌃ ⇧ Space` (Eclipse (macOS)).

### Quick documentation popup

[Quick Documentation popup](viewing-inline-documentation.html) helps you get more information on the elements in your CMake code. To invoke it, use mouse hover or press `Ctrl+Q` (Windows), `F1` (macOS), `⌃ J` (IntelliJ IDEA Classic (macOS)), `⌘ I` (macOS System Shortcuts), `Ctrl+Q` (XWin), `Ctrl+Q` (GNOME), `Ctrl+Q` (KDE), `Ctrl+Q` (Emacs), `Ctrl+Q` (Sublime Text), `Ctrl+Q` (Sublime Text (macOS)), `⌘ ⌃ ⇧ /` (Xcode), `Ctrl+K, I` (Visual Studio), `⌘ K, I` (Visual Studio (macOS)), `Ctrl+Q` (ReSharper), `⌃ Q` (ReSharper (macOS)), `Ctrl+Q` (QtCreator), `Ctrl+Q` (QtCreator (macOS)), `Ctrl+Q` (NetBeans), `Alt+Middle-Click` (Eclipse), `⌥ Middle-Click` (Eclipse (macOS)).

For example, you can view quick documentation for completion suggestions:

![Quick doc in CMake completion](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_quickdoc_completion.png)

### Code folding

Folding/unfolding in CMake scripts is available for macros and functions, if-else clauses, blocks, comments, as well as arbitrary code selections (make sure to enable Custom folding regions in `Settings | Editor | General | Code Folding` for this to work).

![CMake code folding](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_folding.png)

> **Tip:**
> Press `Ctrl+NumPad -` (Windows), `⌘ NumPad -` (macOS), `⌘ NumPad -` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad -` (macOS System Shortcuts), `Ctrl+NumPad -` (XWin), `Ctrl+NumPad -` (GNOME), `Ctrl+NumPad -` (KDE), `Ctrl+NumPad -` (Emacs), `Ctrl+Shift+[` (Sublime Text), `⌘ ⌥ [` (Sublime Text (macOS)), `⌘ ⌥ ←` (Xcode), `Ctrl+M, S` (Visual Studio), `⌃ M, S` (Visual Studio (macOS)), `Ctrl+M, S` (ReSharper), `⌃ M, S` (ReSharper (macOS)), `Ctrl+Shift+Comma` (QtCreator), `⌘ ⇧ Comma` (QtCreator (macOS)), `Ctrl+NumPad -` (NetBeans), `Ctrl+NumPad -` (Eclipse), `⌘ NumPad -` (Eclipse (macOS))/`Ctrl+NumPad +` (Windows), `⌘ NumPad +` (macOS), `⌘ NumPad +` (IntelliJ IDEA Classic (macOS)), `⌘ NumPad +` (macOS System Shortcuts), `Ctrl+NumPad +` (XWin), `Ctrl+NumPad +` (GNOME), `Ctrl+NumPad +` (KDE), `Ctrl+NumPad +` (Emacs), `Ctrl+Shift+]` (Sublime Text), `⌘ ⌥ ]` (Sublime Text (macOS)), `⌘ ⌥ →` (Xcode), `Ctrl+M, E` (Visual Studio), `⌃ M, E` (Visual Studio (macOS)), `Ctrl+M, E` (ReSharper), `⌃ M, E` (ReSharper (macOS)), `Ctrl+Shift+.` (QtCreator), `⌘ ⇧ .` (QtCreator (macOS)), `Ctrl+NumPad +` (NetBeans), `Ctrl+NumPad +` (Eclipse), `⌘ NumPad +` (Eclipse (macOS)) to fold or unfold a code fragment

### Structure view

[Structure](file-structure.html) view for CMake shows variables, functions, macros, and targets used your script. To open it, press `Alt+7` (Windows), `⌘ 7` (macOS), `⌘ 7` (IntelliJ IDEA Classic (macOS)), `⌘ 7` (macOS System Shortcuts), `Alt+7` (XWin), `Alt+7` (GNOME), `Alt+7` (KDE), `Alt+7` (Emacs), `Alt+7` (Sublime Text), `⌘ 7` (Sublime Text (macOS)), `⌘ 3` (Xcode), `Ctrl+Alt+F` (Visual Studio), `⌃ ⌥ F` (Visual Studio (macOS)), `Ctrl+F11` (ReSharper), `⌃ F11` (ReSharper (macOS)), `Alt+7` (QtCreator), `⌘ 7` (QtCreator (macOS)), `Ctrl+7` (NetBeans), `Alt+7` (Eclipse), `⌘ 7` (Eclipse (macOS)) (for the tool window) or `Ctrl+F12` (Windows), `⌘ F12` (macOS), `⌘ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ 7` (macOS System Shortcuts), `Ctrl+F12` (XWin), `Ctrl+F12` (GNOME), `Ctrl+0` (KDE), `Ctrl+F12` (Emacs), `Ctrl+R` (Sublime Text), `⌘ R` (Sublime Text (macOS)), `⌃ 6` (Xcode), `Alt+\` (Visual Studio), `⌥ \` (Visual Studio (macOS)), `Ctrl+F12` (ReSharper), `⌘ F12` (ReSharper (macOS)), `Ctrl+F12` (QtCreator), `⌘ F12` (QtCreator (macOS)), `Ctrl+F12` (NetBeans), `Ctrl+F3` (Eclipse), `⌘ O` (Eclipse (macOS)) (for the popup).

![Structure view for CMake](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_structureview.png)

### Customizable syntax highlighting

You can adjust the color and font scheme for CMake files in `Settings | Editor | Color Scheme | CMake`:

![Color scheme settings for CMake](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_codestyle_settings.png)

## Code style for CMake files

In `Settings | Editor | Code Style | CMake`, you can adjust the code style being applied to CMake files. When you change a certain setting, the Preview pane shows how this will affect your code.

![CMake code style settings](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_codestyle_settings_format.png)

> **Tip:**
> For general information about code style options in CLion, refer to [Code Style](settings-code-style.html).

## See also

### Reference

[CMake Tool Window](cmake.html) [CMake Settings](cmake0.html)

### External Links

[CMake Official Page](http://www.cmake.org/)

### Procedures

[Quick CMake tutorial](quick-cmake-tutorial.html) [Load/Reload CMake](reloading-project.html) [CMake profiling](cmake-profiling.html) [Working with source code](working-with-source-code.html)

