vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Errors setting the Windows SDK version in a Configure Preset

Open benschreiber opened this issue 11 months ago • 1 comments

Brief Issue Summary

Beginning with CMake 3.27, you can specify a Windows SDK version in CMAKE_GENERATOR_PLATFORM. This variable can also be set with cmake -A or the architecture field in a configure preset. Consider the following presets.

{
    "version": 6,
    "configurePresets": [
        {
            "name": "msvc",
            "generator": "Visual Studio 16 2019",
            "toolset": "host=x64",
            "architecture": "x64,version=10.0.19041.0",
            "cacheVariables": {
                "CMAKE_CXX_COMPILER": "cl.exe"
            }
        },
        {
            "name": "ninja",
            "generator": "Ninja Multi-Config",
            "toolset": {
                "value": "host=x64",
                "strategy": "external"
            },
            "architecture": {
                "value": "x64,version=10.0.19041.0",
                "strategy": "external"
            },
            "cacheVariables": {
                "CMAKE_CXX_COMPILER": "cl.exe"
            }
        }
    ]
}

From the CLI, the msvc preset works correctly.

cmake --preset msvc
...
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.

In VS Code, the msvc preset shows errors in the log when loading.

[ERROR:vcvarsall.bat] Invalid argument found : x64_x64=version
[ERROR:vcvarsall.bat] Error in script usage. The correct usage is:

but it does seem to work correctly?

[cmake] -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19045.

Without specifying version=10.0.19041.0, I see

[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.

The ninja preset fails to find cl.exe when specifying version=10.0.19041.0, but it works without it.

[cmake] CMake Error at CMakeLists.txt:3 (project):
[cmake]   The CMAKE_CXX_COMPILER:
[cmake] 
[cmake]     cl.exe
[cmake] 
[cmake]   is not a full path and was not found in the PATH.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.87.2",
  "cmtVersion": "1.17.17",
  "configurations": [
    {
      "folder": "c:\\Users\\bschreiber\\Developer\\cmake_repro",
      "cmakeVersion": "3.28.0",
      "configured": true,
      "generator": "Ninja Multi-Config",
      "usesPresets": true,
      "compilers": {
        "C": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe",
        "CXX": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Debug Log

No response

Additional Information

No response

benschreiber avatar Mar 27 '24 19:03 benschreiber

@benschreiber Ah, this looks like the "magic" that we do in order to pull in the development environment from Visual Studio is failing when it tries to parse the arguments and call the vcvarsall.bat script. We'll add this to the backlog.

Thanks!

gcampbell-msft avatar Mar 29 '24 13:03 gcampbell-msft