本文主要是一个配置参考范例:
1、程序的目录结构:
2、CMakeLists.txt:重要的是set语句,编译成debug模式
cmake_minimum_required(VERSION 3.0)
project(SOLIDER)
include_directories(${CMAKE_SOURCE_DIR}/include)
add_compile_options(-std=c++11 -Wall)
set(CMAKE_BUILD_TYPE "Debug")
add_executable(solider_cmake main.cpp src/Gun.cpp src/solider.cpp)
3、主目录新建build文件夹,cmake操作在build文件夹中进行;
4、主要参数:(1)program:指向要调试程序的绝对路径;(2)preLaunchTask:指示在调试之前先执行哪些命令,和tasks.json中相关;
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/solider_cmake",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask":"Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json:包含了三个任务,第一个任务执行cmake,第二个任务执行make,第三个任务名称是Build,执行cmake和make两个任务,将Build设置成launch.json中preLaunchTask的值,正是代表,在调试之前先执行cmake和make两个命令;
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"cwd":"${workspaceFolder}/build"
},
"tasks": [
{
"label": "cmake",
"type": "shell",
"command": "cmake",
"args":[
".."
]
},
{
"label":"make",
"group":{
"kind": "build",
"isDefault": true
},
"command":"make",
"args": [
]
},
{
"label":"Build",
"dependsOrder": "sequence",
"dependsOn":[
"cmake",
"make"
]
}
]
}