microsoft / microsoft/vscode-cmake-tools

Handling of empty CMake define

Open
#3,218 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: cpptools integration
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

### Brief Issue Summary

defines added to a project using `target_compile_definitions( PRIVATE EXAMPLE)` have the value `1` in the editor tooltip displays while the compiler sees them as no tokens / blank. This then causes parser errors because `1` isn't a valid token in a lot of places that macros are valid

### CMake Tools Diagnostics

```shell
{
"os": "win32",
"vscodeVersion": "1.79.2",
"cmtVersion": "1.14.33",
"configurations": [
{
"folder": "c:\\git\\test\\cmake-empty",
"cmakeVersion": "3.26.0",
"configured": true,
"generator": "Ninja",
"usesPresets": false,
"compilers": {
"C": "C:/Program Files/LLVM/bin/clang.exe",
"CXX": "C:/Program Files/LLVM/bin/clang++.exe"
}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": true,
"activeBuildType": "Debug",
"buildTypesSeen": [
"Debug"
],
"requests": [],
"responses": [],
"partialMatches": [],
"targetCount": 1,
"executablesCount": 1,
"librariesCount": 0,
"targets": [
{
"name": "hello_world",
"type": "EXECUTABLE"
}
]
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "auto",
"configureOnOpen": true
}
]
}
```

### Debug Log

```shell
[main] Configuring project: cmake-empty
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\LLVM\bin\clang++.exe" -SC:/git/test/cmake-empty -Bc:/git/test/cmake-empty/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: C:/git/test/cmake-empty/build
```

### Additional Information

[cmake-empty.zip](https://github.com/microsoft/vscode-cmake-tools/files/11844376/cmake-empty.zip)
Editor shows the define with the value `1` when the in code equivalent is `#define EXAMPLE` (i.e. nothing).
The compile_commands export shows the expected `-DEXAMPLE`

Blank defines added using `EXAMPLE=` (`-DEXAMPLE2=""` in compile_commands (unescaped)) do correctly show as blank but they happen to trigger a different bug in another editor the affected code is being used with so not a great workaround sadly

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Reproduce the case using target_compile_definitions( PRIVATE EXAMPLE), then compare the editor tooltip with the compile_commands entry, which correctly shows -DEXAMPLE. Done means an empty CMake definition is displayed without the value 1 while preserving the existing handling of EXAMPLE=.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, typescript
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.