.github
.husky
docs
ansible.md
awk.md
bash.md
c.md
cargo.md
chmod.md
cmake.md
colors-named.md
conan.md
cron.md
css.md
curl.md
djiango.md
docker.md
dockerfile.md
electron.md
emacs.md
emmet.md
emoji.md
es6.md
expressjs.md
ffmpeg.md
find.md
git.md
github-actions.md
gmail.md
golang.md
grep.md
homebrew.md
html-char.md
html.md
htop.md
http-status-code.md
ini.md
iso-639-1.md
java.md
javascript.md
jest.md
jq.md
json.md
koajs.md
lerna.md
lessjs.md
lsof.md
markdown.md
matlab.md
mime.md
mysql.md
netcat.md
netstat.md
nginx.md
npm.md
package.json.md
postgres.md
python.md
quickreference.md
react.md
regex.md
resolutions.md
rust.md
sass.md
screen.md
sed.md
semver.md
sketch.md
ssh.md
styled-components.md
stylus.md
sublime-text.md
swift.md
swiftui.md
tmux.md
toml.md
typescript.md
vim.md
vscode.md
vue.md
vue2.md
webstorm.md
xcode.md
xpath.md
yaml.md
yarn.md
yum.md
scripts
.dockerignore
.gitignore
.lintstagedrc
.prettierignore
.prettierrc
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
package.json
renovate.json
114 lines
2.0 KiB
Markdown
114 lines
2.0 KiB
Markdown
![]() |
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)_
|