Brief Issue Summary
When using "Compile Active File" with MSVC + Ninja Multi-Config on Windows, CMake Tools incorrectly quotes compiler arguments that end with a backslash. CMake emits /Fd
\ (with a trailing backslash) when no explicit PDB name is configured. CMake Tools wraps this in quotes, but in cmd.exe a backslash before a closing quote is an escape — so the quote is not treated as closing and the next token (/FS) is consumed as part of the argument.
Observed compile command:
"/FdCMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ /FS"
cl.exe error:
fatal error C1041: cannot open program database
'...\CMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ \FS.pdb';
if multiple CL.EXE write to the same .PDB file, please use /FS
cl.exe receives /Fd
\ /FS as a single argument and interprets \FS.pdb as the PDB filename. The /FS flag is lost.
Expected: Arguments with trailing backslashes are quoted correctly, e.g. by doubling the backslash or appending a space before the closing quote ("/FdCMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ ") — or by not quoting the argument at all since it contains no spaces.
Workaround: Set COMPILE_PDB_NAME on the target so CMake emits an explicit filename (/Fd
<name>.pdb) instead of a bare directory path, eliminating the trailing backslash.
Steps to reproduce:
CMake project, Ninja Multi-Config generator, MSVC toolchain, CMAKE_EXPORT_COMPILE_COMMANDS=ON
Do not set COMPILE_PDB_NAME on any target (default CMake behaviour)
Open a .cpp source file and run CMake: Compile Active File
Environment:
Windows 11
MSVC (cl.exe)
Generator: Ninja Multi-Config
CMake Tools version: 1.23.52
VS Code version: 1.117.0
CMake Tools Diagnostics
{
"os": "win32",
"vscodeVersion": "1.117.0",
"cmtVersion": "1.23.52",
"configurations": [
{
"folder": "d:\\src\\thx\\SonicSnitch\\DetectionEngine\\InversePanning",
"cmakeVersion": "4.2.3",
"configured": true,
"generator": "Ninja Multi-Config",
"usesPresets": true,
"compilers": {
"CXX": "C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe"
}
}
],
"cpptoolsIntegration": {
"isReady": true,
"hasCodeModel": true,
"activeBuildType": "Debug",
"buildTypesSeen": [
"Debug",
"Release",
"RelWithDebInfo"
],
"requests": [
"file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/tests/decoder_pump_test.cpp",
"file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/DemoUI/src/InputSources/FFmpeg/FFmpegInputSource.cpp"
],
"responses": [
{
"uri": "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/tests/decoder_pump_test.cpp",
"configuration": {
"includePath": [
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/src",
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/demoui/src",
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/build/ninja/with-vcpkg-qt-online/vcpkg_installed/x64-windows/include",
"c:/qt/6.11.0/msvc2022_64/include/qtcore",
"c:/qt/6.11.0/msvc2022_64/include",
"c:/qt/6.11.0/msvc2022_64/mkspecs/win32-msvc"
],
"defines": [
"GTEST_LINKED_AS_SHARED_LIBRARY=1",
"QT_CORE_LIB",
"TEST_CONTENT_DIR=\"D:/src/thx/SonicSnitch/DetectionEngine/InversePanning/../test-content\"",
"UNICODE",
"WIN32",
"WIN64",
"_ENABLE_EXTENDED_ALIGNED_STORAGE",
"_UNICODE",
"_WIN64"
],
"compilerPath": "c:/program files/microsoft visual studio/18/community/vc/tools/msvc/14.50.35717/bin/hostx64/x64/cl.exe",
"compilerArgs": [],
"compilerFragments": [
"/DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd",
"-Zc:__cplusplus",
"-permissive-",
"-utf-8"
]
}
},
{
"uri": "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/DemoUI/src/InputSources/FFmpeg/FFmpegInputSource.cpp",
"configuration": {
"includePath": [
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/src",
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/demoui/src",
"d:/src/thx/sonicsnitch/detectionengine/inversepanning/build/ninja/with-vcpkg-qt-online/vcpkg_installed/x64-windows/include",
"c:/qt/6.11.0/msvc2022_64/include/qtcore",
"c:/qt/6.11.0/msvc2022_64/include",
"c:/qt/6.11.0/msvc2022_64/mkspecs/win32-msvc"
],
"defines": [
"GTEST_LINKED_AS_SHARED_LIBRARY=1",
"QT_CORE_LIB",
"TEST_CONTENT_DIR=\"D:/src/thx/SonicSnitch/DetectionEngine/InversePanning/../test-content\"",
"UNICODE",
"WIN32",
"WIN64",
"_ENABLE_EXTENDED_ALIGNED_STORAGE",
"_UNICODE",
"_WIN64"
],
"compilerPath": "c:/program files/microsoft visual studio/18/community/vc/tools/msvc/14.50.35717/bin/hostx64/x64/cl.exe",
"compilerArgs": [],
"compilerFragments": [
"/DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd",
"-Zc:__cplusplus",
"-permissive-",
"-utf-8"
]
}
}
],
"partialMatches": [],
"targetCount": 42,
"executablesCount": 11,
"librariesCount": 1,
"targets": []
},
"settings": [
{
"communicationMode": "automatic",
"useCMakePresets": "always",
"configureOnOpen": false
}
]
}
Debug Log
[configure-debug.log](https://github.com/user-attachments/files/26993568/configure-debug.log)
Additional Information
This repo is a minimal configuartion to reproduce.
Brief Issue Summary
When using "Compile Active File" with MSVC + Ninja Multi-Config on Windows, CMake Tools incorrectly quotes compiler arguments that end with a backslash. CMake emits /Fd
\ (with a trailing backslash) when no explicit PDB name is configured. CMake Tools wraps this in quotes, but in cmd.exe a backslash before a closing quote is an escape — so the quote is not treated as closing and the next token (/FS) is consumed as part of the argument.Observed compile command:
"/FdCMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ /FS"
cl.exe error:
fatal error C1041: cannot open program database
\ /FS as a single argument and interprets \FS.pdb as the PDB filename. The /FS flag is lost.'...\CMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ \FS.pdb';
if multiple CL.EXE write to the same .PDB file, please use /FS
cl.exe receives /Fd
Expected: Arguments with trailing backslashes are quoted correctly, e.g. by doubling the backslash or appending a space before the closing quote ("/FdCMakeFiles\INPUT_TESTS.dir\RelWithDebInfo\ ") — or by not quoting the argument at all since it contains no spaces.
Workaround: Set COMPILE_PDB_NAME on the target so CMake emits an explicit filename (/Fd
<name>.pdb) instead of a bare directory path, eliminating the trailing backslash.Steps to reproduce:
CMake project, Ninja Multi-Config generator, MSVC toolchain, CMAKE_EXPORT_COMPILE_COMMANDS=ON
Do not set COMPILE_PDB_NAME on any target (default CMake behaviour)
Open a .cpp source file and run CMake: Compile Active File
Environment:
Windows 11
MSVC (cl.exe)
Generator: Ninja Multi-Config
CMake Tools version: 1.23.52
VS Code version: 1.117.0
CMake Tools Diagnostics
{ "os": "win32", "vscodeVersion": "1.117.0", "cmtVersion": "1.23.52", "configurations": [ { "folder": "d:\\src\\thx\\SonicSnitch\\DetectionEngine\\InversePanning", "cmakeVersion": "4.2.3", "configured": true, "generator": "Ninja Multi-Config", "usesPresets": true, "compilers": { "CXX": "C:/Program Files/Microsoft Visual Studio/18/Community/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe" } } ], "cpptoolsIntegration": { "isReady": true, "hasCodeModel": true, "activeBuildType": "Debug", "buildTypesSeen": [ "Debug", "Release", "RelWithDebInfo" ], "requests": [ "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/tests/decoder_pump_test.cpp", "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/DemoUI/src/InputSources/FFmpeg/FFmpegInputSource.cpp" ], "responses": [ { "uri": "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/tests/decoder_pump_test.cpp", "configuration": { "includePath": [ "d:/src/thx/sonicsnitch/detectionengine/inversepanning/src", "d:/src/thx/sonicsnitch/detectionengine/inversepanning/demoui/src", "d:/src/thx/sonicsnitch/detectionengine/inversepanning/build/ninja/with-vcpkg-qt-online/vcpkg_installed/x64-windows/include", "c:/qt/6.11.0/msvc2022_64/include/qtcore", "c:/qt/6.11.0/msvc2022_64/include", "c:/qt/6.11.0/msvc2022_64/mkspecs/win32-msvc" ], "defines": [ "GTEST_LINKED_AS_SHARED_LIBRARY=1", "QT_CORE_LIB", "TEST_CONTENT_DIR=\"D:/src/thx/SonicSnitch/DetectionEngine/InversePanning/../test-content\"", "UNICODE", "WIN32", "WIN64", "_ENABLE_EXTENDED_ALIGNED_STORAGE", "_UNICODE", "_WIN64" ], "compilerPath": "c:/program files/microsoft visual studio/18/community/vc/tools/msvc/14.50.35717/bin/hostx64/x64/cl.exe", "compilerArgs": [], "compilerFragments": [ "/DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd", "-Zc:__cplusplus", "-permissive-", "-utf-8" ] } }, { "uri": "file:///d%3A/src/thx/SonicSnitch/DetectionEngine/InversePanning/DemoUI/src/InputSources/FFmpeg/FFmpegInputSource.cpp", "configuration": { "includePath": [ "d:/src/thx/sonicsnitch/detectionengine/inversepanning/src", "d:/src/thx/sonicsnitch/detectionengine/inversepanning/demoui/src", "d:/src/thx/sonicsnitch/detectionengine/inversepanning/build/ninja/with-vcpkg-qt-online/vcpkg_installed/x64-windows/include", "c:/qt/6.11.0/msvc2022_64/include/qtcore", "c:/qt/6.11.0/msvc2022_64/include", "c:/qt/6.11.0/msvc2022_64/mkspecs/win32-msvc" ], "defines": [ "GTEST_LINKED_AS_SHARED_LIBRARY=1", "QT_CORE_LIB", "TEST_CONTENT_DIR=\"D:/src/thx/SonicSnitch/DetectionEngine/InversePanning/../test-content\"", "UNICODE", "WIN32", "WIN64", "_ENABLE_EXTENDED_ALIGNED_STORAGE", "_UNICODE", "_WIN64" ], "compilerPath": "c:/program files/microsoft visual studio/18/community/vc/tools/msvc/14.50.35717/bin/hostx64/x64/cl.exe", "compilerArgs": [], "compilerFragments": [ "/DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd", "-Zc:__cplusplus", "-permissive-", "-utf-8" ] } } ], "partialMatches": [], "targetCount": 42, "executablesCount": 11, "librariesCount": 1, "targets": [] }, "settings": [ { "communicationMode": "automatic", "useCMakePresets": "always", "configureOnOpen": false } ] }Debug Log
Additional Information
This repo is a minimal configuartion to reproduce.