CLion 2019.1 Help

CMake Profile

In CLion, settings required for building a CMake project are incorporated in a CMake profile. It includes toolchains, build types, CMake options, and environment variables. You can create multiple profiles with different build types and toolchains:

Cmake Profile

Having multiple CMake profiles enables you, for example, to use different compilers for one project, or to build CMake targets with differing settings.

To build a target using a specific profile, select it in the Run/Debug configuration switcher on the toolbar (or press Shift+Alt+F10 for Run and Shift+Alt+F9 for Debug):

cmake profiles in the configuration switcher

Build types

By default, CMake supports the following build types:

  • Debug

  • Release

  • RelWithDebInfo (Release with debugging information)

  • MinSizeRel (Release optimized for size)

You can select the required build type in Settings / Preferences | Build, Execution, Deployment | CMake. To refer to the build type, use CMAKE_BUILD_TYPE. For example, add the following code into the CMakeLists.txt script:

if (CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DDEBUG=1) endif()
And you will be able to create conditional statements in your code based on the current build type:
int main(int argc, const char* argv[]) { //TODO: add some code #if DEBUG ... #else ... #endif

Сustom 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:

custom build types

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:

custom build types for new cmake profile

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.

Last modified: 24 July 2019