Skip to content

Commit ca110ad

Browse files
🔧 Improved CMake options and macros to prevent collisions (#109)
* exclude any folder prefixed with build * seeing how far generator expresstion will go * refactor cmake + outline some tests * adding missing install destiniation * rolling back some changes since the workflow was no support by CMake * adding missing include * fixing old variable names being used * using target_compile_definitions instead of options * correct options for CI + reporting errors for consumer * using sudo to install * fix bad variable * trying CMAKE_PREFIX_PATH * removing recursive call * remove options from generators + dedicated exports target * remove pthread link lib (unused) * install targets files + include * add missing main * remove install prefix * revive CMAKE_PREFIX_PATH it's really needed * fix collision on DISABLE_BASE64 + more cmake tests * bump cmake version + test minimum * fix job names * fix bad replace * fix bad permissions * fix install of picojson * adding missing ifndef and overload for pico and no base64 * linting * test for version * trying to find version * [test] remove semver prerelase from CMake * fixing some documentation issues * limit cmake test to only related files * touch up docs * making sure new helper supports no base64 mode * some doc fixes * Update cmake.yml * Update .github/workflows/cmake.yml * Update .gitignore
1 parent f85e6df commit ca110ad

File tree

17 files changed

+499
-151
lines changed

17 files changed

+499
-151
lines changed

.cmake-format

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# ----------------------------------
2+
# Options affecting listfile parsing
3+
# ----------------------------------
4+
with section("parse"):
5+
6+
# Specify structure for custom cmake functions
7+
additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'],
8+
'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}
9+
10+
# -----------------------------
11+
# Options effecting formatting.
12+
# -----------------------------
13+
with section("format"):
14+
15+
# How wide to allow formatted cmake files
16+
line_width = 120
17+
18+
# How many spaces to tab for indent
19+
tab_size = 2
20+
21+
# If an argument group contains more than this many sub-groups (parg or kwarg
22+
# groups) then force it to a vertical layout.
23+
max_subgroups_hwrap = 12
24+
25+
# If a positional argument group contains more than this many arguments, then
26+
# force it to a vertical layout.
27+
max_pargs_hwrap = 24
28+
29+
# If true, separate flow control names from their parentheses with a space
30+
separate_ctrl_name_with_space = False
31+
32+
# If true, separate function names from parentheses with a space
33+
separate_fn_name_with_space = False
34+
35+
# If a statement is wrapped to more than one line, than dangle the closing
36+
# parenthesis on its own line.
37+
dangle_parens = False
38+
39+
# If the trailing parenthesis must be 'dangled' on its on line, then align it
40+
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
41+
# the start of the statement, plus one indentation level, `child`: align to
42+
# the column of the arguments
43+
dangle_align = 'prefix'
44+
45+
# If the statement spelling length (including space and parenthesis) is
46+
# smaller than this amount, then force reject nested layouts.
47+
min_prefix_chars = 4
48+
49+
# If the statement spelling length (including space and parenthesis) is larger
50+
# than the tab width by more than this amount, then force reject un-nested
51+
# layouts.
52+
max_prefix_chars = 10
53+
54+
# If a candidate layout is wrapped horizontally but it exceeds this many
55+
# lines, then reject the layout.
56+
max_lines_hwrap = 12
57+
58+
# What style line endings to use in the output.
59+
line_ending = 'unix'
60+
61+
# Format command names consistently as 'lower' or 'upper' case
62+
command_case = 'lower'
63+
64+
# Format keywords consistently as 'lower' or 'upper' case
65+
keyword_case = 'upper'
66+
67+
# A list of command names which should always be wrapped
68+
always_wrap = []
69+
70+
# If true, the argument lists which are known to be sortable will be sorted
71+
# lexicographicall
72+
enable_sort = True
73+
74+
# If true, the parsers may infer whether or not an argument list is sortable
75+
# (without annotation).
76+
autosort = False
77+
78+
# By default, if cmake-format cannot successfully fit everything into the
79+
# desired linewidth it will apply the last, most agressive attempt that it
80+
# made. If this flag is True, however, cmake-format will print error, exit
81+
# with non-zero status code, and write-out nothing
82+
require_valid_layout = False
83+
84+
# A dictionary mapping layout nodes to a list of wrap decisions. See the
85+
# documentation for more information.
86+
layout_passes = {}
87+
88+
# ------------------------------------------------
89+
# Options affecting comment reflow and formatting.
90+
# ------------------------------------------------
91+
with section("markup"):
92+
93+
# What character to use for bulleted lists
94+
bullet_char = '*'
95+
96+
# What character to use as punctuation after numerals in an enumerated list
97+
enum_char = '.'
98+
99+
# If comment markup is enabled, don't reflow the first comment block in each
100+
# listfile. Use this to preserve formatting of your copyright/license
101+
# statements.
102+
first_comment_is_literal = False
103+
104+
# If comment markup is enabled, don't reflow any comment block which matches
105+
# this (regex) pattern. Default is `None` (disabled).
106+
literal_comment_pattern = None
107+
108+
# Regular expression to match preformat fences in comments
109+
# default=r'^\s*([`~]{3}[`~]*)(.*)$'
110+
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
111+
112+
# Regular expression to match rulers in comments
113+
# default=r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'
114+
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
115+
116+
# If a comment line matches starts with this pattern then it is explicitly a
117+
# trailing comment for the preceeding argument. Default is '#<'
118+
explicit_trailing_pattern = '#<'
119+
120+
# If a comment line starts with at least this many consecutive hash
121+
# characters, then don't lstrip() them off. This allows for lazy hash rulers
122+
# where the first hash char is not separated by space
123+
hashruler_min_length = 10
124+
125+
# If true, then insert a space between the first hash char and remaining hash
126+
# chars in a hash ruler, and normalize its length to fill the column
127+
canonicalize_hashrulers = True
128+
129+
# enable comment markup parsing and reflow
130+
enable_markup = True
131+
132+
# ----------------------------
133+
# Options affecting the linter
134+
# ----------------------------
135+
with section("lint"):
136+
137+
# a list of lint codes to disable
138+
disabled_codes = []
139+
140+
# regular expression pattern describing valid function names
141+
function_pattern = '[0-9a-z_]+'
142+
143+
# regular expression pattern describing valid macro names
144+
macro_pattern = '[0-9A-Z_]+'
145+
146+
# regular expression pattern describing valid names for variables with global
147+
# scope
148+
global_var_pattern = '[0-9A-Z][0-9A-Z_]+'
149+
150+
# regular expression pattern describing valid names for variables with global
151+
# scope (but internal semantic)
152+
internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+'
153+
154+
# regular expression pattern describing valid names for variables with local
155+
# scope
156+
local_var_pattern = '[0-9a-z_]+'
157+
158+
# regular expression pattern describing valid names for privatedirectory
159+
# variables
160+
private_var_pattern = '_[0-9a-z_]+'
161+
162+
# regular expression pattern describing valid names for publicdirectory
163+
# variables
164+
public_var_pattern = '[0-9A-Z][0-9A-Z_]+'
165+
166+
# regular expression pattern describing valid names for keywords used in
167+
# functions or macros
168+
keyword_pattern = '[0-9A-Z_]+'
169+
170+
# In the heuristic for C0201, how many conditionals to match within a loop in
171+
# before considering the loop a parser.
172+
max_conditionals_custom_parser = 2
173+
174+
# Require at least this many newlines between statements
175+
min_statement_spacing = 1
176+
177+
# Require no more than this many newlines between statements
178+
max_statement_spacing = 1
179+
max_returns = 6
180+
max_branches = 12
181+
max_arguments = 5
182+
max_localvars = 15
183+
max_statements = 50
184+
185+
# -------------------------------
186+
# Options effecting file encoding
187+
# -------------------------------
188+
with section("encode"):
189+
190+
# If true, emit the unicode byte-order mark (BOM) at the start of the file
191+
emit_byteorder_mark = False
192+
193+
# Specify the encoding of the input file. Defaults to utf-8
194+
input_encoding = 'utf-8'
195+
196+
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
197+
# only claims to support utf-8 so be careful when using anything else
198+
output_encoding = 'utf-8'
199+
200+
# -------------------------------------
201+
# Miscellaneous configurations options.
202+
# -------------------------------------
203+
with section("misc"):
204+
205+
# A dictionary containing any per-command configuration overrides. Currently
206+
# only `command_case` is supported.
207+
per_command = {}
208+

.github/workflows/cmake.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CMake Integration CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
paths:
9+
- 'CMakeLists.txt'
10+
- 'include/jwt-cpp/**'
11+
- 'tests/cmake/**'
12+
- '.github/workflows/cmake.yml'
13+
14+
jobs:
15+
min-req:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: install cmake
20+
run: |
21+
wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
22+
tar -zxf cmake-3.8.2.tar.gz
23+
cd cmake-3.8.2
24+
./bootstrap && make -j $(nproc) && sudo make install
25+
26+
- name: setup
27+
run: |
28+
mkdir build
29+
cd build
30+
cmake .. -DJWT_BUILD_EXAMPLES=OFF
31+
sudo make install
32+
33+
- name: test
34+
run: |
35+
cd tests/cmake
36+
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="defaults-enabled"
37+
cmake --build .
38+
39+
no-pico:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v2
43+
- name: install cmake
44+
uses: lukka/get-cmake@latest
45+
46+
- name: setup
47+
run: |
48+
mkdir build
49+
cd build
50+
cmake .. -DJWT_DISABLE_PICOJSON=ON -DJWT_BUILD_EXAMPLES=OFF
51+
sudo make install
52+
53+
- name: test
54+
run: |
55+
cd tests/cmake
56+
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="picojson-is-disabled"
57+
cmake --build .
58+
59+
no-base64:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- name: install cmake
64+
uses: lukka/get-cmake@latest
65+
66+
- name: setup
67+
run: |
68+
mkdir build
69+
cd build
70+
cmake .. -DJWT_DISABLE_BASE64=ON -DJWT_BUILD_EXAMPLES=OFF
71+
sudo make install
72+
73+
- name: test
74+
run: |
75+
cd tests/cmake
76+
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="base64-is-disabled"
77+
cmake --build .

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: C/C++ CI
1+
name: Coverage CI
22

33
on:
44
push:
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v2
1616

1717
- name: install cmake
18-
uses: lukka/get-cmake@v3.17.2
18+
uses: lukka/get-cmake@latest
1919

2020
- name: configure
2121
run: |
@@ -27,7 +27,7 @@ jobs:
2727
sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a
2828
mkdir build
2929
cd build
30-
cmake .. -DBUILD_TESTS=ON -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
30+
cmake .. -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
3131
3232
- name: make
3333
run: cd build && make jwt-cpp-test coverage

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,4 @@ test
310310

311311
docs
312312

313-
build/*
313+
build/*

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ install:
1313
- sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a
1414

1515
script:
16-
- cmake .
16+
- cmake . -DJWT_BUILD_TESTS=ON
1717
- make
1818
- ./tests/jwt-cpp-test

0 commit comments

Comments
 (0)