VScode CMake插件使用指南

使用插件可以一键创建任务,利用CMake插件编译软件。

配置CMake环境

下载插件

参考文档:https://vector-of-bool.github.io/docs/vscode-cmake-tools/index.html
Github:https://github.com/microsoft/vscode-cmake-tools/tree/main

配置args和选项

打开设置,搜索cmake,找到settings.json。修改cmake.configureArgscmake.configureSettings

配置组合选项

使用Variant来管理编译选项,在.vscode中新建cmake-variants.yaml,写入:

Model:
    default: IPC
    choices:
        IPC:
            short: IPC
            long: SPM IPC Model
            settings:
                CONFIG_TFM_SPM_BACKEND: IPC
        SFN:
            short: SFN
            long: SPM SFN Model
            settings:
                CONFIG_TFM_SPM_BACKEND: SFN

REG_TEST:
    default: Yes
    choices:
        Yes:
            short: Reg
            long: Enable regression test
            settings:
                TEST_S: ON
                TEST_NS: ON
        No:
            short: No Reg
            long: Disable regression test
            settings:
                TEST_S: OFF
                TEST_NS: OFF

ISOLATION_LEVEL:
    default: L1
    choices:
        L1:
            short: L1
            long: ISOLATION L1
            settings:
                TFM_ISOLATION_LEVEL: 1
        L2:
            short: L2
            long: ISOLATION L2
            settings:
                TFM_ISOLATION_LEVEL: 2
        L3:
            short: L3
            long: ISOLATION L3
            settings:
                TFM_ISOLATION_LEVEL: 3

在底部状态栏找到cmake:

点击第二栏,进入选择:

配置task

.vscode中创建tasks.json。dependsOn表示任务的依赖关系。

{
	"version": "2.0.0",
	"tasks": [
		// ################################# Clean #############################
		{
			"type": "shell",
			"label": "TF-M Build Clean",
			"command": "rm -rf cmake_build",
			"problemMatcher": [],
			"detail": "Clean Build Folder"
		},
		// ################################# Configure #########################
		{
			"type": "cmake",
			"label": "TF-M config",
			"command": "configure",
			"problemMatcher": [],
			"detail": "TF-M CMake Configuration",
			"dependsOn": [
				"TF-M Build Clean"
			]
		},
		// ################################# Build #############################
		{
			"type": "cmake",
			"label": "TF-M build",
			"command": "build",
			"targets": [
				"all"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"problemMatcher": [],
			"detail": "TF-M Build",
			"dependsOn": [
				"TF-M config"
			]
		},
		// ################################# Test ##############################
		{
			"type": "shell",
			"label": "RUN FVP",
			"command": "./script/run_an521_fvp.sh",
			"group": {
				"kind": "test",
				"isDefault": true
			},
			"problemMatcher": [],
			"detail": "RUN TF-M on AN521 FVP",
			"dependsOn": [
				"TF-M build"
			]
		},
		{
			"type": "shell",
			"label": "RUN QEMU",
			"command": "./script/run_an521_qemu.sh",
			"group": {
				"kind": "test",
				"isDefault": true
			},
			"problemMatcher": [],
			"detail": "RUN TF-M on AN521 QEMU",
			"dependsOn": [
				"TF-M build"
			]	
		},
		// ################################# Debug #############################
		{
			"type": "shell",
			"label": "Debug QEMU",
			"command": "./script/debug_an521_qemu.sh",
			"group": {
				"kind": "test",
				"isDefault": true
			},
			"problemMatcher": [],
			"detail": "Debug TF-M on AN521 QEMU",
			"dependsOn": [
				"TF-M build"
			]
		},
	]
}

按下ctrl+P,Mac为Command键,输入task加空格,弹出以上任务:

注意上面的任务中,group表示任务分组,例如test分组,在ctrl+P中输入>tasks看到任务的分组:

这里可以为任务设置快捷键,例如当前使用Command+^+T打开测试任务分组:

点击即弹出终端开始执行任务。