-
User Story
-
Resolution: Done
-
P2: Important
-
None
CMake upstream is getting at https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5169 the ability to configure a project with a CMakeSettings.json file.
cmake [<options>] -S <path-to-source> --preset=<preset-name>``
Uses ``<path-to-source>`` as the source tree and reads a preset from
``<path-to-source>/CMakeSettings.json``. The preset specifies the generator
and the build directory, and optionally a list of variables and other
arguments to pass to CMake. The :manual:`CMake GUI <cmake-gui(1)>` can also
recognize ``CMakeSettings.json`` files.
The ``CMakeSettings.json`` file is a JSON document with an object as the
root:
.. code-block:: json
{
"configurations": [
{
"name": "Default Config",
"generator": "Ninja",
"buildRoot": "${projectDir}/build/default",
"cmakeCommandArgs": "-DCMDLINE_ARGUMENT=ON",
"variables": [
{
"name": "VARIABLE_ARGUMENT",
"value": "OFF"
}
]
}
]
}
The root object recognizes the following fields:
``configurations``
An array of preset objects. Each preset may contain the following fields:
``name``
A required string representing the name of the preset.
``generator``
A required string representing the generator to use for the preset.
``buildRoot``
A required string representing the path to the output binary directory.
This field supports variable expansion.
``cmakeCommandArgs``
An optional string representing additional arguments to pass to CMake as
if they had been passed from the command line. This field supports
variable expansion.
``variables``
An optional array of variable objects. Each variable must have the
following fields:
``name``
A required string representing the name, and optionally the type, of
the variable. This may be specified as ``<name>`` or ``<name>:<type>``.
``value``
A required string representing the value of the variable. This field
supports variable expansion.
Each object in ``variables`` is passed to CMake as ``-D<name>=<value>``.
As mentioned above, some fields support variable expansion. This variable
expansion is specific to ``CMakeSettings.json``, and is unrelated to CMake
variables. Variables are recognized in the form ``${<variable-name>}``.
It is an error to not put a closing brace at the end of a variable name. For
example, ``${projectDir`` is invalid.
Dollar signs (``$``) can be escaped using a backslash (``\``). Only dollar
signs are escaped; any other backslash is preserved as-is. For example,
``\$`` will be interpreted as ``$``, ``\\$`` will be interpreted as
``\$``, and ``\a`` will be interpreted as ``\a``. However, note that since
you are writing a JSON document, backslashes have to be double-escaped. For
example, ``"\\$"`` will be interpreted as ``$``, ``"\\\\$"`` will be
interpreted as ``\$``, and ``"\\a"`` will be interpreted as ``\a``.
Recognized variable names include:
``projectFile``
Path to the project's ``CMakeLists.txt`` file. Equivalent to
``${projectDir}/CMakeLists.txt``.
``projectDir``
Path to the project directory.
``thisFile``
Path to this ``CMakeSettings.json`` file. Equivalent to
``${projectDir}/CMakeSettings.json``.
``name``
Name specified in the preset's ``name`` field.
``generator``
Generator specified in the preset's ``generator`` field.
It would be nice if Qt Creator would support this.
- is duplicated by
-
QTCREATORBUG-27214 Support CMake Presets
-
- Closed
-
- is required for
-
QTCREATORBUG-28113 Suggestions pick list
-
- Reported
-
- relates to
-
QTCREATORBUG-28894 CMakePresets.json : settings of presets are lost after inheritance from included file
-
- Closed
-
-
QTCREATORBUG-26869 Qt Creator CMake support improvements
-
- Closed
-
(1 mentioned in)
| For Gerrit Dashboard: QTCREATORBUG-24555 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V |
| 413514,25 | CMakePM: Add support for configure CMake presets | master | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 430738,17 | CMakePM: Add support for build CMake presets | master | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 435071,16 | CMakePM: Add supprot for CMakePresets version 3 | 9.0 | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 438984,3 | CMakePM: Use parent environment for $env{macro} expansion | 9.0 | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 439506,2 | CMakePM: Add installDir CMakePresets support | 9.0 | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 443823,2 | CMakePM: Do not crash with invalid build presets | 9.0 | qt-creator/qt-creator | Status: MERGED | +2 | 0 |
| 466588,3 | CMakePM: add ${pathSepList} from CMakePresets version 5 | 10.0 | qt-creator/qt-creator | Status: MERGED | +2 | 0 |