Configure CMake
Compiler settings
In addition to setting a toolchain, you can use CMake options to specify a compiler. Go to on the main menu and specify the desired compiler by passing the following command:
-D CMAKE_<LANG>_COMPILER=[fully qualified compiler name]
-D CMAKE_CXX_COMPILER=C:\MinGW\bin\g++
Environment variables
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:
-
Parent environment
To include parent environment, open the Environment Variables dialog by clicking 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.
-
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.
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 in CMake Tool Window.