Clion Cmake

  1. Clion Cmake Option
  2. Clion Cmake-build-debug
  3. Clion Cmake Path

For CMake projects in CLion, a toolchain is a set of all the necessary tools required for building and running your application: the working environment, the CMake executable, the make tool and compilers, and the debugger.

Build your application or library in CLION using Cmake as normal to generate caches For me on windows my cmake gui was in my start menu after installing it. Follow these directions; basically setting the source and the build binaries, just use the existing project files. Then click on advanced to show your variables.

When you start working with CLion, you already have a default toolchain available. Although you can use it in development, you may also want to adjust the set of tools for the needs of your project (for example, change the working environment or switch to another compiler).

You can always have multiple toolchains for one project and switch between them when needed.

  1. This post explains how to setup a development environment for C and C projects using Clang as compiler, CMake as build system, CLion as IDE and Conan as package manager. The name 4 Cs is cool, but not my idea, it has been coined by well known C blogger Arne Metz, author of the great Simplify C blog.
  2. Build your application or library in CLION using Cmake as normal to generate caches For me on windows my cmake gui was in my start menu after installing it. Follow these directions; basically setting the source and the build binaries, just use the existing project files.
  3. Extend CMake language support in the IDE's Editor.
  4. Cmake Your dependencies (the packages you want to use) should go under the “requires” section. To search for packages, run (you can use either CLion’s terminal or your mac’s terminal): conan search -remote=conan-center.

Create a new toolchain

  1. Go to Settings / Preferences Build, Execution, Deployment Toolchains and click to add a new toolchain.

  2. On Windows, choose your working Environment: MinGW, Cygwin, Visual Studio, WSL, or Remote Host. For more details on how to configure CLion on Windows, take a look at our tutorial.

    On Linux or macOS, choose the type of your toolchain - System for local projects or Remote Host for Full remote mode.

  3. Select the preferred CMake installation, either the bundled one or a custom version of your choice.

  4. The CMake executable that you set up on the previous step attempts to detect the make utility and the C/C++ compilers. These installations are not defaults, but the ones that CMake detects considering all the packages installed on your system at the moment.

    If you prefer to use custom make and compilers instead of the detected ones, use the fields Make, C Compiler, and C++ Compiler to provide the paths. See Switching compilers.

    If you are using the GNU ARM toolchain, make sure it's presented in your system PATH (see Embedded development: toolchains and compilers ).

    For the IAR toolchain, specify the compilers as described in IAR toolchain.

  5. Finally, specify the Debugger. On Windows, you can choose between the bundled or custom GDB. On macOS and Linux, CLion also includes the LLDB debugger (default for macOS). See the currently supported versions.

  6. CLion verifies your choices and notifies you if any of the tools or packages are missing.

  7. When the configuration is completed, click OK to save it. Now you have one more toolchain to use when creating a CMake profile.

Settings required for building a CMake project are incorporated into a CMake profile. It includes the toolchain, build type, as well as CMake options such as generators, and environment variables. You can configure multiple profiles for your project in order to, for example, use different compilers or to build targets with differing settings.

To set up the profiles for your project, go to Settings / Preferences Build, Execution, Deployment CMake.

You can quickly access this dialog from Find Action (Ctrl+Shift+A) (search for CMake Settings) or assign a shortcut for it in Settings / Preferences Editor Keymap.

Add new profiles

  1. Go to Settings / Preferences Build, Execution, Deployment CMake.

  2. Click , and CLion will add a new profile to the list.

  3. Change the profile name, build type, and other settings as required.

Build with a profile

  1. Use one of the available Build actions.

  2. Alternatively, select the desired profile in the Run/Debug configuration switcher and build , run , or debug the configuration:

Set default profiles for new projects

  • Go to File New Projects Settings Settings for New Projects Build, Execution, Deployment CMake.

  • Configure the list of profiles to be used for all new projects by default.

Disabling/enabling profiles

