feat: add cmake.md
cheatsheet (#19).
This commit is contained in:
parent
600dbc6fef
commit
4662fb8071
@ -18,6 +18,7 @@ Quick Reference
|
|||||||
|
|
||||||
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||||
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
||||||
|
[CMake](./docs/cmake.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
||||||
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||||
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
|
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
|
||||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||||
|
114
docs/cmake.md
Normal file
114
docs/cmake.md
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
CMake 备忘清单
|
||||||
|
===
|
||||||
|
|
||||||
|
本清单提供了对 CMake 的入门简要概述,以及 CMake 常用示例
|
||||||
|
|
||||||
|
入门
|
||||||
|
---
|
||||||
|
|
||||||
|
### Hello CMake
|
||||||
|
|
||||||
|
CMake 是一个用于配置跨平台源代码项目应该如何配置的工具建立在给定的平台上。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
├┈ CMakeLists.txt # 希望运行的 CMake 命令
|
||||||
|
╰┈ main.cpp # 带有 main 的源文件
|
||||||
|
```
|
||||||
|
|
||||||
|
在此项目上运行 `CMake` 时,系统会要求您提供二进制目录,运行 `CMake` 不会创建最终的可执行文件,而是会为 `Visual Studio`、`XCode` 或 `makefile` 生成项目文件。 使用这些工具构建该项目
|
||||||
|
|
||||||
|
#### CMakeLists.txt
|
||||||
|
|
||||||
|
```cmake
|
||||||
|
# 设置可以使用的最低 CMake 版本
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
# 设置项目名称
|
||||||
|
project (hello_cmake)
|
||||||
|
# 添加可执行文件
|
||||||
|
add_executable(hello_cmake main.cpp)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### main.cpp
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
std::cout << "Hello CMake!" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 编译示例
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mkdir build # 创建 build 目录
|
||||||
|
$ cd build # 进入目录
|
||||||
|
$ cmake .. # 目录的上一级目录运行命令
|
||||||
|
$ ./hello_cmake # 运行生成的 hello_cmake
|
||||||
|
Hello CMake!
|
||||||
|
```
|
||||||
|
|
||||||
|
### cmake
|
||||||
|
<!--rehype:wrap-class=col-span-2-->
|
||||||
|
|
||||||
|
生成项目构建系统
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake [<options>] <path-to-source | path-to-existing-build>bash
|
||||||
|
$ cmake [<options>] -S <path-to-source> -B <path-to-build>
|
||||||
|
```
|
||||||
|
|
||||||
|
建立一个项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --build <dir> [<options>] [-- <build-tool-options>]
|
||||||
|
```
|
||||||
|
|
||||||
|
安装项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --install <dir> [<options>]
|
||||||
|
```
|
||||||
|
|
||||||
|
打开一个项目
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --open <dir>
|
||||||
|
```
|
||||||
|
|
||||||
|
运行脚本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake [-D <var>=<value>]... -P <cmake-script-file>
|
||||||
|
```
|
||||||
|
|
||||||
|
运行命令行工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake -E <command> [<options>]
|
||||||
|
```
|
||||||
|
|
||||||
|
运行查找包工具
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --find-package [<options>]
|
||||||
|
```
|
||||||
|
|
||||||
|
运行工作流预设
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --workflow [<options>]
|
||||||
|
```
|
||||||
|
|
||||||
|
查看帮助
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cmake --help[-<topic>]
|
||||||
|
```
|
||||||
|
|
||||||
|
另见
|
||||||
|
----
|
||||||
|
|
||||||
|
- [CMake Examples](http://ttroy50.github.io/cmake-examples/) _(ttroy50.github.io)_
|
3
scripts/assets/cmake.svg
Normal file
3
scripts/assets/cmake.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
|
||||||
|
<path d="M11.769.066.067 23.206l12.76-10.843zm11.438 23.868L7.471 17.587 0 23.934zm.793-.198L12.298.463l1.719 19.24zM12.893 12.959l-5.025 4.298 5.62 2.248z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 274 B |
Loading…
x
Reference in New Issue
Block a user