一般来说,项目有多种构建风格(尤其是开发),例如调试和发布,并且某些项目还允许跨平台配置。例如,Visual Studio 称之为“平台”(Win32/x&4...)和“配置”,在 QtCreator 中,它是 Kit(工具链)和 Configuration(调试/发布)的组合,而 VSCode C++ 扩展则调用此 Configuration。
我的问题是,虽然可以通过命令查询当前选择的配置,但我找不到在tasks.json或launch.json文件中使用特定于配置的变量的方法。我只能查询配置名称。
作为示例,这是一个示例 C/C++ 属性文件:
{
"configurations": [
{
"name": "linux_gnu_amd64-clang_amd64-10.0.0:debug",
"compileCommands": "${workspaceFolder}/.vscode/linux_gnu_amd64-clang_amd64-10.0.0/debug/compile_commands.json",
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "linux_gnu_amd64-clang_amd64-10.0.0:final",
"compileCommands": "${workspaceFolder}/.vscode/linux_gnu_amd64-clang_amd64-10.0.0/final/compile_commands.json",
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "linux_gnu_amd64-clang_amd64-11.0.0:debug",
"compileCommands": "${workspaceFolder}/.vscode/linux_gnu_amd64-clang_amd64-11.0.0/debug/compile_commands.json",
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++17"
},
{
"name": "linux_gnu_amd64-clang_amd64-11.0.0:final",
"compileCommands": "${workspaceFolder}/.vscode/linux_gnu_amd64-clang_amd64-11.0.0/final/compile_commands.json",
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++17"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这使我能够在配置之间进行选择并获得完美的代码完成。对于构建,我可以依赖配置名称:
{
"tasks": [
{
"label": "build",
"type": "process",
"command": ["/usr/bin/python3"],
"args": …Run Code Online (Sandbox Code Playgroud)