Skip to content

Use of field condition in CMake Presets v3 is bugged #2185

@vdilecce

Description

@vdilecce

Brief Issue Summary

When the field condition is used in a CMake preset, the extension CMake Tools shows a bugged behavior.

Consider the following CMakePresets.json defining two configure presets (Visual Studio 2017 on Windows and Ninja Multi-Config on Linux) with the relative build preset combinations:

{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 21,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "windows-base",
      "hidden": true,
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    },
    {
      "name": "linux-base",
      "hidden": true,
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Linux"
      }
    },
    {
      "name": "multi-config-base",
      "binaryDir": "buildc",
      "hidden": true
    },
    {
      "name": "vs-base",
      "hidden": true,
      "architecture": {
        "value": "x64",
        "strategy": "set"
      },
      "toolset": {
        "value": "host=x64",
        "strategy": "set"
      }
    },
    {
      "name": "vs2017",
      "inherits": [
        "windows-base",
        "vs-base",
        "multi-config-base"
      ],
      "displayName": "Visual Studio 2017",
      "description": "Architecture x64 - Toolset v141",
      "generator": "Visual Studio 15 2017"
    },
    {
      "name": "ninja-multi-config",
      "generator": "Ninja Multi-Config",
      "displayName": "Ninja",
      "description": "Multi-Config",
      "inherits": [
        "linux-base",
        "multi-config-base"
      ]
    }
  ],
  "buildPresets": [
    {
      "name": "windows-base",
      "hidden": true,
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      }
    },
    {
      "name": "linux-base",
      "hidden": true,
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Linux"
      }
    },
    {
      "name": "vs2017-base",
      "configurePreset": "vs2017",
      "hidden": true
    },
    {
      "name": "ninja-multi-config-base",
      "configurePreset": "ninja-multi-config",
      "hidden": true
    },
    {
      "name": "debug-base",
      "configuration": "Debug",
      "hidden": true
    },
    {
      "name": "release-base",
      "configuration": "Release",
      "hidden": true
    },
    {
      "name": "relwithdebinfo-base",
      "configuration": "RelWithDebInfo",
      "hidden": true
    },
    {
      "name": "minsizerel-base",
      "configuration": "MinSizeRel",
      "hidden": true
    },
    {
      "name": "vs2017-debug",
      "displayName": "Debug",
      "inherits": [
        "windows-base",
        "vs2017-base",
        "debug-base"
      ]
    },
    {
      "name": "vs2017-release",
      "displayName": "Release",
      "inherits": [
        "windows-base",
        "vs2017-base",
        "release-base"
      ]
    },
    {
      "name": "vs2017-relwithdebinfo",
      "displayName": "RelWithDebInfo",
      "inherits": [
        "windows-base",
        "vs2017-base",
        "relwithdebinfo-base"
      ]
    },
    {
      "name": "vs2017-minsizerel",
      "displayName": "MinSizeRel",
      "inherits": [
        "windows-base",
        "vs2017-base",
        "minsizerel-base"
      ]
    },
    {
      "name": "ninja-multi-config-debug",
      "displayName": "Debug",
      "inherits": [
        "linux-base",
        "ninja-multi-config-base",
        "debug-base"
      ]
    },
    {
      "name": "ninja-multi-config-release",
      "displayName": "Release",
      "inherits": [
        "linux-base",
        "ninja-multi-config-base",
        "release-base"
      ]
    },
    {
      "name": "ninja-multi-config-relwithdebinfo",
      "displayName": "RelWithDebInfo",
      "inherits": [
        "linux-base",
        "ninja-multi-config-base",
        "relwithdebinfo-base"
      ]
    }
  ]
}

Expected behavior:

  • Only presets matching the condition are visible in the list presented when the button for selecting the presets in the side bar is clicked.
  • All presets matching the condition are always visible every time the button for selecting the presets in the side bar is clicked.

Actual behavior:

  • All presets are visible.
  • Once a preset is selected, it is no more presented in list shown when the button for selecting the presets in the side bar is clicked. Only restarting Visual Studio Code resets the behavior.

If the condition field is removed form the CMakePresets.json, everything works as expected.

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.21.3
  • VSCode Version: 1.61.1
  • CMake Tools Extension Version: 1.9.0
  • C/C++ Extension Version: 1.7.0
  • Compiler/Toolchain: Visual Studio 2017

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions