(cmake-format) CMake 格式化工具
文章目录
🧮介绍
cheshirekow/cmake_format: Source code formatter for cmake listfiles.
cmake-format
是cmakelang
下的一个子项目:The
cmakelang
project provides Quality Assurance (QA) tools forcmake
:
cmake-annotate
can generate pretty HTML from your listfilescmake-format
can format your listfiles nicely so that they don’t look like crap.cmake-lint
can check your listfiles for problemsctest-to
can parse a ctest output tree and translate it into a more structured format (either JSON or XML).
很可惜该项目已经两年没更新了
🧮安装
# 查询包
pip_search cmake-format
# 安装
pip install cmake-format
# 卸载
pip uninstall cmake-format
🧮使用
最简单直接的使用
直接指定目标的 cmake 文件。
cmake-format CMakeLists.txt
🗳️选项 options
option | 含义 |
---|---|
-h, --help | 显示帮助信息并退出 |
-v, --version | 显示程序版本号并退出 |
-l, --log-level | |
–dump-config | 如果指定,将默认配置打印到 stdout 并退出 |
–dump | |
–no-help | 当与--dump-config 一起使用时,将省略输出中的 helptext 注释 |
–no-default | 当与--dump-config 一起使用时,将省略任何未修改的配置值 |
-i, --in-place | |
–check | 如果格式化不会改变文件内容,则以状态码0退出,如果会改变,则以状态码1退出 |
-o, --outfile-path | 写入格式化文件的位置。默认为stdout |
-c, --config-files | 配置文件路径 |
🗳️样式配置 config
# 查看默认配置
cmake-format --dump-config
# 指定样式
# + yaml
# + json
# + python (默认)
cmake-format --dump-config [{
yaml,json,python}]
# example
# 注意,这里后缀不要用 yml
cmake-format --dump-config yaml > .cmake-format.yaml
⭐END
🌟help
cmake-format -h
usage:
cmake-format [-h]
[--dump-config {
yaml,json,python} | -i | -o OUTFILE_PATH]
[-c CONFIG_FILE]
infilepath [infilepath ...]
Parse cmake listfiles and format them nicely.
Formatting is configurable by providing a configuration file. The configuration
file can be in json, yaml, or python format. If no configuration file is
specified on the command line, cmake-format will attempt to find a suitable
configuration for each ``inputpath`` by checking recursively checking it's
parent directory up to the root of the filesystem. It will return the first
file it finds with a filename that matches '\.?cmake-format(.yaml|.json|.py)'.
cmake-format can spit out the default configuration for you as starting point
for customization. Run with `--dump-config [yaml|json|python]`.
positional arguments:
infilepaths
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-l {
error,warning,info,debug}, --log-level {
error,warning,info,debug}
--dump-config [{
yaml,json,python}]
If specified, print the default configuration to
stdout and exit
--dump {
lex,parse,parsedb,layout,markup}
--no-help When used with --dump-config, will omit helptext
comments in the output
--no-default When used with --dump-config, will omit any unmodified
configuration value.
-i, --in-place
--check Exit with status code 0 if formatting would not change
file contents, or status code 1 if it would
-o OUTFILE_PATH, --outfile-path OUTFILE_PATH
Where to wr