CMake presets | Qt Creator Documentation
Description: Examples of supported CMake presets.

- Qt Creator Documentation
- CMake presets
- Qt Creator 19.0.1

CMake Qt vendor presets ◦ Conan build configuration

# CMake presets

`CMakePresets.json` has options for project-wide builds, whereas `CMakeUserPresets.json` has options for your local builds.

Create the presets files in the format described in CMake: cmake-presets(7) and store them in the project's root directory. You can then see them in the Projects view.

Qt Creator supports configure, build, and test presets up to version 10 (introduced in CMake 3.31), but does not enforce version checking. It reads and uses all the fields from version 10 if present.

You can import the presets the first time you open a project, when no `CMakeLists.txt.user` file exists or you have disabled all kits in the project.

You can view the presets in the Initial Configuration field and in the environment configuration field below it.

To update changes to the `CMakePresets.json` file, go to Build, select Reload CMake Presets, and then select the presets file to load.

## Configure presets

The following configure presets instruct CMake to use the default generator on the platform and specify the build directory for all build types. `NOT_COMMON_VALUE` is displayed in Initial Parameters and `AN_ENVIRONMENT_FLAG` in the environment configuration field.

     {
       "version": 1,
       "configurePresets": [
         {
           "name": "preset",
           "displayName": "preset",
           "binaryDir": "${sourceDir}/build/preset",
           "cacheVariables": {
             "NOT_COMMON_VALUE": "NOT_COMMON_VALUE"
             },
           "environment": {
             "AN_ENVIRONMENT_FLAG": "1"
             }
           },
           "vendor": {
             "qt.io/QtCreator/1.0": {
                "AskBeforePresetsReload": false,
                "AskReConfigureInitialParams": false,
                "AutorunCMake": false,
                "PackageManagerAutoSetup": false,
                "ShowAdvancedOptionsByDefault": true,
                "ShowSourceSubFolders": false,
                "UseJunctionsForSourceAndBuildDirectories": true
                }
           }
       ]
     }

For more information about the CMake project settings in the `vendor` section, see CMake Qt vendor presets.

## MinGW example

The following example configures a Qt project with:

