VSCode配置多目录CMake项目

多目录CMake项目指一个workspace下有多个CMake项目,不需要使用CMakeTool插件

修改tasks.json,添加cmake,按照clean->cmake->make的顺序执行

tasks.json
 {
    "version": "2.0.0",
    "options": {
        "cwd": "${fileDirname}/build"
    },
    "tasks": [
        {
            "label": "clean",
            "type": "shell",
            "command": "rm",
            "args": [
                "-rf",
                "./*"
            ]
        },
        {
            "label": "cmake",
            "type": "shell",
            "command": "cmake",
            "args": [
                ".."
            ],
            "dependsOn": [
                "clean" //cmake 之前对build下进行清空
            ]
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "args": [],
            "dependsOn": [
                "cmake" //make之前需要先进行cmake
            ]
        },
    ]
}

修改luanch.json,修改preLaunchTask以在调试器启动前完成cmake

luanch.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/build/${fileBasenameNoExtension}", //这里强制进入build目录下执行
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "make", //找到tasks.json的make任务
            "miDebuggerPath": "/usr/bin/gdb"
        },
    ]
}

 

posted @ 2024-01-16 17:20  celestially98  阅读(170)  评论(0编辑  收藏  举报