Skip to content
\n

For release builds, I have a different task:

\n
 \"label\": \"LCR\",\n \"type\": \"shell\",\n \"command\": \"cmake -S . -B ./cmake/rel -DCMAKE_BUILD_TYPE=Release; cmake --build ./cmake/rel --config Release\"\n
\n

Corresponding to a debug or release code that I am working on/going to run, I have corresponding configurations in c_cpp_properties.json

\n
{\n    \"name\": \"LCD\",\n    \"compileCommands\": \"${workspaceFolder}/cmake/dbg/compile_commands.json\"\n},\n{\n    \"name\": \"LCR\",\n    \"compileCommands\": \"${workspaceFolder}/cmake/rel/compile_commands.json\"\n}\n
\n

Currently, I manually choose either of these configurations (via VSCode command C_Cpp.ConfigurationSelect so that the correct compile_commands.json can be used for intellisense/highlighting of code, etc.

\n

Is there a way to pass the VSCode command of having the LCD configuration be selected automatically when task LCD is run?

\n

XPost from SO

\n

This is possibly related to this issue or this but these issues are so many years apart and it is not clear to me if there is a command that does take an optional parameter to set the active configuration. Is the following a syntactically correct tasks.json task?

\n
 \"label\": \"LCD\",\n \"type\": \"shell\",\n \"command\": \"C_Cpp.ConfigurationSelect=\\\"LCD\\\"; cmake -S . -B ./cmake/dbg -DCMAKE_BUILD_TYPE=Debug; cmake --build ./cmake/dbg --config Debug\",\n
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

You can take a look at \"input\" variables and try a \"command\" type. The name of the argument for this command is \"configurationName\", but the command itself returns void so I don't know if you'll run into trouble with the shell task when it resolves this type of variable.

","upvoteCount":0,"url":"https://github.com/microsoft/vscode-cpptools/discussions/13307#discussioncomment-12303377"}}}

Is there a way to pre-pend or post-pend a VSCode command C_Cpp.ConfigurationSelect before/after a tasks.json task has been run? #13307

Answered by bobbrow
onecable5781 asked this question in Q&A
Discussion options

You must be logged in to vote

You can take a look at "input" variables and try a "command" type. The name of the argument for this command is "configurationName", but the command itself returns void so I don't know if you'll run into trouble with the shell task when it resolves this type of variable.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@onecable5781
Comment options

@bobbrow
Comment options

Answer selected by onecable5781
@bobbrow
Comment options

@onecable5781
Comment options

@starball5
Comment options

@onecable5781
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants