vscode workspace from Cmake

从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:编译工程

_images/no_kits.png

_images/kit_selector.png

_images/kit_selected.png

 

配置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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值