本文共 2278 字,大约阅读时间需要 7 分钟。
之前开发一个软件,使用的是vscode + cmake + mingw三个结合开发的,需要使用vscode 编写代码,然后使用cmake 根据设置好的规则生成makefile 文件,最后使用mingw编译生成最终的可执行文件。之前一直是使用vscode 的终端指令输入 cmake -G "MinGW Makefiles" .. 生成Makefile 文件,然后使用mingw 编译文件:mingw32-make
今天突发奇想,准备使用快捷键结合自定义脚本的方式来实现快捷键编译。
第一步是找到运行任务的快捷键 找到快捷键的方式是 文件->首选项->键盘快捷方式。
之后就是将运行脚本绑定到自己方便的快捷键上,我这里是绑定到了ctrl + r ,也不知道是不是默认的。
在编辑界面按下快捷键 就会弹出运行任务的选项。
根据我的需求,我需要1. 生成makefile 2.编译(普通编译)3.快速(多核2)编译(make 带 -j 参数) 4.清理编译产生的文件
生成任务脚本的方法就是在工程的 .vscode 目录下创建task.json文件。文件的内容如下
{ "tasks": [ { "type": "shell", "label": "cmake build make file ", "command": "cmake", "args": [ "-G", "MinGW Makefiles", "F:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/src/" ], "options": { "cwd": "F:/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/src/build" }, "problemMatcher": [ "$gcc" ], "group": "build" } { "type": "shell", "label": "mingw32-make ", "command": "mingw32-make", "args": [ ], "options": { "cwd": "F:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/src/build" }, "problemMatcher": [ "$gcc" ], "group": "build" } { "type": "shell", "label": "mingw32-make -j12", "command": "mingw32-make -j12", "args": [ ], "options": { "cwd": "F:/xxxxxxxxxxxxxxxxxxxxxxxxx/src/build" }, "problemMatcher": [ "$gcc" ], "group": "build" } { "type": "shell", "label": "clean", "command": "del * -r", "args": [ ], "options": { "cwd": "F:/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/src/build" }, "problemMatcher": [ "$gcc" ], "group": "build" } ]}
其实我也每太懂这个文件的各个项目的作用,大搞就知道这个会执行指定的shell 指令其中的label选项就是 功能的名字
command 就是要执行的shell 命令 也就是之前我需要手打上去的指令
cwd 参数是当前指令的执行路径,这个挺重要的,因为我是固定的开发,所以我就直接找到本地的路径添加上去就可以了。
希望有用。有其他问题可以给我留言。
转载地址:https://jeason.blog.csdn.net/article/details/109263146 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!