vscode-cmake-config

  1. 配置cmake任务json
  2. DeBug 配置

配置cmake任务json

  • tasks.json
{
	"version": "2.0.0",
	"tasks": [
		{
		// 1. cmake 配置
			"type": "cppbuild",
			"label": "CMake 配置",
			"command": "cmake",
			"args": [
				"-DCMAKE_BUILD_TYPE=Debug",
				"-S .",
				"-B Build"
			],
			"problemMatcher":"$msCompile",
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"options": {
				"cmd":"${workspaceFolder}"
			}
		},
		// 2. cmake 构建
		{
			"type": "cppbuild",
			"label": "CMake 构建",
			"command": "cmake",
			"args": [
				"--build",
				"Build"
			],
			"problemMatcher":"$msCompile",
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"options": {
				"cmd":"${workspaceFolder}"
			},
			"dependsOn":[
				"CMake 配置"
			]
		},
		// 3. 删除 Build
		{
			"type": "shell",
			"label": "删除构建目录",
			"command": "rm",
			"args": [
				"-rf",
				"Build"
			],
			"problemMatcher":"$msCompile",
			"group": {
				"kind": "build",
				"isDefault": false
			},
			"options": {
				"cmd":"${workspaceFolder}"
			}

		},
		// 4. 运行可执行文件
		{
			"type":"shell",
			"label": "执行可执行文件",
			"command": "${workspaceFolder}/Build/cmake_debug",
			"problemMatcher": "$msCompile",
			"group": {
				"kind": "test",
				"isDefault": true
			},
			"options": {
				"cwd": "${workspaceFolder}/Build"
			},
			"dependsOn":"CMake 构建"
		}
	]
}

cmake配置

cmake编译

执行可执行文件

删除Build目录

DeBug 配置

  • launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cppdbg",
            "miDebuggerPath": "/usr/bin/gdb",
            "request": "launch",
            "name": "C++ CMake Debug",
            "program": "${workspaceFolder}/Build/cmake_debug",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "CMake 构建",
        }
    ]
}
github