Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-24555

CMake Project Manager: Support presets functionality

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              cadam Cristian Adam
              cadam Cristian Adam
              Votes:
              32 Vote for this issue
              Watchers:
              36 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: