vscode-cmake-tools
vscode-cmake-tools copied to clipboard
Customize the environment variables when launch the target in the terminal
Brief Issue Summary
When using the launch target feature of the cmake plugin, the cmake plugin will start a terminal and then run the target directly.
But I'd like to be able to plug in some custom configurations after launching the terminal like environment variables, etc. (because there may be multiple environment variables with the same key in different projects, and I don't want them to pollute the global environment variables).
Admittedly, we can manually add environment variables to the terminal and reuse that terminal afterward, but the problem is that the terminal needs to be manually configured after each launch of vscode, which is tedious. (In my personal case, in order to run the Qt program, I need to temporarily add the corresponding bin directory to the system path in the terminal every time I start the terminal, which is troublesome)
I didn't find the relevant settings to fix this, I hope to be able to add this feature in the subsequent updates of the cmake plugin, thanks.
CMake Tools Diagnostics
No response
Debug Log
No response
Additional Information
No response
Thanks for the suggestion, marking this as a request and putting it on our backlog. Thanks!
Seconding this, would be much appreciated!
Finally found, thanks to this question and answer, that this feature is not enabled!
I've been stumbling for a couple of days trying to give my executable a chance to use a specific project environment in Launch mode, without any success. Please take into account that this is an essential feature when the program uses 3rd party DLLs: the PATH (Windows) or LD_LIBRARY_PATH (Linux) must be set accordingly for the program execution.
According to the documentation (https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-settings.md), "cmake.environment" in settings.json should be used for running also, but the fact is that it is only applied when debugging. Curiously, "cmake.debugConfig" is applied for both cases (at least "args" are used for Launch and Debug modes).
@AlMar-Devel Do you have a repro project? I have tested this for a similar issue #3687 and I wasn't able to reproduce the issue. We add the configure environment, which for presets and for kits should include the cmake.environment
setting.
I can reproduce that cmake.environment & cmake.debugConfig.environment & cmake.testEnvironment all apply to debugging projects and does not apply to launching projects from terminal. In my case, i'm going to set QT_QPA_PLATFORM=xcb. Is it intended?
Hi @1m188 @AlMar-Devel @mcwindy, As indicated by the mentioned PR, I think the root cause of this issue is how we re-use the same terminal for multiple launches, which means changes to the environment are not applied in the re-used terminal. Just to confirm that is the issue, I attached a vsix of cmake-tools with this change included. If one of you can install this vsix by renaming the .zip extension to .vsix and running the "Install from VSIX" command in the Extensions Pane, then testing that either cmake.Environment or cmake.debugConfig.environment variables are applied during a Terminal Launch, that would be great. Thanks!
I completed the PR, so the fix should be available in the next release. Please open a new issue if the problem persists. Thanks!