microsoft / vscode-cmake-tools

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

How come my build presets don't show up in the Build Preset List? #3825

Closed tengai650 closed 2 weeks ago

tengai650 commented 2 weeks ago

Brief Issue Summary

VisualCode

image image

Here is my CMakePresets.json file:

{
    "version": 6,
    "configurePresets": [
        {
            "name": "debug_x64",
            "hidden": true,
            "generator": "Visual Studio 17 2022",
            "binaryDir": "${workspaceFolder}/build",
            "description": "Default build.",
            "cacheVariables": {
                "CMAKE_BUILD_TYPE": "Debug",
                "CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
                "BOOST_ROOT": "G:/dev/boost/boost_1_85_0"
            }
        },
        {
            "name": "release_x64",
            "hidden": true,
            "generator": "Visual Studio 17 2022",
            "binaryDir": "${workspaceFolder}/build",
            "description": "Release build.",
            "cacheVariables": {
                "CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
                "BOOST_ROOT": "G:/dev/boost/boost_1_85_0"
            }
        }
    ],
    "buildPresets": [
        {
            "name": "Release",
            "description": "",
            "displayName": "",
            "configurePreset": "release_x64"
        },
        {
            "name": "Debug",
            "description": "",
            "displayName": "",
            "configurePreset": "debug_x64"
        }
    ]
}

CMake Tools Diagnostics

[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled adding configure preset
[expand] expanding cmake
[main] Configuring project: tcprobe 
[main] Saving open files before configure/build
[presetController] Reading presets file G:\dev\tcprobe\CMakePresets.json
[presetController] Reading and validating the presets "file G:\dev\tcprobe\CMakePresets.json"
[presetController] Successfully validated presets in G:\dev\tcprobe\CMakePresets.json
[expand] expanding cmake
[main] No preset selected. Abort configure
[extension] [5471] cmake.selectConfigurePreset finished (returned false)
[extension] [4111] cmake.selectBuildPreset finished (returned false)
[expand] expanding cmake
[extension] [2092] cmake.addBuildPreset started
[presetController] User cancelled adding build preset
[extension] [2092] cmake.addBuildPreset finished (returned false)
[extension] [7494] cmake.selectBuildPreset started
[extension] [5915] cmake.selectConfigurePreset started
[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled configure preset selection
[extension] [5915] cmake.selectConfigurePreset finished (returned false)
[extension] [7494] cmake.selectBuildPreset finished (returned false)
[extension] [4032] cmake.selectBuildPreset started
[extension] [7247] cmake.selectConfigurePreset started
[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled adding configure preset
[expand] expanding cmake
[main] Configuring project: tcprobe 
[main] Saving open files before configure/build
[main] No preset selected. Abort configure
[extension] [4591] cmake.showConfigureCommand finished (returned -1)
[extension] [2707] cmake.selectBuildPreset started
[extension] [1720] cmake.selectConfigurePreset started
[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled configure preset selection
[extension] [1720] cmake.selectConfigurePreset finished (returned false)
[extension] [2707] cmake.selectBuildPreset finished (returned false)
[extension] [4641] cmake.selectBuildPreset started
[extension] [9175] cmake.selectConfigurePreset started
[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled configure preset selection
[extension] [9175] cmake.selectConfigurePreset finished (returned false)
[extension] [4641] cmake.selectBuildPreset finished (returned false)
[extension] [3686] cmake.selectBuildPreset started
[extension] [2620] cmake.selectConfigurePreset started
[presetController] Start selection of configure presets. Found 2 presets.
[presetController] Opening configure preset selection QuickPick
[presetController] User cancelled configure preset selection
[extension] [2620] cmake.selectConfigurePreset finished (returned false)
[extension] [3686] cmake.selectBuildPreset finished (returned false)

Debug Log

No response

Additional Information

Visua Code Version: 1.90.1 (user setup) Commit: 611f9bfce64f25108829dd295f54a6894e87339d Date: 2024-06-11T21:01:24.262Z Electron: 29.4.0 ElectronBuildId: 9593362 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Windows_NT x64 10.0.22631

v-frankwang commented 2 weeks ago

@tengai650 I think the problem is because you set the hidden attribute in the config to true, when I set this attribute to false, I don't have the problem you mentioned.

v-frankwang commented 2 weeks ago

@gcampbell-msft I am reproducing the problem stated by the user with a simple project, I think the user's problem is caused by setting the hidden attribute to true, here are my steps to reproduce it:

ENV: VS Code: 1.90.0 CMake tools: 1.18.42 C/C++:1.20.5

  1. Create a folder named test and open it with vscode.
  2. Add the CMakeLists.txt file with the following code:
    cmake_minimum_required(VERSION 3.5)
    project(test)
    add_executable(test main.cpp)
  3. Add the main.cpp file with the following code:
    
    #include"iostream"

int main() { std::cout << "Hello world\n" << std::endl; }

4. Add CMakePresets.json file with the following code:

{ "version": 6, "configurePresets": [ { "name": "debug_x64", "hidden":true, "generator": "Visual Studio 17 2022", "binaryDir": "${workspaceFolder}/build", "description": "Default build.", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", "BOOST_ROOT": "G:/dev/boost/boost_1_85_0" } }, { "name": "release_x64", "hidden": true, "generator": "Visual Studio 17 2022", "binaryDir": "${workspaceFolder}/build", "description": "Release build.", "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", "BOOST_ROOT": "G:/dev/boost/boost_1_85_0" } } ], "buildPresets": [ { "name": "Release", "description": "", "displayName": "", "configurePreset": "release_x64" }, { "name": "Debug", "description": "", "displayName": "", "configurePreset": "debug_x64" } ] }


5. Run the command:"**CMake:configure**"

The result of setting the hidden attribute value to true:
![image](https://github.com/microsoft/vscode-cmake-tools/assets/160998958/8b243e1c-31b4-419a-ae30-604dfe7290b8)

The result of setting the hidden attribute value to false:
![image](https://github.com/microsoft/vscode-cmake-tools/assets/160998958/ddbd6efc-5c9a-4a7b-a524-c1539b665503)
gcampbell-msft commented 2 weeks ago

@tengai650 @v-frankwang While this is not exactly matching the behavior of cmake.exe, you should have at least one configure preset visible.

The cmake.exe does allow you to list the build presets even if they use hidden configure Presets, you are not able to build with the command-line with the build presets that use a hidden configure preset. Therefore, the current behavior makes sense.

Closing for now, since you should be using non-hidden configure presets. Thanks! Let me know if there are any other questions.