CL环境变量
PATH
# cmake路径
VisualStudio\IDE\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
# Ninja路径
VisualStudio\IDE\VC\Auxiliary\Build
# MSBuild路径
VisualStudio\IDE\Msbuild\Current\Bin
# rc.exe路径
Windows Kits\10\bin\10.0.19041.0\x64
# cl.exe和link.exe路径
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\bin\Hostx64\x64\cl.exe
INCLUDE
是cl.exe
的查找路径
# C++标准库头文件路径
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\include
# C库头文件路径
Windows Kits\10\Include\10.0.19041.0\ucrt
LIB
是link.exe
的查找链接路径
# 系统相关的一些库
Windows Kits\10\Lib\10.0.19041.0\um\x64
# C库
Windows Kits\10\Lib\10.0.19041.0\ucrt\x64
# C++开发和调试库
VisualStudio\IDE\VC\Tools\MSVC\14.30.30705\lib\x64
mingw环境变量
需要先安装mingw64和cmake,然后设置PATH
环境变量
# make、gcc和ld路径路径
mingw64\bin
CPLUS_INCLUDE_PATH
和C_INCLUDE_PATH
是gcc
的查找路径
mingw64/x86_64-w64-mingw32/include
LIBRARY_PATH
是ld.exe
的查找链接路径
mingw64/x86_64-w64-mingw32/lib
配置launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(msvc) Launch",
"type": "cppvsdbg",//调试器类型
"request": "launch",//launch调试或者attach调试
"program": "${command:cmake.launchTargetPath}",//当前CMake Tools下的活跃程序
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
}
],
"externalConsole": true
}
]
}
其中type
字段指定调试器类型,cppvsdbg表示MSVC调试器;cppdbg表示gdb或者lldb调试器,通过字段"MIMode": "lldb"
、"MIMode": "gdb"
区分调试器类型。
配置task.json
参考CMakeTools+CMakePresets下配置task.json
配置生成cmake缓存。
{
"type": "cmake",
"label": "CMake: configure",
"command": "configure",
"preset": "${command:cmake.activeConfigurePresetName}",
"detail": "CMake template configure task"
}
构建生成二进制文件。
{
"type": "cmake",
"label": "CMake: build",
"command": "build",
"preset": "${command:cmake.activeBuildPresetName}",
"detail": "CMake template build task"
}
清除缓存。
{
"type": "cmake",
"label": "CMake: clean",
"command": "clean",
"detail": "CMake template clean task"
}
清除并重新构建。
{
"type": "cmake",
"label": "CMake: clean rebuild",
"command": "cleanRebuild",
"detail": "CMake template clean rebuild task"
}
CMakePresets配置
文件标准结构如下。
{
"version":3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets":[],
"buildPresets":[],
"testPresets":[],
"workflow":[]
}
configurePresets
用于配置项目,configurePresets
标准结构如下,cacheVariables
为cmake内的变量赋值,environment
指定环境变量。
"configurePresets": [
{
"name": "stm32-base",
"hidden": true,
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {},
"environment":{},
"warnings": {}
}
]
以cacheVariable
为例
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
}
以enviroment
为例
"environment": {
"C_INCLUDE_PATH": "mingw64/x86_64-w64-mingw32/include",
"CPLUS_INCLUDE_PATH": "mingw64/x86_64-w64-mingw32/include"
}
buildPresets
用于构建程序,configurePresets
指定一个configurePresets配置。
"buildPresets": [
{
"name": "Linux x64-debug",
"displayName": "MingGW 2022 Release - amd64 - Debug",
"configurePreset": "Linux x64",
"jobs": 8
}
]