You can disable the profiles that are not currently in use to save time on loading and avoid potential errors (for example, when you have a remote profile you don't use regularly and the machine is shut down).

When you enable or disable a profile, CLion incrementally reloads CMake regardless of the Reload CMake project on editing CMakeLists.txt control.

Disable/enable a profile

Use one of the following options:

Clion Cmake Option

  • Clear or set the Enable profile checkbox in Settings / Preferences Build, Execution, Deployment CMake. Disabled profiles are grayed out in the list:

  • To disable a successfully loaded profile, select Disable This Profile from the configuration menu in the CMake tool window:

    From this menu, you can also enable any of the previously disabled profiles:

  • If a profile has failed to load, you can disable it form the CMake tool window using the Disable profile option:

Sharing profiles

You can share CMake profiles in VCS along with the project. The profiles' settings are stored in cmake.xml in the .idea directory.

To share a profile, select it in the list and set the Share checkbox:

Note that only the Profile settings can be shared. The Reload CMake project on editing CMakeLists.txt option is common for all profiles and is stored in workspace.xml.

Make sure to have different names for shared and local profiles. If a shared and a local profile have the same name, the local one takes precedence and you will not see the shared one in the settings.

Compiler flags

In CLion, there are two ways to specify compiler flags: either in CMake options of a profile, or right in the CMakeLists.txt script.

Set compiler flags

  • Using CMake options

    Select the profile in Settings / Preferences Build, Execution, Deployment CMake and edit the CMake options field.

    Use -D with the CMAKE_CXX_FLAGS variable (or CMAKE_C_FLAGS for C projects). For example, -DCMAKE_CXX_FLAGS='-Wall -Wextra'.

  • In CMakeLists.txt

    Alternatively, add the following line in your CMakeLists.txt script: set(CMAKE_CXX_FLAGS '${CMAKE_CXX_FLAGS} -Wall -Wextra')


In the CMake options field, you can specify a CMake generator via -G. For example, in the case of Ninja:

For Ninja Multi-Config, use -G 'Ninja Multi-Config'. Note that CLion will use only the configuration that corresponds to the build type of the current profile (see Current limitations ).

You can set up any CMake generator available for your platform and use different generators in different CMake profiles if necessary.

Clion cmake not found

When building your project, make sure to select the desired profile in the configuration switcher:

Note that for a CMake profile, the actual built tools are taken from the selected toolchain. If you specify the generator other than Makefiles, the Make path in the toolchain settings will be ignored.

Current limitations

  • CLion uses CMake File API, which first appeared in CMake v3.14. However, CLion supports it starting from the update introduced in CMake v3.15, so if you decide to switch from the bundled CMake, make sure to use version 3.15.x or later.

  • For multi-config generators like Ninja Multi-Config, Xcode, or Visual Studio, CLion uses only the configuration that corresponds to the build type specified in the CMake profile (CPP-20890 ).

Build types

Use the Build type field to set one of the following CMake build types:

  • Default (corresponds to the empty value of CMAKE_BUILD_TYPE).

  • Debug (the default build type)

  • Release

  • RelWithDebInfo (Release with debugging information)

  • MinSizeRel (Release optimized for size)

To refer to the build type in CMakeLists.txt, use the CMAKE_BUILD_TYPE variable. For example:

if (CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DDEBUG=1)endif()

You can also create conditional statements in your code based on the current build type:

int main(int argc, const char* argv[]) { #if DEBUG ... #else ... #endif

Custom build types

The list of the available build types is defined in the CMAKE_CONFIGURATION_TYPES command. The default value of this command is the four build types given above, but you can extend it to have other build types. For example:

# adding two custom build types to the cached value # variable CMAKE_CONFIGURATION_TYPES should be defined before other definitions: set(CMAKE_CONFIGURATION_TYPES 'MyDebug;MyRelease' CACHE STRING ' FORCE)

After reloading the project, custom types will be available from the CMake settings:

Note that the custom types were added to the value Debug which was cached in CMakeCache.txt. So for example, if you add a new CMake profile, it will have its own CMakeCache.txt, and for this profile, the list of the available build types will contain your custom types only:

Build options

In the Build options field, you can set the options to be passed either to the build tool used by CMake or as command line parameters to CMake itself. These options will be used during the build phase.

Arguments for the underlying build tool (make, Ninja, or another one) should be preceded with --. For example, if you specify -j 5 --clean-first -- -d -p, then -j 5 --clean-first will be processed by CMake, while -d -p will be passed to the build tool.

When nothing is specified in this field, CLion uses default settings which depend on the selected environment. For example, if the make generator is set, the default value of this field is -- -j <80%_of_logical_cores>, while for Microsoft Visual C++ this field is empty.

Environment variables

You can pass additional environment variables to CMake generation and build via the Environment field of the CMake Settings dialog (navigate to Settings / Preferences Build, Execution, Deployment CMake ).

Clion Cmake-build-debug

The overall impacting environment for CMake generation and build consists of:

  • Parent environment

    To include parent environment, open the Environment Variables dialog by clicking or pressing Shift+Enter, and set the Include system environment variables checkbox. The values you specify additionally will be appended to system variables. Otherwise, when the checkbox is cleared, your custom values will overwrite the system ones.

  • Toolchain environment

    For example, variables defined in vcvarsall.bat for MSVC, path variables like mingw/bin, and others.

  • CMake profile environment

    Your custom variables specified in the Environment field.

Clion Cmake Path

For references to existing variables, use the $VAR$ syntax. Mind that such references are case-sensitive, for example, PATH=xxx:$PATH$ for Linux and macOS, and Path=xxx;$Path$ for Windows. Referencing existing variables is currently not available if you are using a remote toolchain (CPP-15693 ).