microsoft / microsoft/vscode-cmake-tools

Cannot set Launch/Debug Target with CMake Presets

Open
#2,363 6 comments 0 reactions 0 assignees View on GitHub
Feature: debug/launch Feature: presets
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

### Brief Issue Summary

Given a CMake project contains a valid CMakePresets.json and CMake Tools are set up to use Presets (cmake.useCMakePresets is 'auto' or 'always'). When a target executable was built successfully, then it does not seem to be possible to select the executable for launch or to actually launch it.

Consider the following demo project:

CMakeLists.txt:
```
cmake_minimum_required(VERSION 3.20)
project(CmakeHelloWorld)

set(CMAKE_CXX_STANDARD 14)

add_executable(cmake-hello-world
main.cpp
)
```

CMakePresets.json:
```
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "aconfig",
"generator": "Ninja",
"cmakeExecutable": "cmake",
"binaryDir": "${sourceDir}/build/${presetName}"
}
],
"buildPresets": [
{
"name": "abuild",
"configurePreset": "aconfig",
"configuration": "Debug",
"targets": "cmake-hello-world"
}
]
}
```

main.cpp:
```
#include

int main()
{
std::cout << "Hello, World! " << std::endl;
return 0;
}
```

1. Open the project in vscode.
2. Make sure cmake.useCMakePresets is set to 'always' and cmake.loggingLevel is set to 'debug'.
3. In the status bar select configure preset 'apreset'.
4. In the status bar select build preset 'abuild'.
5. In the status bar select build target 'cmake-hello-world'.
6. In the status bar click on the 'Build' button.
7. To make sure the resulting binary is ok, navigate to build/aconfig and run binary cmake-hello-world. Greeting should be printed.
8. In the status bar select 'target to launch'. Note that no selection is possible and the following log is produced:
[extension] [7898] cmake.selectLaunchTarget started
[extension] [7898] cmake.selectLaunchTarget finished (returned null)
9. In the left hand pane select 'Cmake'. Navigate to the cmake-hello-world binary and from the context menu choose 'Set as Launch/Debug target'. Note that the target does not become a launch target (no rocket icon) and the same output as in 8. is printed.
10. In the status bar hit the run arrow icon. The following is printed, but the executable is not launched:
[extension] [2724] cmake.launchTarget started
[extension] [2724] cmake.launchTarget finished (returned null)

### Apparent Behavior

No target is selected for launch and nothing is launched.

### Expected Behavior

The target 'cmake-hello-world' becomes the selected launch target in the status bar and the rocket icon appears next to it in the left hand CMake tree view. When launching it via the status bar run button the executable is executed and the greeting is printed in the terminal view.

### CMake Tools Diagnostics
```
{
"os": "linux",
"vscodeVersion": "1.64.0",
"cmtVersion": "1.9.2",
"configurations": [
{
"folder": "/home/alibaba/concealed",
"cmakeVersion": "3.22.2",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"compilers": {
"C": "/usr/bin/cc",
"CXX": "/usr/bin/c++"
}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": true,
"activeBuildType": "",
"buildTypesSeen": [
""
],
"requests": [
"file:///home/alibaba/concealed/main.cpp"
],
"responses": [
{
"uri": "file:///home/alibaba/concealed/main.cpp",
"configuration": {
"defines": [],
"standard": "gnu++14",
"includePath": [],
"compilerPath": "/usr/bin/c++",
"compilerArgs": [
"-std=gnu++14"
]
}
}
],
"partialMatches": [],
"targetCount": 1,
"executablesCount": 1,
"librariesCount": 0,
"targets": [
{
"name": "cmake-hello-world",
"type": "EXECUTABLE"
}
]
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "always",
"configureOnOpen": null
}
]
}
```

### Debug Log

see above

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied CMakeLists.txt, CMakePresets.json, and main.cpp, using the listed preset and launch-target steps. Start by tracing the cmake.selectLaunchTarget and cmake.launchTarget commands alongside the CMake Tools diagnostics. Done means the executable can be selected, shows the rocket icon, and runs from the status bar with its greeting printed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, typescript, vscode
Domain
build-system, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.