VSCode使用CMake构件C++项目

VSCode 使用CMake构建

CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.1.0)

include(CTest)
enable_testing()

aux_source_directory(src SRC_SUB)
aux_source_directory(. SRC_CUR)
add_executable(demo ${SRC_SUB} ${SRC_CUR} )
include_directories(include)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

task.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
"options": {
"cwd": "${workspaceFolder}/build/"
},
"tasks": [
{
"label": "cmake",
"type": "shell",
"command":"cmake",
"args": [".."]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true,
},
"command":"mingw32-make.exe",
"args": []
},
{
"label": "Build My Project",
"dependsOn":[
"cmake",
"make"
]
}
],
"version": "2.0.0"
}

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\demo.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build My Project"
}
]
}