vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

`cmake.buildDirectory` shouldn't be ignored if no `binaryDir` in cmake presets

Open Joker-Principal opened this issue 8 months ago • 4 comments

Brief Issue Summary

I have read this issue.

In my case, I use CMake presets in several IDEs. However, some conflict happened when I set the same build directory in different IDEs. So I tried to set a separate directory in each IDE, and remove all binaryDir fields in my CMakePresets.json.

I have tested that cmake --preset=xxx -B my/build/dir -S . successfully build the project in my/build/dir.

But in vscode-cmake-tools, when I set "cmake.buildDirectory: "my/build/dir" in settings.json, it's ignored, and an option, -B out/build, is always appended in command line.

Then I tried to set "cmake.configureArgs": [ "-B my/build/dir" ], now the command line become cmake ... -B my/build/dir -B out/build. The directory out/build is used because of the order of options.

Along the way, I noticed that vscode-cmake-tools doesn't seem to use cmake --preset(available from cmake 3.19), instead it parses the CMakePresets.json and setups the command line options. This can be a nice workaround for old version cmake users, but make the command line complex, which is hard to check errors.

Joker-Principal avatar Mar 06 '25 03:03 Joker-Principal

Hi @Joker2387089590 , thanks for reporting issue here! I reproduced this on our side, below video is our repro steps, in settings.json "cmake.buildDirectory": "${workspaceFolder}/build"
and no binaryDir in cmake presets, but after configuring, it shows "-B xxx/out/build/xxx" in output window. Please confirm if this is your issue?

Image

From this doc, it says The following settings in settings.json either duplicate options in CMakePresets.json or no longer apply. These settings will be ignored when CMakePresets.json integration is enabled.

I'm not sure if cmake.buildDirectory is no longer apply, this issue is by design. @gcampbell-msft could you please help confirm?

Amy-Li03 avatar Mar 06 '25 09:03 Amy-Li03

Thanks for your reply :)

Hi @Joker2387089590 , thanks for reporting issue here! I reproduced this on our side, below video is our repro steps, in settings.json "cmake.buildDirectory": "${workspaceFolder}/build" and no binaryDir in cmake presets, but after configuring, it shows "-B xxx/out/build/xxx" in output window. Please confirm if this is your issue?

Yes.

I'm not sure if cmake.buildDirectory is no longer apply, this issue is by design.

So I think this can be an enhancement, make it free for users to determine the matter they set the build directory.

Then I find that the binaryDir is set by these codes. I think set ${cmake.buildDirectory} as default is reasonable enough if no binaryDir in CMakePresets.json

https://github.com/microsoft/vscode-cmake-tools/blob/5107f7edfb4a748c0ef1606bf4db2a2f54cb491e/src/presets/preset.ts#L1321C1-L1330C6

Joker-Principal avatar Mar 07 '25 08:03 Joker-Principal

@Joker2387089590 I understand what you're asking.

However, I'd actually rather dig into why your use of binaryDir wasn't working. Could you give us more information on this so that we can investigate?

gcampbell-msft avatar Mar 07 '25 15:03 gcampbell-msft

@Joker2387089590 I understand what you're asking.

However, I'd actually rather dig into why your use of binaryDir wasn't working. Could you give us more information on this so that we can investigate?

In my project:

  • I use two IDEs, Qt Creator and VS Code, to debug a C++ server and a Python client at the same time.
  • I need these IDEs to automatically execute cmake configure when some project files modified, so that some files will be auto-generated or downloaded during configuring.
  • Then I found conflicts happened on the file operations.

Now, when one of them are configuring the project, I have not to view another one to avoid triggerring the auto-config.

Joker-Principal avatar Mar 09 '25 19:03 Joker-Principal

I just ran into this today. Our presets specifically do not set binaryDir. The path passed to cmake -B always starts with ${cmake.buildDirectory}/out, and there is no setting I can find that changes this. Is this value literally hardcoded?

fsecilia avatar Jul 25 '25 08:07 fsecilia