Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake-presets attribute toolset gets ignored when generator attribute is empty #4156

Open
m1lhaus opened this issue Nov 5, 2024 · 4 comments
Labels
bug a bug in the product Feature: presets
Milestone

Comments

@m1lhaus
Copy link

m1lhaus commented Nov 5, 2024

Brief Issue Summary

In our project we are using Visual Studio generators in order to generate cmake project with VS2017 compilers (V141 toolset). In other words, across the team we have different versions of Visual Studio ranging from 2017 to 2022 with only one common denominator and that is target Visual C++ toolset. In our case it is V141 which are VS2017 compilers. So users normally generate their solutions by omitting -G flag and just providing -T v141 and -A x64 flags. Cmake will handle the rest and find compatible Visual Studio.

Now I have a configure-presets that inherit this:

{
  "name": "MSVC_x64",
  "hidden": true,
  "description": "Default MSVC 141 x64 preset",
  "toolset": {
    "value": "v141",
    "strategy": "set"
  },
  "architecture": "x64"
}

This works great when cmake configure is executed from console (cmd.exe). CMake correctly identifies that my generator is VS2022 since its the only Visual Studio I have installed on my PC. I can see from cmake logs that proper version of C/C++ compilers is selected (V141 toolset).

Now when I configure the same preset from VSCode via cmake tools extension, no matter what always the latest C/C++ compilers are taken from VS2022 (V143 toolset). Even if I put some random string garbage for toolset value, cmake cmake tools would still configure with VS2022 compilers.

Only if I provide specific generator to CMakePresets.json file, in my case "Visual Studio 17 2022", toolset attribute starts working and cmake project with correct compilers gets generated. This looks like a bug to me since cmake itself can handle that by no issue. Or am I missing something?

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.95.1",
  "cmtVersion": "1.19.52",
  "configurations": [
    {
      "folder": "d:\\eSmart\\_P-eSmart\\trunk",
      "cmakeVersion": "3.30.3",
      "configured": true,
      "generator": "",
      "usesPresets": true,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug",
      "Release",
      "MinSizeRel",
      "RelWithDebInfo"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 632,
    "executablesCount": 91,
    "librariesCount": 220,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

No response

Additional Information

No response

@Amy-Li03
Copy link
Collaborator

Amy-Li03 commented Nov 7, 2024

Hi @m1lhaus , thanks for reporting issue here!
We try to reproduce your issue on our side with cmake tools extension v1.19.52 + cmake version 3.29.5-msvc4, however we get the same result when cmake configure is executed from console (cmd.exe) and from VSCode via cmake tools extension, C/C++ compilers are taken from VS2022 (V143 toolset). Please see the test result as below:

cmake configure is executed from console (cmd.exe)
Image

cmake configure is executed from VSCode via cmake tools extension
Image

As you said above, after added "generator": "Visual Studio 17 2022" to CMakePresets.json file, C/C++ compilers are taken from V141 toolset.
Image

@Amy-Li03 Amy-Li03 added more info needed More info is needed from the community for us to properly triage and investigate. and removed triage labels Nov 7, 2024
@m1lhaus
Copy link
Author

m1lhaus commented Nov 7, 2024

Hello @Amy-Li03, well I get different result:

Image

Image

In both cases I am executing my only preset. See code snippet bellow. Also I am bit skeptical about how you are running it from the console. I can't see you explicitly calling a preset.

This would be a dummy preset I can share

{
  "version": 9,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 30,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "Base",
      "hidden": true
    },
    {
      "name": "MSVC_x64",
      "hidden": true,
      "description": "Default MSVC 141 x64 preset",
      "toolset": {
        "value": "v141",
        "strategy": "set"
      },
      "architecture": "x64"
    },
    {
      "name": "MQB_MEB",
      "hidden": true,
      "description": "Base MQB_MEB preset"
    },
    {
      "name": "ALL",
      "hidden": true,
      "description": "Base ALL preset"
    },
    {
      "name": "ALL_MQB_MEB",
      "description": "Base ${presetName} preset",
      "inherits": ["Base", "MSVC_x64", "ALL", "MQB_MEB"],
      "binaryDir": "${sourceDir}/000_bin_preset/build"
    }
  ]
}

@Amy-Li03
Copy link
Collaborator

Amy-Li03 commented Nov 8, 2024

Hi @m1lhaus , thanks for your quick response!
After using command: cmake --preset ALL_MQB_MEB, C/C++ compilers are taken from V141 toolset when cmake configure is executed from console.
Image

@gcampbell-msft I can repro customer's issue: when generator attribute is empty, C/C++ compilers are taken from V141 toolset when cmake configure is executed from console(cmake --preset ALL_MQB_MEB), but they are taken from VS2022 (V143 toolset) when cmake configure is executed from VSCode via cmake tools extension.

I'm not sure if this is a feature request or a bug?

@gcampbell-msft
Copy link
Collaborator

@m1lhaus Yes, this does seem to be a bug based on the command-line behavior and the CMake Presets spec. The only time this wouldn't be a bug would be if you're using a presets version prior to v3, but even then, we would require the generator field, so therefore this is definitely a bug and we will mark/treat it as such.

Thanks!

@gcampbell-msft gcampbell-msft added bug a bug in the product Feature: presets and removed more info needed More info is needed from the community for us to properly triage and investigate. labels Nov 11, 2024
@gcampbell-msft gcampbell-msft moved this from Blocked to Pending Prioritization in CMake Tools Nov 11, 2024
@gcampbell-msft gcampbell-msft added this to the On Deck milestone Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in the product Feature: presets
Projects
Status: Pending Prioritization
Development

No branches or pull requests

3 participants