从CMAKE自动生成工程并导入vscode
主要的命令为
CMake:Configure
相当于cmake-gui中做的configure和generate两个功能
CMake:Build
将生成的工程编译,相当于做make
CMake: Clean
清理工程,相当于cmake clean
CMake: Run
做单元测试
窗口下的几个属性是按键,分别可以调整:
Selecting a Kit:选debug,release
Selecting a Variant:选gcc版本
Build:编译工程
配置Cmake属性:
编辑settings.json
以下就是自定义cmakelist.txt文件的地址和生成文件的地址
{
"cmake.configureOnOpen": true,
"cmake.buildDirectory": "${workspaceRoot}/depth_fusion/build",
"cmake.sourceDirectory": "${workspaceRoot}/depth_fusion"
}
CMake:Build不能定制make的选项,可以自己编辑一个编译的文件tasks.json
这里就可以添加 -j8 这样的多线程编译设置
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "makefile build",
"type": "shell",
"command": "make",
"args": [
"-j8"
],
// use options.cwd property if the Makefile is not in the project root ${workspaceRoot} dir
"options": {
"cwd": "${workspaceRoot}/build"
}
}
]
}
然后这个还能和调试的文件关联,也就是设置为调试之前先编译工程
{
// 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": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main",
"args": ["Some args for program"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
// this is link to the tasks.json
"preLaunchTask": "makefile build"
}
]
}
参考:
https://vector-of-bool.github.io/docs/vscode-cmake-tools/getting_started.html
https://www.codeproject.com/Articles/1184735/Quick-Start-to-Use-Visual-Studio-Code-for-Cplusplu