microsoft / vscode-cmake-tools

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

CMake Tools does not provide the `/Fo` arg (and others) in a cpptools custom configuration #3085

Open Colengms opened 1 year ago

Colengms commented 1 year ago

When I build a file with CMake Tools with a simple example, I'm seeing the following command line used:

cl /c /IZ:\repos\Bug\include /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"MyProject.dir\Debug\\" /Fd"MyProject.dir\Debug\vc143.pdb" /external:W3 /Gd /TP /errorReport:queue Z:\repos\Bug\main.cpp

The custom configuration sent to cpptools is missing some of those arguments:

    "includePath": [
        "z:/repos/bug/include"
    ],
    "defines": [],
    "compilerPath": "c:/program files/microsoft visual studio/2022/enterprise/vc/tools/msvc/14.35.32215/bin/hostx64/x64/cl.exe",
    "compilerArgs": [],
    "compilerFragments": [
        "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1"
    ]

I've not dug into the importance of the other missing arguments, but cpptools specifically needs the /Fo argument. If (and only if) it is a path ending in a backslash or forward slash, it's used as an output directory for .tlh files. We need that path to pass to EDGE for --import_dir. That argument would be needed in order to properly support #using of COM .tlb files in cpptools.

gcampbell-msft commented 1 year ago

@Colengms Thanks for reporting the issue! I have investigated this and the issue is a gap in what is reported by the CMake File API.

We will investigate improving this and/or finding a fix. Thanks!

gcampbell-msft commented 4 months ago

Some context:

It appears to repro with the simplest of examples.

cmake_minimum_required(VERSION 3.10)
project(MyProject VERSION 1.0)
add_executable(MyProject main.cpp)
set(CMAKE_VERBOSE_MAKEFILE on)

It repro's with MSBuild, not Ninja, so just don't set the generator and choose a CL kit.

In the verbose build output, you'll see: /Fo"MyProject.dir\Debug\"

In the C/C++ logging output, I see:

Custom configurations received: ... "compilerFragments": [ "/DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1" ... }