khteh
khteh

Reputation: 3976

VSCode CMake targets - what is it and how to use it?

What's targets in tasks.json and how to use it? I have the following in tasks.json:

        {
            "type": "cmake",
            "label": "CMake: build Console",
            "command": "build",
            "targets": [
                "Console"
            ],
            "options": {
                "cwd": "${workspaceRoot}/build"
            },          
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "problemMatcher": [],
            "detail": "CMake build Console"
        },
build task started....
/usr/bin/cmake --build /usr/src/DataStructuresAlgorithms/build --config Debug --target Console --
ninja: error: unknown target 'Console'
build finished with error(s).

I have "CMake Tools" extension installed but I don't see "build target" at the bottom bar at all: enter image description here

Upvotes: 1

Views: 75

Answers (1)

int main
int main

Reputation: 81

That is a reference to CMake targets to be later triggered with VSCode Integration with External Tools via Tasks configured by CMake Tools (extension) Task Provider. Seems that CMakeLists.txt is required to reference existing targets.

Documentation

Targets represent executables, libraries, and utilities built by CMake. Every add_library, add_executable, and add_custom_target command creates a target.

Observation

I am using CMake Tools VSCode extension and at the bottom bar it has "build target" selector from: all, install, project name (executable), linked libraries names. Which is seems to be a GUI analog of tasks.json.

Upvotes: 0

Related Questions