CMake官方文档学习
根据官方文档学习CMake,由于对linux,Vscode,C++均不熟练,多阅读一些文档,有助于帮助理解这几个东西都干了什么
CMake Tools fro Visual studio Code documention
https://github.com/microsoft/vscode-cmake-tools/blob/develop/docs/README.md
分成
How to (create a new project, configure, build a project,debug a new project, pass command-line arguments to the debugger,)
Kits(how kits are found and defined, Kit options)
Configure(Cmake configuration process overview, the cmake tools configure step, the configure step outside of Cmake tools, clean configure)
variants(varinats yaml example, schema, settings, options, how variants are applied, large variant file example)
build(build the default target, build a single target, how cmake tools builds your project, clean child)
debug and launch(select a launch target, quick debugging, debug using a launch.json file, run without debugging)
configure cmake tools settings(cmake tools settings, variable substitution)
troubleshoot cmake tools
frequently asked questions
主要就是前面的这些,开始创建一个project,配置configure,编译build,找bug debug, pass command-line to debug,下面就是这些功能的详细部分。
Get Started with CMake Tools on Linux
需要 1 Vscode 2 C++ extensions 3 CMake Tools extension for vs code 4 install cmake, a compiler, a debugger, and build tools.
确保安装 1 cmaek --version 2 compiler, debugger and build tools (make) gcc for compiler, gdb to debug, make to build the project
gcc -v sudo apt-get update sudo apt-get install build-essential gdb
创建CMakeProject
1 有一个CMakeLists.txt 2 有一个main.cpp文件
或者 mkdir cmakeQuickStart cd cmakeQuickStart code .
code .就是用vs 新打开这个文件夹
Ctrl+ shit + P Cmake: quick start 快速开始
然后选择kit工具 选择 正常的gcc工具就行,选择Executable (如果想要自己写一个别人可以调用的第三方库,那么选library,否则 选可执行)
这样,等下就会创建 CMakeLists.txt main.cpp 和一个build 的文件夹
configure project 配置项目
有两个东西,必须配置 1 select a kit 2 select a variant
kit 就是gcc解释器 如果想改 Crl + Shirt + P CMake: select a kit 就可以
variant: 就是你想如何build项目,Debug Release,MinRelSize and RelWithDebInfo
CMake: select variant 选择Debug 就可以debug
然后 CMake: build 就可以了
创建Project ,可以这样创建,主要看CMakeLists.txt怎么写,都是什么意思
configure refers to detecting requirements and generating the build files that will produce the final compiled artifacts
CMake Cache 是一个key-value pairs ,包含:1 values 很难改的东西,#include 库之类的 2 很少变的,path to a header/library 3 values control to the developer
这个文件,在CMake scripts are run之前传给Cmake。允许control the build setting
除非 overwritten or deleted 否则 CMake Cache 在CMake运行之间 一直存在
CMake 不去自己编译(编译),configure的结果,取决于CMake generator,也就是 CMake自己写一套东西,用generator和系统编译工具用来编译
generator: ninja, makefile, visual studio 这几个都是generator的东西
配置的步骤 CMake Tools drives CMake via the cmake-file-api
1 active kit(SoftwarDevelopmentKit--SDK软件开发工具包)
kit 提供 information about the toolchains,一系列的工具
ToolChain, cmake tools 设置 Cmake cache variable CMAKE_TOOLCHAIN_FILE
Compilers, CMAKE_<LANG>_COMPILER 变量
如果是Visual Studio CMake Tools 设置必要的环境变量去选择vs 安装 设置CC CXX to cl.exe
2 generator
配置是 cmake.generator cmake.preferredGenerators
3 configuration options 配置选项
4 configure environment

浙公网安备 33010602011771号