# Quick CMake tutorial

This tutorial will guide you through the process of creating and developing a simple CMake project in CLion. Step by step, you will learn the basics of [CMake](https://cmake.org/) as a build system, along with CMake-specific IDE settings and actions.

> **Note:**
> The source code of the sample project shown below is available on [GitHub](https://github.com/JetBrains/CMake-Tutorial-sample).

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

## 1. Simple CMake project

[CMake](https://cmake.org/) is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines).

When you create a new CMake project in CLion, a `CMakeLists.txt` file is generated automatically under the project root.

Procedure: Start a sample CMake project

1. Select `File | New Project` from the main menu.

2. Select C++ Executable on the left-hand pane.

In our example, the project name is cmake_testapp and the selected language standard in C++17.

![Creating a new CMake project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_create_prj.png)

Click Create.

3. CLion will generate a stub project with a single source file `main.cpp` and a [CMakeLists.txt](cmakelists-txt-file.html) script under the root.

![CMakeLists.txt in a stub CMake project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_simple_cmakeprj.png)

The automatically generated `CMakeLists.txt` contains the following commands:

| Command | Description |
| --- | --- |
| `cmake_minimum_required(VERSION 3.26)` |  [Specifies](https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html) the minimum required version of CMake, as set in the default [toolchain](how-to-create-toolchain-in-clion.html). For most cases, if CMake executable was not changed intentionally, this is the bundled CMake version.  |
| `project(cmake_testapp)` | Defines the project name according to what we provided during project creation. |
| `set(CMAKE_CXX_STANDARD 17)` | [Sets](https://cmake.org/cmake/help/latest/command/set.html) the CMAKE_CXX_STANDARD variable to the value of 17, as we selected when creating the project.      |
| `add_executable(cmake_testapp main.cpp)` | [Adds](https://cmake.org/cmake/help/latest/command/add_executable.html) the cmake_testapp executable target to be built from `main.cpp`. We'll get into targets further [below](#targets-configs). |

4. Click ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.icons.expui.CMakeToolWindow.svg) on the left-hand toolbar of the IDE to open the CMake tool window, where you can check the progress and status of project load:

![CMake tool window](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_toolwindow.png)

> **Tip:**
> The CMake tool window opens up automatically in case of a load failure.

## 2. CMake targets and CLion configurations

[Target](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#binary-targets) is an executable or a library to be built using a CMake script. You can define multiple build targets in a single script.

For now, our test project has only one build target, `cmake_testapp`. Upon the first project loading, CLion automatically adds a run/debug configuration associated with this target:

![Default configuration for a new CMake project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_defaultconf1.png)

In the switcher, click Edit Configurations to view the details. The target name and the executable name are the same as specified in `CMakeLists.txt`:

![Details of the default configuration for a new CMake project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_defaultconf2.png)

Notice the Before launch area of this dialog. Build is set as a before launch step by default. So we can use this configuration not only to debug or run our target, but also to perform the build. For more information about various build actions available in CLion, check out [Build actions](build-actions.html).

## 3. Adding files to existing targets

Let’s create a new source file `general.cpp` and add it to the `cmake_testapp` target.

Procedure:

1. Right-click the root folder in the Project tree and select New | C/C++ Source File:

![Adding a source file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_addsourcefile.png)

2. Set the Add to targets checkbox:

![Adding a file to an existing target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_tutorial_addfiletotarget.png)

3. Click OK, and the new file will be added to the `add_executable` command:

![Source file added to add_executable](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_tutorial_newfile_incmake.png)

> **Tip:**
> When you add a file to a target this way, without manually editing the `CMakeLists.txt` script, CLion reloads the project automatically in the background.

## 4. Adding new targets

Now let's add two more files and create an executable and a library target for them.

Procedure: New executable target

1. Right-click the root folder in the Project tree and select New | C/C++ Source File again.

2. Set the file name (`calc` in our example).

3. In the Add to targets field, clear the cmake_testapp checkbox.

4. Click the Add new target link:

![Adding a file to a new target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_newfile_addtotargets.png)

5. Specify the target name (`cmake_testapp_calc`) and click Add:

![Adding a new executable target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newexetarget.png)

6. The newly created target will appear in the list.

Make sure that only the `cmake_testapp_calc` target is selected:

![New target added to the list of targets](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newtarget_added.png)

Click OK.

7. CLion will add a new `add_executable` command to `CMakeLists.txt` and reload the project:

![New target in CMakeLists.txt](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newexetarget_incmakelists.png)

8. After reload, a new configuration will appear in the configuration switcher:

![Configuration for the newly added target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_addtarget_conf.png)

> **Note:**
> This is an example to illustrate how to add a new executable target. Note that if you want to run this configuration, you need to add an `int main()` function to `calc.cpp`.

Procedure: New library target

1. Right-click the root folder in the Project tree and select New | C/C++ Source File again.

2. Provide the file name (`calc_lib`).

3. Clear the checkboxes in the Add to targets field.

4. Click Add new target.

![Adding new target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_addlib_clicknewtargets.png)

5. In the drop-down list, select `add_library`:

![New library target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newlibtarget.png)

> **Tip:**
> In this drop-down, you can find the commands for adding [CUDA](cuda-projects.html) and [Qt](qt-tutorial.html) targets.

6. Set the target name (`cmake_testapp_lib`) and click Add.

![Adding a library target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_addlib_clicknewtargets.png)

7. The newly created target will appear in the list.

Make sure that other targets' checkboxes are cleared.

![New library target added](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newlibtarget_added.png)

Set the Create an associated header checkbox to also add a header file, `calc_lib.h`.

Click OK.

8. CLion will add a `add_library` command to `CMakeLists.txt` and reload the project:

![New library target in CMakeLists.txt](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_newlibtarget_addedtocmakelists.png)

9. Similarly to the case of executable targets, CLion automatically creates configurations for library targets:

![Configuration for the newly added library target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_addlibrary_conf.png)

However, this is a non-executable configuration, so if you try to run or debug it, you will get the ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.general.balloonError.svg) Executable not specified error message:

![Executable not specified error](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libtarget_exenotspecified.png)

10. To obtain the library file, you need to build this configuration. Select it in the switcher and press `Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `⌘ B` (Xcode), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `F7` (ReSharper), `F7` (ReSharper (macOS)), `Ctrl+F9` (QtCreator), `⌘ F9` (QtCreator (macOS)), `F11` (NetBeans), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS)) or click the build icon:

![Building a library target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_build_lib.png)

As the result, the `libcmake_testapp_lib.a` file will appear in the `cmake-build-debug` folder.

![Library artifact](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libfile.png)

## 5. Reloading the project

Let's introduce some changes in `CMakeLists.txt` manually. For example, add `STATIC` to the declaration of the library target:

![Manually changing CMakeLists.txt](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_cmakelists_manualchanges.png)

When we make changes in `CMakeLists.txt`, CLion shows the icon suggesting to reload the project. Click it or press the shortcut:

![CMake reload icon](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_reload_icon.png)

> **Tip:**
> If you prefer CLion to reload the project silently on every change in `CMakeLists.txt`, go to `Settings | Build, Execution, Deployment | CMake` and enable auto-reload:
>
> ![Enabling auto-reload in CMake settings](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_autoreloadsetting.png)

## 6. CMake presets and CLion CMake profiles

To configure and share CMake options for your project, you can use CMake presets, CLion's CMake profiles, or both.

[CMake Profiles](cmake-profile.html) have many settings in common with [CMake Presets](cmake-presets.html) and are also shareable via VCS. The major difference is that profiles reference CLion [toolchains](how-to-create-toolchain-in-clion.html), which contain information that is not present and not needed in CMake presets (like the debugger or environment settings).

Procedure: CMake presets

[CMake Presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) are a way to configure and share CMake options using two files:

* `CMakePresets.json` for project-wise builds. This file can be shared via VCS.

* `CMakeUserPresets.json` for developers' own local builds. This file should not be checked into VCS.

Both of these files have the same format and should be located in the project's root directory.

> **Note:**
> Find out more on using presets in CLion: [CMake presets](cmake-presets.html)

Procedure: CMake profiles

A profile includes [toolchain](how-to-create-toolchain-in-clion.html) and [build type](cmake-profile.html#buildtypes), as well as CMake options such as [generators](cmake-profile.html#cmake-generators) and [environment variables](cmake-profile.html#EnvVariables). You can configure multiple profiles for your project in order to, for example, use different compilers or to build targets with differing settings.

See the next chapter for an example of adding a profile for Release build.

## 7. Build types

All the Run/Debug configurations created so far were Debug configurations, which is the default build type of the [CMake profile](cmake-profile.html) that was automatically configured for our project.

For example, let's separate the Debug and Release builds. For this, add (![](https://resources.jetbrains.com/help/img/idea/2026.2/app.general.inlineAddHover.svg)) a new CMake profile in `Settings | Build, Execution, Deployment | CMake` and set its build type to Release:

![Adding a release CMake profile](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_addprofile.png)

Notice the Build directory field that specifies the location of build results. The default folders are `cmake-build-debug` for Debug profiles and `cmake-build-release` for Release profiles. You can always set ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.menu-open.svg) other locations of your choice.

Save the profile, and it will appear in the switcher:

![CMake profiles in the configuration switcher](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_profiles_configs.png)

> **Tip:**
> Switching configurations or CMake profiles may affect preprocessor definitions used for resolving your code. See [resolve context](switching-resolve-context.html) for more information.

## 8. Adding include directories

To use additional headers located in separate directories, you need to add them either to all targets or to some specific ones.

Procedure:

1. As an example, let's create three directories under the project root: `includes`, `includes/general`, and `includes/math`. Use the `New | Directory` option in the project tree context menu.

![New include directories](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_includedirs.png)

2. Open `CMakeLists.txt` and add the following commands:

```CMAKE
target_include_directories (cmake_testapp_lib PUBLIC includes/math)
target_include_directories (cmake_testapp_lib PUBLIC includes/general)
```

These two commands make the headers located in `general` and `math` available from the sources of the `cmake_testapp_lib` target.

For example, if we place a header called `header_math.h` inside the `includes/math` folder, we can then include it from `calc_lib.cpp` using `#include "header_math.h"`.

## 9. Linking libraries

### Static libraries

On [step 4](#new-lib-target), we created a static library called `cmake_testapp_lib` (the default filename is `libcmake_testapp_lib.a`).

Now let's see how this library can be linked to our project. For convenience, we will create and use a separate folder for it.

Procedure:

1. Create a `lib` directory under the project root.

2. Copy `libcmake_testapp_lib.a` from its default location, which is `cmake-build-debug`, to the `lib` folder.

![Library artifact in the lib folder](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libartifact_inlibfolder.png)

3. Add the following commands to link this library to the cmake_testapp target:

```CMAKE
find_library(TEST_LIBRARY cmake_testapp_lib lib)
target_link_libraries(cmake_testapp LINK_PUBLIC ${TEST_LIBRARY})
```

* [find_library](https://cmake.org/cmake/help/latest/command/find_library.html) provides the full path to the library,

* which we then pass directly into the [target_link_libraries](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) command via the `${TEST_LIBRARY}` variable.

![Linking a static library](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_link_staticlib.png)

> **Note:**
> Note: make sure to place `target_link_libraries` after the `add_executable` command, so that CMake actually builds the target before linking the library.

### Dynamic libraries

To illustrate the case of shared (dynamic) libraries, we will take the example of using [LibPNG](https://libspng.org), a C library for reading and writing Portable Network Graphics (PNG) files.

Procedure: Install the library package using vcpkg

CLion integrates with [vcpkg](package-management.html), a package manager for C/C++. We will use it to quickly install the library right from the IDE.

1. Follow [this instruction](package-management.html#install-vcpkg) to install vcpkg.

2. In the vcpkg tool window, search for libpng:

![Search for libpng in vcpkg](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libpng_searchvcpkg.png)

3. Click Install in the right-hand pane and wait for installation to complete.

Procedure: Add the library to CMakeLists.txt

1. Open the `CMakeLists.txt` file and add the following commands:

```CMAKE
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
target_link_libraries(cmake_testapp PRIVATE ${PNG_LIBRARY})
```

2. To check whether the library is linked correctly, try including one of the library headers to `main.cpp`:

![Including a LibPNG header](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libpng_includeheader.png)

For example, include `png.h`. You can then press `Ctrl+B` (Windows), `⌘ B` (macOS), `⌘ B` (IntelliJ IDEA Classic (macOS)), `⌘ B` (macOS System Shortcuts), `Ctrl+B` (XWin), `Ctrl+B` (GNOME), `Ctrl+B` (KDE), `Ctrl+Alt+G` (Emacs), `F12` (Sublime Text), `F12` (Sublime Text (macOS)), `⌘ Click` (Xcode), `F12` (Visual Studio), `F12` (Visual Studio (macOS)), `Ctrl+B` (ReSharper), `⌘ B` (ReSharper (macOS)), `F2` (QtCreator), `F2` (QtCreator (macOS)), `Ctrl+B` (NetBeans), `F3` (Eclipse), `F3` (Eclipse (macOS)) to to open this file:

![Go to the png.h file](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_libpng_gotoheader.png)

## 10. CMake debug

In case there are errors or unwanted behaviour during CMake configuration, you can debug the CMake script similarly to other code in your project.

> **Note:**
> The debugger does not debug your actual project build, and the project model is not [reloaded](reloading-project.html) after CMake execution under debug.

Procedure:

1. Place breakpoints in your `CMakeLists.txt` file or files.

2. Open the top-level `CMakeLists.txt`, click the gutter icon next to the first command, and select Debug:

![Starting a CMake debug session from gutter](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_boost_debug_gutter.png)

> **Tip:**
> When CMake generation fails, you can click the debug hint in the CMake tool window to start debugging:
>
>
>
> ![Debug hint in CMake tool window](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_debug_tw_hint.png)
>
>
>
> You can also ask the AI Assistant to [explain the error](https://www.jetbrains.com/help/ai-assistant/explain-code-with-ai.html#explain-cmake-errors).

3. CLion will start a CMake debug session:

![CMake debug session](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_boost_debug_session.png)

For further information, refer to [CMake debug features](cmake-debug.html#cmake-debug-features).

## 11. Tips on editing CMakeLists.txt

CLion provides code insight features to help you work with CMake scripts effectively. For example:

* [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). ![CMake script structure](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_tutorial_structure.png)

* Code completion works for most of the elements in your `CMakeLists.txt`, including the arguments of commands like `find_package()`: ![Completion for find_package](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_tutorial_boost_find_completion.png)

* [Quick Documentation popup](viewing-inline-documentation.html) helps you get more information on code elements. 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)). You can view quick documentation even for completion suggestions: ![Quick documentation for completion suggestions](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmake_tutorial_boost_completion_quickdoc.png)

* 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) > **Tip:** > See [Code insight in CMake](cmakelists-txt-file.html#code-insight-cmake) for more hints on handy features.

## 12. Working with CTest

This chapter gives a simple example of how to use [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html), a framework for compiling and running tests as part of the CMake build process. You can find a general description of the framework in [CTest support](ctest-support.html).

Procedure: Add CTest to the sample project

1. Create a `ctest` directory under the project root.

2. Add the following files to the `ctest` directory:

* A source file `addvalues_zero.cpp`. Don't link this file with any CMake target for now.

* A header file `assert_macro.h`. Don't link this file with any CMake target for now.

* A `CMakeLists.txt` script.

![Adding a folder for CTest](https://resources.jetbrains.com/help/img/idea/2026.2/CMakeLists.txt`:

```
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)

add_executable(ctest_exe_addvalues_zero addvalues_zero.cpp)

target_link_libraries(ctest_exe_addvalues_zero LINK_PUBLIC cmake_testapp_lib)

add_test(NAME ctest_addvalues_zero COMMAND ctest_exe_addvalues_zero)

set_tests_properties(ctest_addvalues_zero PROPERTIES PASS 0)
```

The first line states the minimum supported version of CTest, which corresponds to the version of CMake, 3.14.

We are using the [add_test](https://cmake.org/cmake/help/latest/command/add_test.html) command here to register the `ctest_exe_addvalues_zero` executable with CTest.

4. Next, we need to enable CTest and declare the subproject in the top-level `CMakeLists.txt`:

```CMAKE
enable_testing()
add_subdirectory(ctest)
```

The [enable_testing](https://cmake.org/cmake/help/latest/command/enable_testing.html) command creates a built-in target `test` which will execute CTest.

5. Reload the project.

Procedure: Add the code to be tested

Let's prepare a code piece to be tested with CTest.

1. In `calc_lib.cpp`, add a simple function

```CPLUSPLUS
int add_values (int a, int b) { return a+b;}
```

2. In the associated header, `calc_lib.h`, add the function declaration:

```CPLUSPLUS
int add_values (int a, int b);
```

![Adding a function to be tested](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_testfunc_upd.png)

Procedure: Add the code inside the test sources

1. `assert_macro.h`:

```CPLUSPLUS
#include <iostream>
#include <sstream>


#define assertEqual( ... )               \
do {                                            \
if( !( __VA_ARGS__ ) ) {                     \
std::cerr << "Unit test assert [ " \
<< ( #__VA_ARGS__ )             \
<< " ] failed in line [ "       \
<< __LINE__                     \
<< " ] file [ "                 \
<< __FILE__ << " ]"             \
<< std::endl;                     \
err_code = 1;                           \
}                                            \
} while( false )
```

2. `addvalues_zero.cpp`:

```CPLUSPLUS
#include "assert_macro.h"
#include "../calc_lib.h"

int test_addvalues_zero() {
int err_code = 0;
assertEqual (add_values(0, 0) == 0);
assertEqual (add_values(-5, 5) == 0);
return err_code;
}

int main() {
return test_addvalues_zero();
}
```

Procedure: Edit the CTest configuration

1. In the main menu, go to `Run | Edit Configurations`.

2. Under the CTest Application node, you will find the automatically created All CTest configuration.

Since the code to be tested is located in the `ctest_exe_addvalues_zero` executable, we need to select that executable as a build target in the configuration settings:

![CTest configuration—changing the target](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_ctest_config_targets_to_build_upd.png)

> **Tip:**
> To apply this to all CTest configurations in the project, click Edit configuration templates... in the bottom-left corner of the same dialog, select CTest Application, and change the target in the template:
>
> ![Editing the CTest configuration template](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_ctest_configtemplate_upd.png)

3. Let's also check the Test list to run field. Click the pen icon to open the List of Available Tests dialog, where we can view and adjust the set of tests:

![List of the available tests in CTest configuration](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_ctest_allconfig.png)

> **Tip:**
> For more information about the CTest Application template, refer to [CTest run/debug configuration](ctest-support.html#ctest-configs).

Procedure: Run the CTest configuration and explore the results

1. Select All CTest in the configuration switcher and click ![The Run button](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.execute.svg) or press `Shift+F10` (Windows), `⌃ R` (macOS), `⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ R` (macOS System Shortcuts), `Shift+F10` (XWin), `Shift+F10` (GNOME), `Shift+F10` (KDE), `Shift+F10` (Emacs), `Shift+F10` (Sublime Text), `Shift+F10` (Sublime Text (macOS)), `⌘ ⌥ ⇧ R` (Xcode), `Ctrl+F5` (Visual Studio), `⌃ F5` (Visual Studio (macOS)), `Ctrl+F5` (ReSharper), `⌃ F5` (ReSharper (macOS)), `Ctrl+R` (QtCreator), `⌘ R` (QtCreator (macOS)), `F6` (NetBeans), `Alt+Shift+X` (Eclipse), `⌘ ⇧ F11` (Eclipse (macOS)).

![Running a CTest configuration](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_ctestrun.png)

2. Find results in the [Test Runner](viewing-and-exploring-test-results.html) window:

![CTest results](https://resources.jetbrains.com/help/img/idea/2026.2/cl_cmaketutorial_ctest_results.png)

## 13. Useful links

To dig deeper into CMake in CLion, learn how to:

* [Change project root](change-project-root-directory.html)

* [Reset CMake Cache](cmake-cache.html)

* [Specify compiler flags](cmake-profile.html#compiler-flags)

* [Switch compilers](how-to-switch-compilers-in-clion.html)

* Run [Build actions](build-actions.html) and [CMake install](using-cmake-install.html)

* Use [environment variables](cmake-profile.html#EnvVariables) and the [CLION_IDE](detecting-origin-of-cmake-invocation.html) macro.

* Run [CMake profiling](cmake-profiling.html)

* [Debug CMake](cmake-debug.html)

* Use [CMake install](using-cmake-install.html)

## See also

### How tos

[CTest support](ctest-support.html)

