CLion 2017.2 Help

Changing Configuration Types

In this topic we are going to discuss the ways of optimizing the project generation depending on the purpose of a particular build.

Let's consider the debugging process. As a rule, debugging needs a lot of interstitial information, therefore you have to include a number of code fragments for logging, printing, etc. On the other hand, such code affects performance and increases the code size of your project.

To avoid such a conflict, CMake offers you an instrument known as a build configuration.

The following default build configuration types are provisioned by CMake:

  • Debug;
  • Release;
  • RelWithDebInfo;
  • MinSizeRel.

CLion lets you create as many build configuration as needed for your development lifecycle using the CMake Settings dialog and choosing the configuration among them that is optimal for the current purposes. For example, the following code sample will be executed only if the Debug build configuration had being selected:

int main(int argc, const char* argv[]) { #if DEBUG printf("Executing as \"%s\"\n", argv[0]); #endif ...
and be ignored when another configuration type (Release, for instance) is used.

In this example, DEBUG must be defined in CMakeLists.txt file as follows:

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

Thus, any build configuration accumulates the compiler, linker and CMake default and customized settings. To build a target in a specific build configuration, use Run/Debug configuration dialog to select it in Configuration field.

Advanced option: setting custom build configuration types

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

To adjust the list of configuration types for a certain project, do the following:

  • in CMakeLists.txt file, specify CMAKE_CONFIGURATION_TYPES variable as in example below:
    cmake_minimum_required(VERSION 3.6) project(exampleProject) # setting two custom configuration 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})

You can check the results in the CMakeCache text file by pressing the /help/img/idea/2017.2/icon_config.png button of the CMake tool window.

See Also

Last modified: 16 August 2017