microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.48k stars 453 forks source link

CMake Presets - Architecture field ignored during configuration #4181

Open joelkeeling opened 2 days ago

joelkeeling commented 2 days ago

Brief Issue Summary

When using the cmake tools extension, I am unable to change the target architecture(x86/x64) with the "architecture" field in my configure preset. This functionality does work if I use cmake over the command line.

In the example, I am trying use the "debug-32bit" preset, which is supposed to build for x86.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.95.1",
  "cmtVersion": "1.20.24",
  "configurations": [
    {
      "folder": "c:\\Users\\TEST\\cmakePresetTestProject",
      "cmakeVersion": "3.31.0",
      "configured": true,
      "generator": "Visual Studio 17 2022",
      "usesPresets": true,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug",
      "Release",
      "MinSizeRel",
      "RelWithDebInfo"
    ],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 3,
    "executablesCount": 0,
    "librariesCount": 1,
    "targets": [
      {
        "name": "ALL_BUILD",
        "type": "UTILITY"
      },
      {
        "name": "SctTest",
        "type": "SHARED_LIBRARY"
      },
      {
        "name": "ZERO_CHECK",
        "type": "UTILITY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

[main] Configuring project: cmakePresetTestProject 
[driver] Removing C:/Users/TEST/cmakePresetTestProject/out/build/debug-32bit/CMakeCache.txt
[driver] Removing C:\Users\TEST\cmakePresetTestProject\out\build\debug-32bit\CMakeFiles
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_BUILD_TYPE=Debug -SC:/Users/TEST/cmakePresetTestProject -BC:/Users/TEST/cmakePresetTestProject/out/build/debug-32bit
[cmake] -- Building for: Visual Studio 17 2022
[cmake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
[cmake] -- The CXX compiler identification is MSVC 19.39.33522.0
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Configuring done (2.9s)
[cmake] CMake Warning:
[cmake]   Manually-specified variables were not used by the project:
[cmake] 
[cmake]     CMAKE_BUILD_TYPE
[cmake] 
[cmake] 
[cmake] -- Generating done (0.2s)
[cmake] -- Build files have been written to: C:/Users/TEST/cmakePresetTestProject/out/build/debug-32bit

Additional Information

This is a follow up to a comment I made to @gcampbell-msft : https://github.com/microsoft/vscode-cmake-tools/issues/3818#issuecomment-2438503253

PRESETS

"configurePresets": [        
        {
            "name": "base-64bit",
            "hidden": true,
            "architecture": 
            {
                "value": "x64",
                "strategy": "set"
            }
        },
        {
            "name": "base-32bit",
            "hidden": true,
            "architecture": 
            {
                "value": "Win32",
                "strategy": "set"
            }
        },
        {
            "name": "base-debug",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug"
            }
        },
        {
            "name": "base-release",
            "hidden": true,
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Release"
            }
        },
        {
            "name": "debug-32bit",
            "inherits": [
                "base-32bit",
                "base-debug"       
            ]
        },
        {
            "name": "debug-64bit",
            "inherits": [
                "base-64bit",
                "base-debug"       
            ]
        },
        {
            "name": "release-32bit",
            "inherits": [
                "base-32bit",
                "base-release"       
            ]
        },
        {
            "name": "release-64bit",
            "inherits": [
                "base-64bit",
                "base-release"       
            ]
        }
    ],

CORRECT FUNCTIONALITY USING COMMAND LINE

PS C:\Users\TEST\cmakePresetTestProject\build> cmake ../ --preset debug-32bit
Preset CMake variables:

  CMAKE_BUILD_TYPE="Debug"

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The CXX compiler identification is MSVC 19.39.33522.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (2.5s)
-- Generating done (0.0s)
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_BUILD_TYPE

-- Build files have been written to: C:/Users/TEST/cmakePresetTestProject/build
Amy-Li03 commented 1 day ago

Hi @joelkeeling, thanks for your feedback ticket! We can repro this issue on our side with below:

Environment:

VS Code: 1.95.3 CMake Tools: v1.20.25 (pre-release)

Repro steps:

  1. Unzip the project and open it with vscode. test_project.zip
  2. Open the command palette (F1 or Ctrl+Shift+P)
  3. Enter and select the command CMake: Configure
  4. Choose "debug-32bit"
  5. Observe the messages in OUTPUT window

Test result:

CMake configure is executed from VSCode via cmake tools extension. Image

CMake configure is executed from command line. (cmake ../ --preset debug-32bit) Image