Back to Cmake

BuildPresets Properties

Help/manual/presets/buildPresets-properties.rst

4.4.08.4 KB
Original Source

.. This file was generated by Utilities/Scripts/regenerate-presets.py from Help/manual/presets/schema.yaml. Do not edit.

.. _CMakePresets.buildPresets.name:

name A required string representing the machine-friendly name of the preset. This identifier is used in the :option:cmake --build --preset <cmake--build --preset> option. There must not be two build presets in the union of CMakePresets.json and CMakeUserPresets.json in the same directory with the same name. However, a build preset may have the same name as a configure, test, package, or workflow preset.

.. _CMakePresets.buildPresets.hidden:

hidden An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the :cmake-build-option:--preset argument and does not have to have a valid :preset:buildPresets.configurePreset, even from inheritance. hidden presets are intended to be used as a base for other presets to inherit via the :preset:buildPresets.inherits field.

.. _CMakePresets.buildPresets.inherits:

inherits An optional array of strings representing the names of presets from which to inherit. This field can also be a string, which is equivalent to an array containing one string.

The preset will inherit all of the fields from the inherits presets by default (except name, hidden, inherits, description, and displayName), but can override them as desired. If multiple inherits presets provide conflicting values for the same field, the earlier preset in the inherits array will be preferred.

A preset can only inherit from another preset that is defined in the same file or in one of the files it includes (directly or indirectly). Presets in CMakePresets.json may not inherit from presets in CMakeUserPresets.json.

.. _CMakePresets.buildPresets.condition:

condition .. presets-versionadded:: 3

An optional Condition_ object.

.. _CMakePresets.buildPresets.vendor:

vendor An optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. However, it should follow the same conventions as the root-level vendor field. If vendors use their own per-preset vendor field, they should implement inheritance in a sensible manner when appropriate.

.. _CMakePresets.buildPresets.displayName:

displayName An optional string with a human-friendly name of the preset.

.. _CMakePresets.buildPresets.description:

description An optional string with a human-friendly description of the preset.

.. _CMakePresets.buildPresets.environment:

environment An optional map of environment variables. The key is the variable name (which may not be an empty string), and the value is either null or a string representing the value of the variable. Each variable is set regardless of whether or not a value was given to it by the process's environment.

This field supports macro expansion_, and environment variables in this map may reference each other, and may be listed in any order, as long as such references do not cause a cycle (for example, if ENV_1 is $env{ENV_2}, ENV_2 may not be $env{ENV_1}). $penv{NAME} allows one to prepend or append values to existing environment variables by accessing only values from the parent environment.

Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied. Setting a variable to null causes it to not be set, even if a value was inherited from another preset.

.. note::

For a CMake project using :module:`ExternalProject` with a
configuration preset having environment variables needed in the
ExternalProject, use a build preset that inherits that
configuration preset or the ExternalProject will not have the
environment variables set in the configuration preset. Example:
suppose the host defaults to one compiler (say Clang) and the user
wishes to use another compiler (say GCC). Set configuration preset
environment variables :envvar:`CC` and :envvar:`CXX` and use a
build preset that inherits that configuration preset. Otherwise the
ExternalProject may use a different (system default) compiler than
the top-level CMake project.

.. _CMakePresets.buildPresets.configurePreset:

configurePreset An optional string specifying the name of a configure preset to associate with this build preset. If configurePreset is not specified, it must be inherited from the inherits preset (unless this preset is hidden). The build directory is inferred from the configure preset, so the build will take place in the same binaryDir that the configuration did.

.. _CMakePresets.buildPresets.inheritConfigureEnvironment:

inheritConfigureEnvironment An optional boolean that defaults to true. If true, the environment variables from the associated configure preset are inherited after all inherited build preset environments, but before environment variables explicitly specified in this build preset.

.. _CMakePresets.buildPresets.jobs:

jobs An optional integer. Equivalent to passing :cmake-build-option:--parallel or -j on the command line. If the value is 0, it is equivalent to passing --parallel with <jobs> omitted; alternatively, one can define the environment variable :envvar:CMAKE_BUILD_PARALLEL_LEVEL as an empty string using the environment field.

.. versionchanged:: 4.3

This field does not accept negative integer values, regardless of
the version in the presets file.

.. _CMakePresets.buildPresets.targets:

targets An optional string or array of strings. Equivalent to passing :cmake-build-option:--target or -t on the command line. Vendors may ignore the targets property or hide build presets that explicitly specify targets. This field supports macro expansion_.

.. _CMakePresets.buildPresets.configuration:

configuration An optional string. Equivalent to passing :cmake-build-option:--config on the command line.

.. _CMakePresets.buildPresets.cleanFirst:

cleanFirst An optional bool. If true, equivalent to passing :cmake-build-option:--clean-first on the command line.

.. _CMakePresets.buildPresets.resolvePackageReferences:

resolvePackageReferences .. presets-versionadded:: 4

An optional string that specifies the package resolve mode.

Package references are used to define dependencies to packages from external package managers. Currently only NuGet in combination with the :ref:Visual Studio generators is supported. If there are no targets that define package references, this option does nothing. Valid values are:

on Causes package references to be resolved before attempting a build.

off Package references will not be resolved. Note that this may cause errors in some build environments, such as .NET SDK style projects.

only Only resolve package references, but do not perform a build.

.. note::

The command line parameter
:cmake-build-option:`--resolve-package-references`
will take priority over this setting. If the command line
parameter is not provided and this setting is not specified, an
environment-specific cache variable will be evaluated to decide,
if package restoration should be performed.

When using the :ref:`Visual Studio generators`,
package  references are defined using the
:prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references
are restored using NuGet. It can be disabled by setting the
:variable:`CMAKE_VS_NUGET_PACKAGE_RESTORE` variable to ``OFF``.
This can also be done from within a configure preset.

.. _CMakePresets.buildPresets.verbose:

verbose An optional boolean. If true, equivalent to passing :cmake-build-option:--verbose on the command line.

.. _CMakePresets.buildPresets.nativeToolOptions:

nativeToolOptions An optional array of strings. Equivalent to passing options after :cmake-build-option:-- on the command line. The array values support macro expansion_.