File: configopts.rst

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (597 lines) | stat: -rw-r--r-- 18,096 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
.. _configopts:

======
global
======

include
=======

``include`` specifies a list of additional configuration files to load.
Configurations are merged and individual variables follow a latest-wins
semantic.

-----
parse
-----

additional_commands
===================

Use this variable to specify how to parse custom cmake functions.
See :ref:`additional-cmd`.

vartags
=======

Specify a mapping of variable patterns (python regular expression) to a list
of tags. Any time a a variable matching this pattern is encountered the tags
can be used to affect the parsing/formatting. For example:

.. code::

   vartags = [
     (".*_COMMAND", ["cmdline"])
   ]

Specifies that any variable ending in ``_COMMAND`` be tagged as ``cmdline``.
This will affect the formatting by preventing the arguments from being
vertically wrapped.

Note: this particular rule is builtin so you do not need to include this in
your configuration. Use the configuration variable to add new rules.

proptags
========

Specify a mapping of property patterns (python regular expression) to a list
of tags. Any time a a property matching this pattern is encountered the tags
can be used to affect the parsing/formatting. For example:

.. code::

   proptags = [
     (".*_DIRECTORIES", ["file-list"])
   ]

Specifies that any property ending in ``_DIRECTORIES`` be tagged as
``file-list``. In the future this may affect formatting by allowing arguments
to be sorted (but currently has no effect).

Note: this particular rule is builtin so you do not need to include this in
your configuration. Use the configuration variable to add new rules.

------
format
------

disable_format
==============

``disable_format`` turns ``cmake-format`` into a no-op, emitting exactly the
same content as was input. The intention is that you can use this to disable
formatting within a subdirectory of your project tree so long as you
``cmake-format`` is using automatic config file discovery. Consider the
following project tree, for example:

.. code::

  project/
  ├ .cmake-format.py    (1)
  ├ CMakeLists.txt
  ├ 3rdparty/
  │ ├ .cmake-format.py  (2)
  │ ├ foo
  │ │ └ CMakeLists.txt
  │ └ ...
  └ src/
    └ ...

In this case, you may specify ``disable_format=True`` in the config file (2)
to prevent cmake-format from touching files in 3rdparty, such as
3rdparty/foo/CMakeLists.txt.

line_width
==========

``line_width`` specifies the number of columns that ``cmake-format`` should
fit commands into. This is the number of columns at which arguments will be
wrapped.

.. code::

  # line_width = 80 (default)
  add_library(libname STATIC sourcefile_one.cc sourcefile_two.cc
                             sourcefile_three.cc sourcefile_four.cc)

  # line_width = 100
  add_library(libname STATIC sourcefile_one.cc sourcefile_two.cc sourcefile_three.cc
                             sourcefile_four.cc)

tab_size
========

``tab_size`` indicates how many spaces should be used to indent nested
"scopes". For example:

.. code::

  # tab_size = 2 (default)
  if(this_condition_is_true)
    message("Hello World")
  endif()

  # tab_size = 4
  if(this_condition_is_true)
      message("Hello World")
  endif()


max_subgroups_hwrap
===================

A "subgroup" in this context is either a positional or keyword argument group
within the current depth of the statement parse tree. If the number of
"subgroups" at this depth is greater than ``max_subgroups_hwrap`` then
hwrap-formatting is inadmissable and a vertical layout will be selected.

The default value for this parameter is `2`.

Consider the following two examples:

.. code:: cmake

  # This statement has two argument groups, so hwrap is admissible
  add_custom_target(target1 ALL COMMAND echo "hello world")

  # This statement has three argument groups, so the statement will format
  # vertically
  add_custom_target(
     target2 ALL
     COMMAND echo "hello world"
     COMMAND echo "hello again")

In the first statement, there are two argument groups. We can see them with
``--dump parse``

.. code::

  └─ BODY: 1:0
    └─ STATEMENT: 1:0
        ├─ FUNNAME: 1:0
        ├─ LPAREN: 1:17
        ├─ ARGGROUP: 1:18
        │   ├─ PARGGROUP: 1:18  <-- group 1
        │   │   ├─ ARGUMENT: 1:18
        │   │   └─ FLAG: 1:26
        │   └─ KWARGGROUP: 1:30  <-- group 2
        │       ├─ KEYWORD: 1:30
        │       └─ ARGGROUP: 1:38
        │           └─ PARGGROUP: 1:38
        │               ├─ ARGUMENT: 1:38
        │               └─ ARGUMENT: 1:43
        └─ RPAREN: 1:56

The second statement has three argument groups:

.. code::

  └─ BODY: 1:0
      └─ STATEMENT: 1:0
          ├─ FUNNAME: 1:0
          ├─ LPAREN: 1:17
          ├─ ARGGROUP: 2:5
          │   ├─ PARGGROUP: 2:5  <-- group 1
          │   │   ├─ ARGUMENT: 2:5
          │   │   └─ FLAG: 2:13
          │   ├─ KWARGGROUP: 3:5  <-- group 2
          │   │   ├─ KEYWORD: 3:5
          │   │   └─ ARGGROUP: 3:13
          │   │       └─ PARGGROUP: 3:13
          │   │           ├─ ARGUMENT: 3:13
          │   │           ├─ ARGUMENT: 3:18
          │   └─ KWARGGROUP: 4:5  <-- group 3
          │       ├─ KEYWORD: 4:5
          │       └─ ARGGROUP: 4:13
          │           └─ PARGGROUP: 4:13
          │               ├─ ARGUMENT: 4:13
          │               └─ ARGUMENT: 4:18
          └─ RPAREN: 4:31

max_pargs_hwrap
===============

This configuration parameter is relavent only to positional argument groups.
A positional argument group is a list of "plain" arguments. If the number of
arguments in the group is greater than this number, then then hwrap-formatting
is inadmissable and a vertical layout will be selected.

The default value for this parameter is 6

Consider the following two examples:

.. code::

  # This statement has six arguments in the second group and so hwrap is
  # admissible
  set(sources filename_one.cc filename_two.cc filename_three.cc
              filename_four.cc filename_five.cc filename_six.cc)

  # This statement has seven arguments in the second group and so hwrap is
  # inadmissible
  set(sources
      filename_one.cc
      filename_two.cc
      filename_three.cc
      filename_four.cc
      filename_five.cc
      filename_six.cc
      filename_seven.cc)

max_rows_cmdline
================

``max_pargs_hwrap`` does not apply to positional argument groups for shell
commands. These are never columnized and always hwrapped. However, if the
wrapped format exceeds this many lines, then the group will also be nested.

separate_xxx_with_space
=======================

The two parameters:

* separate_ctrl_name_with_sapce
* separate_fn_name_with_space

dictate whether or not to insert a space between a statement command name and
the corresponding left parenthesis. For example:

.. code::

  # separate_ctrl_name_with_space = True
  if (condition)
    # ... do something
  endif ()

  # separate_ctrl_name_with_space = False (default)
  if(condition)
    # ... do something
  endif()

``separate_ctrl_name_with_space`` applies to control flow statements such as
``if`` and ``foreach`` whereas ``separate_fn_name_with_space`` applies to
everything else. You may want to use separate values for these two since
control flow statements are often composed of boolean logic and so the extra
space may help readability in some cases. The default value is ``False`` for
both.

dangle_parens
=============

If a statement is wrapped to more than one line, than dangle the closing
parenthesis on its own line. For example:

.. code::

  # dangle_parens = False (default)
  set(sources filename_one.cc filename_two.cc filename_three.cc
              filename_four.cc filename_five.cc filename_six.cc)

  # dangle_parens = True
  set(sources filename_one.cc filename_two.cc filename_three.cc
            filename_four.cc filename_five.cc filename_six.cc
  )  # <-- this is a dangling parenthesis

The default is ``false``.

dangle_align
============

If the trailing parenthesis must be 'dangled' on it's on line, then align it
to this reference. Options are:

* ``prefix``: the start of the statement,
* ``prefix-indent``: the start of the statement, plus one indentation  level
* ``child``: align to the column of the arguments

For example:

.. code::

  # dangle_align = "prefix"
  set(sources filename_one.cc filename_two.cc filename_three.cc
           filename_four.cc filename_five.cc filename_six.cc
  )  # <-- aligned to the statement

  # dangle_align = "prefix-indent"
  set(sources filename_one.cc filename_two.cc filename_three.cc
           filename_four.cc filename_five.cc filename_six.cc
    )  # <-- plus one indentation level

  # dangle_align = "child"
  set(sources filename_one.cc filename_two.cc filename_three.cc
           filename_four.cc filename_five.cc filename_six.cc
      )  # <-- aligned to "sources"


layout_passes
=============

See the :ref:`Formatting Algorithm <formatting-algorithm>` section for more
information on how `cmake-format` uses multiple passes to converge on the
final layout of the listfile source code. This option can be used to override
the default behavior. The format of this option is a dictionary, where the keys
are the names of the different layout node classes:

* StatementNode
* ArgGroupNode
* KWargGroupNode
* PargGroupNode
* ParenGroupNode

The dictionary values are a list of pairs (2-tuples) in the form of
:code:`(passno, wrap-decision)`. Where :code:`passno` is the pass number at
which  the wrap-decision becomes active, and :code:`wrap-decision` is a boolean
:code:`(true/false)`. For each layout pass, the decision of whether or not the
node should wrap (either nested, or vertical) is looked-up from this map.

min_prefix_chars
================

This value only comes into play when considering whether or not to nest
arguments below their parent. If the number of characters in the parent is
less than this value, we will not nest. In the example below, we'll set
``line_width=40`` for illustration:

.. code::

  # min_prefix_chars = 4 (default)
  message(
    "With the default value, this "
    "string is allowed to nest beneath "
    "the statement")

  # min_prefix_chars = 8
  message("With the default value, this "
          "string is allowed to nest beneath "
          "the statement")

max_lines_hwrap
===============

Usually the layout algorithm will prefer to do a simple "word-wrap" of
positional arguments, if it can. However if such a simple word-wrap would
exceed this many lines, then that layout is rejected, and further passes are
tried. The default value is ``max_lines_hwrap=2`` so, for example:

.. code::

  message("This message can easily be wrapped" "to two lines so there is no"
          "problem with using" "horizontal wrapping")
  message(
    "However this message cannot be wrapped to two lines because the "
    "arguments are too long. It would require at least three lines."
    "As a result, a simple word-wrap is rejected"
    "And each argument"
    "gets its own line")

line_ending
===========

This is a string indicating which style of line ending ``cmake-format`` should
use when writing out the formatted file. If ``line_ending="unix"`` (default)
then the output will contain a single newline character (``\n``) at the end of
each line. If ``line_ending="windows"`` then the output will contain a
carriage-return and newline pair (``\r\n``). If ``line_ending="auto"`` then
``cmake-format`` will observe the first line-ending of the input file and will
use style that all lines in the output.

command_case
============

``cmake`` ignores case in command names. Very old projects tend to use
uppercase for command names, while modern projects tend to use lowercase.
There are three options for this variable:

* ``upper``: format commands as uppercase
* ``lower``: format commands as lowercase
* ``canonical``: format standard commands as they are formatted in the
  ``cmake`` documentation.

``canonical`` is generally the same as ``lower`` except that some third-party
find modules that have moved into the distribution (e.g.
``ExternalProject_Add``).

keyword_case
============

``cmake`` ignores the case of sentinal words (keywords) in argument lists.
Generally projects tend to prefer uppercase (``keyword_case="upper"``) which is
the default. Alternatively, this may also be set to ``lower`` to format
keywords as lowercase.

require_valid_layout
====================

By default, if cmake-format cannot successfully fit everything into the
desired linewidth it will apply the last, most aggressive attempt that it made.
If this flag is True, however, cmake-format will print error, exit with non-
zero status code, and write-out nothing


-------
comment
-------

bullet_char
===========

When cmake-format parses and reflows comment text, this is the character that
it looks for and emits for unordered bulleted lists. The default is the
asterisk character (``*``). For example:

.. code::

   # * one
   # * two
   # * three


enum_char
=========

When cmake-format parses and reflows comment text, this is the character that
it looks for and emits after the numeral for ordered bulleted lists. The
default is the period character (``.``). For example:

