microsoft / microsoft/vscode-cmake-tools
In custom configuration data, indicate which sources are associated with the active build target
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
Bug type: Language Service
Describe the bug
- Windows 10:
- Latest: 1.56
- C/C++ Extension Version: 1.4.0
- Other extensions you installed: CMake Tools (1.7.2)
A single C codebase that has 2 CMake targets/proejcts defined for it: One using CUDA and another not using it (plain C).
The same codebase is compiled to either of these depending on which target is current/active.
CUDA-related portions are within #ifdef __CUDACC__ blocks.
Compilation succeeds on both targets, producing working executables.
But the editing experience is not adjusting properly.
Switchin back and forth between targets doesn't inform the syntax highlighting and code anlysis of a CUDA target being enabled/disabled. It always just debahves as if the projects aren't using CUDA.
There is a .cu file who's #include is under an #ifdef __CUDACC__ block, and when opening it even while the CUDA target is active, none of the CUDA-specific syntax is considered properly, so is full of errors being reported visually - even though it compiles and runs just fine.
Steps to reproduce
- Start a new CUDA CMake project'
- Create a
code.hfile with a#ifdef __CUDACC__block declaring a__constant__variable. - Create a
cuda_code.cufile and include it intocode.hunder that#ifdef __CUDACC__, and add some CUDA-specific code in it. - Include
code.hinmain.cu(Add#include code.h). - Duplicate
main.cuand rename it's file extension to just.c - Duplicate the project definition in the
CMakeLists.txtfile, renaming it to something else and making it a non-CUDA target/project (remove theCUDAterm in theproject()directive, as well as any target properties such asCUDA_SEPARABLE_COMPILATION), then change it's target executable to bemain.cinsteaf ofmain.cu. - After CMake reconfigures, select the CUDA-enabled target as the active one, and open
cuda_code.cu- see how the syntax highlighting isn't working. Also opencode.hand see how the#ifdef __CUDACC__block is greyed out.
Expected behavior
The code analysis and syntax highlighting should get enabled and disabled appropriately when switchin between the CUDA vs. the non-CUDA targets.
Note: See attached animated-gif
Code sample and logs
#ifdef __CUDACC__
#ifndef NDEBUG
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) {
if (code != cudaSuccess) {
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
#else
#define gpuErrchk(ans) ans
#endif
#endif
-
Configurations in
c_cpp_properties.json
None (default) -
Logs from running
C/C++: Log Diagnosticsfrom the VS Code command palette
Nothing special:
-------- Diagnostics - 5/12/2021, 7:11:28 PM
Version: 1.4.0-insiders
Current Configuration:
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerArgs": [],
"intelliSenseModeIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"compilerPathIsExplicit": true,
"browse": {
"path": [
"${workspaceFolder}/**"
],
"limitSymbolsToIncludedHeaders": true
}
}
Custom browse configuration:
{
"browsePath": [
"d:/code/c/raytracerxpu"
],
"standard": "c++14",
"compilerPath": "c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe",
"compilerArgs": [
"-D_WINDOWS",
"-Xcompiler=\" /GR /EHsc\"",
"-Xcompiler=\"-O2 -Ob2\"",
"-DNDEBUG",
"--generate-code=arch=compute_52,code=[compute_52,sm_52]",
"-Xcompiler=-MD",
"-std=c++14"
]
}
Custom configurations:
[ D:\Code\C\RayTracerXPU\main.c ]
{
"defines": [
"WIN32",
"_WINDOWS",
"NDEBUG"
],
"includePath": [],
"compilerPath": "c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe",
"compilerArgs": [
"/DWIN32",
"/D_WINDOWS",
"/O2",
"/Ob2",
"/DNDEBUG",
"-MD"
]
}
Translation Unit Mappings:
[ D:\Code\C\RayTracerXPU\main.c ]:
D:\CODE\C\RAYTRACERXPU\LIB\RENDER\RAYTRACER.H
D:\CODE\C\RAYTRACERXPU\LIB\CORE\TYPES.H
Translation Unit Configurations:
[ D:\Code\C\RayTracerXPU\main.c ]:
Process ID: 4504
Memory Usage: 64 MB
Compiler Path: c:/program files (x86)/microsoft visual studio/2019/community/vc/tools/llvm/x64/bin/clang-cl.exe
Includes:
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\LLVM\X64\LIB\CLANG\11.0.0\INCLUDE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.28.29910\INCLUDE
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\VC\TOOLS\MSVC\14.28.29910\ATLMFC\INCLUDE
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
Defines:
WIN32
_WINDOWS
NDEBUG
WIN32
_WINDOWS
NDEBUG
Standard Version: c17
IntelliSense Mode: windows-clang-x64
Other Flags:
--ms_compatibility
--microsoft_version=1929
--ms_extensions
--clang
--clang_version=110000
Total Memory Usage: 64 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4161
Screenshots

Additional context
I've also tried different settings (without success) such as:
"C_Cpp.intelliSenseEngine": "Tag Parser",
"C_Cpp.default.intelliSenseMode": "windows-clang-x64",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
Setting to "Tag Parser" has the opposite effect: CUDA syntax seems to always be on, even when the non-CUDA project is active.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two-target setup described in CMakeLists.txt, using the CMake Tools configuration provider and the C/C++ Log Diagnostics output as the first inspection points. Compare the active CUDA and non-CUDA target configurations while opening code.h and cuda_code.cu. Done means IntelliSense, syntax highlighting, and conditional code display follow the selected build target.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake, cpp
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100