In CLion, settings required for building a CMake project are incorporated in a CMake profile, which includes toolchain, build type, CMake options such as CMake generators, and environment variables. Having multiple profiles enables you, for example, to use different compilers for one project, or to build CMake targets with differing settings.
To configure CMake profiles for your projects, go to.
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):
You can set up any CMake generator available for your platform and use different generators in different CMake profiles if necessary.
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 issues and 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-configuration generators like Xcode and Visual Studio, CLion will use only the configuration that corresponds to the build type specified in the CMake profile.
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)
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:
You can also create conditional statements in your code based on the current build type:
С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:
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:
You can pass additional environment variables to CMake generation and build via the Environment field of the dialog (navigate to ).
The overall effective environment for CMake generation and build consists of:
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.
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.