(cmake-format) CMake 格式化工具

(cmake-format) CMake 格式化工具

🧮介绍

cheshirekow/cmake_format: Source code formatter for cmake listfiles.

cmake-formatcmakelang 下的一个子项目:

The cmakelang project provides Quality Assurance (QA) tools for cmake:

  • cmake-annotate can generate pretty HTML from your listfiles
  • cmake-format can format your listfiles nicely so that they don’t look like crap.
  • cmake-lint can check your listfiles for problems
  • ctest-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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天赐细莲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值