CLion 2018.3 Help

Configure CMake

Compiler settings

In addition to setting a toolchain, you can use CMake options to specify a compiler. Go to Settings / Preferences | Build, Execution, Deployment | CMake on the main menu and specify the desired compiler by passing the following command:

-D CMAKE_<LANG>_COMPILER=[fully qualified compiler name]
The LANG part specifies the language to compile (C for C and CXX for C++), and you need to provide the full path to the compiler, for example:
Note: if you specify a compiler via CMake settings, you override the selection made in the toolchains setting dialog.

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

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

  1. Parent environment

    To include parent environment, open the Environment Variables dialog by clicking icons actions menu open svg or pressing Shift+Enter, and set the Include parent 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.

    Click Show to view the full list of system variables and their values.

  2. Toolchain environment

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

  3. CMake profile environment

    Your custom variables specified in the Environment field.

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.

Advanced options

Changing build directory

The CMake settings dialog provides an input box for specifying the build options, and also enables you to change the CMake files generation path. CLion supports in-source builds: you can specify a directory for generated files within the source folder.

Creating multiple toolchains

You may want to have an individual set of tools ready to be used in different projects (for example, if your projects require different environments or CMake executables). Or you may need different toolchains to be used in one project for different CMake profiles (see the detailed description of build configurations).

In CLion, you can create and manage the list of toolchains and use them in CMake profiles. For the latter, use the Toolchains field of the CMake Settings dialog to select the desired toolchain from the drop-down list.

Setting custom build types

You can extend the list of available build types with custom ones by setting them explicitly in CMakeLists.txt.

To adjust the list of build types, specify the CMAKE_CONFIGURATION_TYPES variable, for example::

cmake_minimum_required(VERSION 3.6) project(exampleProject) # setting two custom build types # variable CMAKE_CONFIGURATION_TYPES shall be defined prior to other definitions: set(CMAKE_CONFIGURATION_TYPES "CustomType1;CustomType2" CACHE STRING "" FORCE) set(CMAKE_CXX_STANDARD 11) # setting the language standard set(SOURCE_FILES main.cpp) add_executable(exampleProject ${SOURCE_FILES})

To check the results in the CMakeCache text file, press icons fileTypes config in CMake Tool Window.

Last modified: 14 February 2019