- MinGW compiler
- build directory – `<sourceDir>/build-release`
- build type – `CMAKE_BUILD_TYPE` as `Release`
- generator – MinGW Makefiles
- path to a CMake executable
- path to the Qt installation via `CMAKE_PREFIX_PATH`
- GNU gdb 11.2.0 for MinGW 11.2.0 64-bit debugger

     {
       "version": 1,
       "configurePresets": [
         {
           "name": "mingw",
           "displayName": "MinGW 11.2.0",
           "generator": "MinGW Makefiles",
           "binaryDir": "${sourceDir}/build-release",
           "cmakeExecutable": "C:/Qt/Tools/CMake_64/bin/cmake.exe",
           "cacheVariables": {
             "CMAKE_BUILD_TYPE": "Release",
             "CMAKE_PREFIX_PATH": "C:/Qt/6.4.0/mingw_64"
           },
           "environment": {
             "PATH": "C:/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
           },
           "vendor": {
             "qt.io/QtCreator/1.0": {
               "debugger": {
                 "DisplayName": "GNU gdb 11.2.0 for MinGW 11.2.0 64-bit",
                 "Abis": ["x86-windows-msys-pe-64bit"],
                 "Binary": "C:/Qt/Tools/mingw1120_64/bin/gdb.exe",
                 "EngineType": 1,
                 "Version": "11.2.0"
               }
             }
           }
       ]
     }

To speed up the process on Windows, specify the `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` in the `cacheVariables` section.

For possible values of some of the `debugger` preferences, see CMake Qt vendor presets.

## Ninja generator example

The following configure and build presets set Ninja Multi-Config as the generator, add `Debug` and `Release` build steps, and specify the path to `ninja.exe` as a value of the `CMAKE_MAKE_PROGRAM` variable:

     {
       "version": 2,
       "configurePresets": [
         {
           "name": "ninja-nmc",
           "displayName": "Ninja Multi-Config MinGW",
           "generator": "Ninja Multi-Config",
           "binaryDir": "${sourceDir}/build",
           "cacheVariables": {
             "CMAKE_CONFIGURATION_TYPES": "Debug;Release",
             "CMAKE_PREFIX_PATH": "C:/Qt/6.4.0/mingw_64",
             "CMAKE_MAKE_PROGRAM": "C:/Qt/Tools/Ninja/ninja.exe"
           },
           "environment": {
             "PATH": "c:/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
           }
         }
       ],
       "buildPresets": [
         {
           "name": "release",
           "displayName": "Ninja Release",
           "configurePreset": "ninja-nmc",
           "configuration": "Release"
         },
         {
           "name": "debug",
           "displayName": "Ninja Debug",
           "configurePreset": "ninja-nmc",
           "configuration": "Debug"
         }
       ]
     }

This example assumes that the CMake executable path is set in Preferences > CMake > Tools.

## MSVC example

When using MSVC compilers with NMAKE Makefiles, Ninja, or Ninja Multi-Config generators, you can use the `external` strategy for the `architecture` and `toolset` fields. This lets Qt Creator set up the Visual C++ environment before invoking CMake.

For example:

     "generator": "Ninja Multi-Config",
     "toolset": {
       "value": "v142,host=x64",
       "strategy": "external"
     },
     "architecture": {
       "value": "x64",
       "strategy": "external"
     },

If you use MSVC compilers with non-VS generators and have several compilers in the `PATH`, you might also have to specify the compiler to use in `cacheVariables` or `environmentVariables`:

     "generator": "Ninja Multi-Config",
     "toolset": {
       "value": "v142,host=x64",
       "strategy": "external"
     },
     "architecture": {
       "value": "x64",
       "strategy": "external"
     },
     "cacheVariables": {
       "CMAKE_C_COMPILER": "cl.exe",
       "CMAKE_CXX_COMPILER": "cl.exe"
     }

## Cross-compilation example

The following example configures a Qt project for cross-compilation on macOS for Windows and running with the `wine` emulator on macOS:

- generator – Ninja
- build directory – `<sourceDir>/build-release`
- LLVM/MinGW toolchain
- configuration type – `CMAKE_BUILD_TYPE` as `Release`
- LLDB 18.1.6 debugger
- `wine` emulator

     {
       "version": 4,
       "configurePresets": [
         {
           "name": "llvm-mingw",
           "displayName": "LLVM-MinGW 18.1.6",
           "generator": "Ninja",
           "binaryDir": "${sourceDir}/build-release",
           "toolchainFile": "llvm-mingw.cmake",
           "cacheVariables": {
             "CMAKE_BUILD_TYPE": "Release",
             "CMAKE_CROSSCOMPILING_EMULATOR": "/opt/homebrew/bin/wine"
           },
           "vendor": {
             "qt.io/QtCreator/1.0": {
               "debugger": {
                 "DisplayName": "LLDB 18.1.6 (CMake Preset)",
                 "Abis": ["x86-darwin-generic-mach_o-64bit", "arm-darwin-generic-mach_o-64bit"],
                 "Binary": "/Users/jdoe/llvm-mingw/bin/lldb",
                 "EngineType": 256,
                 "Version": "18.1.6"
               }
             }
           }
         }
       ]
     }

## Using conditions

The following configure presets are used if they match `condition`. That is, if the `hostSystemName` equals `Linux`, the `linux` presets are used and if it equals `Windows`, the `windows` presets are used.

     {
       "version": 3,
       "configurePresets": [
         {
           "name": "linux",
           "displayName": "Linux GCC",
           "binaryDir": "${sourceDir}/build",
           "cacheVariables": {
             "CMAKE_PREFIX_PATH": "$env{HOME}/Qt/6.4.0/gcc_64"
           },
           "condition": {
             "type": "equals",
             "lhs": "${hostSystemName}",
             "rhs": "Linux"
           }
         },
         {
           "name": "windows",
           "displayName": "Windows MSVC",
           "binaryDir": "${sourceDir}/build",
           "cacheVariables": {
             "CMAKE_PREFIX_PATH": "$env{SYSTEMDRIVE}/Qt/6.4.0/msvc2019_64"
           },
           "condition": {
             "type": "equals",
             "lhs": "${hostSystemName}",
             "rhs": "Windows"
           }
         }
       ]
     }

## Test presets

The following test presets instruct CMake to stop test execution and print output from the test program upon failure, as well as display an error if the test cannot be found.

     {
       "version": 3,
       "testPresets": [
       {
         "name": "default",
         "configurePreset": "default",
         "output": {"outputOnFailure": true},
         "execution": {"noTestsAction": "error", "stopOnFailure": true}
         }
       ],
     }

See also Building projects with CMake, CMake, CMake Qt vendor presets, and SDK Tool.

CMake Qt vendor presets ◦ Conan build configuration