.. code::

   # 1. foo
   # 2. bar
   # 3. baz

first_comment_is_literal
========================

Don't reflow the first comment block in each listfile. Use this to preserve
formatting of your copyright/license statements. shebang lines are always
preserved and are not considered the first comment for the purpose of
implementing this feature.

literal_comment_pattern
=======================

Don't reflow any comment block which matches this (regex) pattern. Default is
`None` (disabled). This can be used to match e.g. standard copyright text that
shouldn't be reflowed. The format is a python regular expression.

fence_pattern
=============

``cmake-format`` supports fenced literals in comments. Any comment text
between a pair of fences is preserved verbatim without reformatting. The
pattern of characters that defines a fence is defined by this variable. The
format is a python regular expression. The default is
``^\s*([`~]{3}[`~]*)(.*)$`` which will match three or more backticks
(:literal:`\`\`\``) or tilde (``~~~``) characters. e.g.

.. code::

  # This is paragraph text but:
  # ```
  #    This
  # is
  #      some literal text
  # ```

ruler_pattern
=============

``cmake-format`` will attempt to recognize and canonicalize "rulers" within
comment text. A ruler is a sequence of characters used to intentionally break
up text, such as the following:

.. code::

  # Section Title
  # =============
  # Paragraph text

In this example, the sequence of equals (``=``) characters is used as a
"ruler". The definition of what constitutes a ruler is stored in this variable.
The format is a python regular expression pattern. The default value is
``^\s*[^\w\s]{3}.*[^\w\s]{3}$`` which will match any sequence of three or more
special characters on either side of anything (in the case of nothing
in-between, this means at least six special characters). This pattern will
match, e.g. the following:

.. code::

  # ======
  # === ===
  # === Some Text ===
  # ___ Some Text ___

hashruler_min_length
====================

Because the hash character (``#``) has syntax in cmake, rulers (see above)
that are composed of hash characters are dealt with a little differently.
In general ``cmake-format`` will chomp multiple hash characters as un-intended
redundancy, unless the sequence contains at least this many characters.
The default is ``10``.

canonicalize_hashrulers
=======================

If true, then insert a space between the first hash char and remaining hash
chars in a hash ruler, and normalize its length to fill the column

enable_markup
=============

This is the big on/off switch for comment reflow and formatting. If this is
``true`` (the default) then ``cmake-format`` comment processing and formatting
features are enabled. If ``false``, then comments are generally preserved,
but trailing whitespace will still be removed.

explicit_trailing_pattern
=========================

If ``cmake-format`` encountes a comment within or at the very end of a
statement it will try to determine whether or not that comment refers to
a particular argument, and will format it accordingly. For example:

.. code::

  cmake_parse_arguments(
    ARG
    "FOO BAR" # optional keywords
    "BAZ" # one value keywords
    "BOZ" # multi value keywords
    ${ARGN})

The rules for associating a comment with the preceding argument depend on
how much (and what kinds) of whitespace separate them. Alternatively, if
the comments match the ``explicit_trailing_pattern``, then they are associated
with the preceding argument regardless of the whitespace separating them.
The format for this variable is a python regular expression matching prefix
characters for such explicit trailing comments. The default value is ``#<``,
such that the above example using explicit trailing comments would  be:

.. code::

  cmake_parse_arguments(
    ARG
    "FOO BAR" #< optional keywords
    "BAZ" #< one value keywords
    "BOZ" #< multi value keywords
    ${ARGN})

------
encode
------

emit_byteorder_mark
===================

If ``true`` (the default is ``false``) then output the unicode byte-order at
the start of the document.

input_encoding
==============

Specify the input encoding of the file. The format of this string is `anything
understood`__ by the ``encoding=`` keyword of the python ``open()`` function.
The default is ``utf-8``.

.. __: https://docs.python.org/3/library/codecs.html#standard-encodings

output_encoding
===============

Specify the output encoding of the file. The format of this string is `anything
understood`__ by the ``encoding=`` keyword of the python ``open()`` function.
The default is ``utf-8``.

.. __: https://docs.python.org/3/library/codecs.html#standard-encodings