Skip to content

Commit a6927cb

Browse files
Add support for CMake Presets (#348)
* dev container + vscode extensions * exploring cmake presets for CI * ignore user presets * add configure to build preset windows ran in debug, which means the multi config needs more help * coverage preset * creating a fuzzing preset * fuzzing fix cwd + more configs to preset * move cmake set vars to right section https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170 "You can set C and C++ compilers by using cacheVariables.CMAKE_C_COMPILER and cacheVariables.CMAKE_CXX_COMPILER in a Configure Preset. It's equivalent to passing -D CMAKE_C_COMPILER=<value> and -D CMAKE_CXX_COMPILER=<value> to CMake from the command line." * fix workdir for new fuzz run targets * split up presets into more files * fix include order (liking this less) * add asan to presets * fix copy paste * add asan build preset * move ubsan to presets * replace mustache with a cmake script * touch ups * restore file to void merge conflicts * fix order for args * remove action wrapper more quotes for inputs * revert bad render of boost_json * fix casing * format changes * test to see if output is working * last try * git revert moving mustache to cmake * cmake not enough for presets * drop ci prefix * new test for `library_ROOT` search path * install with presets * cmake --install does not take a preset * install with preset is not yet supported https://gitlab.kitware.com/cmake/cmake/-/issues/23208 * add missing build step * more global fuzzing flags to toolchain file * fixup toolchain in presets * fix pathing and limit configs to tested platforms * clean up + use presets for clang-tidy * dry up sanitizer flags * try install with a preset * remove duplicated test * notes about hunter test * skip checking the compiler since this causes errors with the same CMake uses in combinations with the fuzz sanitizer flag https://github.com/prince-chrismc/jwt-cpp/actions/runs/7481024827/job/20361722539?pr=33 ``` /usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x22 CMakeFiles/cmTC_ff7c6.dir/testCCompiler.c.o: in function `main': testCCompiler.c:(.text.main[main]+0x0): multiple definition of `main'; /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o):(.text.main+0x0): first defined here /usr/bin/ld: /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerMain.cpp.o): in function `main': (.text.main+0x12): undefined reference to `LLVMFuzzerTestOneInput' ``` * remove system name to disable cross compiling * tests do not pass clang-tidy * drop toolchain, use target specific flags * leave flags in cmake * missing deps + clean apt files * remove some code duplication * fix typo * devcontainers fix, test and add wolfssl refactored installer to have a script that could be reused * add missing build context * pass version to script * dont use bash syntax * fix typo * upload tar.gz for new releases * revert name to manually trigger it * Update and rename nuget.yml to release.yml * disable nuget for testing * add a zip as well * back to basics * remove remove testing code * update workflow name * enable testing needs to be in the root * add a test preset and use it in some workflows * fix linting tests * bump github actions * bump python setup * drop dev containers * dont install openssl on windows * revert merge conflicts * fix whitespace * fix private claims example to have a valid token #351 * put back versioned format I dont remember why, it looks like it was debugging
1 parent 0d03bc5 commit a6927cb

15 files changed

+351
-80
lines changed

.github/workflows/cmake.yml

+26-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ jobs:
2222

2323
- name: setup
2424
run: |
25-
mkdir build
26-
cd build
27-
cmake .. -DJWT_BUILD_EXAMPLES=OFF
28-
sudo make install
25+
cmake --preset release
26+
sudo cmake --build --preset release --target install
2927
3028
- name: test
3129
working-directory: tests/cmake
@@ -95,6 +93,29 @@ jobs:
9593
cmake . -DTEST:STRING="defaults-enabled"
9694
cmake --build .
9795
96+
preset-support-but-not-enough:
97+
runs-on: ubuntu-22.04
98+
steps:
99+
- uses: actions/checkout@v4
100+
- uses: ./.github/actions/install/cmake
101+
with:
102+
version: "3.24.4"
103+
url: "https://cmake.org/files/v3.24/cmake-3.24.4.tar.gz"
104+
- uses: ./.github/actions/install/gtest
105+
106+
- name: setup
107+
run: |
108+
mkdir build
109+
cd build
110+
cmake .. -DJWT_BUILD_EXAMPLES=ON -DJWT_BUILD_TESTS=ON
111+
sudo make install
112+
113+
- name: test
114+
run: |
115+
cd tests/cmake
116+
cmake . -DTEST:STRING="defaults-enabled"
117+
cmake --build .
118+
98119
custom-install-linux:
99120
runs-on: ubuntu-latest
100121
steps:
@@ -117,7 +138,7 @@ jobs:
117138
root-hint-install-linux:
118139
runs-on: ubuntu-latest
119140
steps:
120-
- uses: actions/checkout@v3
141+
- uses: actions/checkout@v4
121142
- uses: lukka/get-cmake@latest
122143

123144
- name: setup

.github/workflows/cross-platform.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v4
17-
- run: cmake -E make_directory ${{ github.workspace }}/build
1817

1918
- name: configure
20-
shell: bash # access regardless of the host operating system
21-
working-directory: ${{ github.workspace }}/build
22-
run: cmake $GITHUB_WORKSPACE -DJWT_BUILD_EXAMPLES=ON
19+
run: cmake --preset examples
2320

2421
- name: build
25-
working-directory: ${{ github.workspace }}/build
26-
shell: bash
27-
run: cmake --build .
22+
run: cmake --build --preset examples
2823

2924
- name: test
3025
run: |
31-
cmake --build build/ --target rsa-create-run
32-
cmake --build build/ --target rsa-verify-run
26+
cmake --build --preset examples --target rsa-create-run
27+
cmake --build --preset examples --target rsa-verify-run
3328
3429
- if: github.event_name == 'push' && always()
3530
uses: ./.github/actions/badge

.github/workflows/jwt.yml

+26-45
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ jobs:
1818
- uses: ./.github/actions/install/open-source-parsers-jsoncpp
1919

2020
- name: configure
21-
run: |
22-
mkdir build
23-
cd build
24-
cmake .. -DJWT_BUILD_EXAMPLES=OFF -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
25-
21+
run: cmake --preset coverage
2622
- name: run
27-
working-directory: build
28-
run: make jwt-cpp-test coverage
23+
run: cmake --build --preset coverage
2924

3025
- uses: coverallsapp/github-action@v2
3126
with:
@@ -38,21 +33,19 @@ jobs:
3833
steps:
3934
- uses: actions/checkout@v4
4035
- uses: lukka/get-cmake@latest
41-
- uses: ./.github/actions/install/gtest
4236

4337
- name: configure
44-
run: |
45-
mkdir build
46-
cd build
47-
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DJWT_ENABLE_FUZZING=ON
38+
run: cmake --preset ci-fuzzing
39+
- name: build
40+
run: cmake --build --preset ci-fuzzing
4841

4942
- name: run
5043
run: |
51-
cmake --build build/ --target jwt-cpp-fuzz-BaseEncodeFuzz-run
52-
cmake --build build/ --target jwt-cpp-fuzz-BaseDecodeFuzz-run
53-
cmake --build build/ --target jwt-cpp-fuzz-TokenDecodeFuzz-run
44+
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseEncodeFuzz-run
45+
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-BaseDecodeFuzz-run
46+
cmake --build --preset ci-fuzzing --target jwt-cpp-fuzz-TokenDecodeFuzz-run
5447
55-
asan: # Based on https://gist.github.com/jlblancoc/44be9d4d466f0a973b1f3808a8e56782
48+
asan:
5649
runs-on: ubuntu-latest
5750
strategy:
5851
fail-fast: false
@@ -69,46 +62,34 @@ jobs:
6962
version: ${{ matrix.openssl.tag }}
7063

7164
- name: configure
72-
run: |
73-
mkdir build
74-
cd build
75-
cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" \
76-
-DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -g" \
77-
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \
78-
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak"
65+
run: cmake --preset ci-asan
66+
- name: build
67+
run: cmake --build --preset ci-asan
7968

8069
- name: run
81-
working-directory: build
8270
run: |
83-
make
84-
export ASAN_OPTIONS=check_initialization_order=true:detect_stack_use_after_return=true:fast_unwind_on_malloc=0
85-
./example/rsa-create
86-
./example/rsa-verify
87-
./example/jwks-verify
88-
./tests/jwt-cpp-test
71+
cmake --build --preset ci-asan --target private-claims-run
72+
cmake --build --preset ci-asan --target rsa-create-run
73+
cmake --build --preset ci-asan --target rsa-verify-run
74+
cmake --build --preset ci-asan --target jwks-verify-run
75+
cmake --build --preset ci-asan --target jwt-cpp-test-run
8976
9077
ubsan:
91-
runs-on: ubuntu-20.04
78+
runs-on: ubuntu-latest
9279
steps:
9380
- uses: actions/checkout@v4
9481
- uses: lukka/get-cmake@latest
9582
- uses: ./.github/actions/install/gtest
9683

9784
- name: configure
98-
run: |
99-
mkdir build
100-
cd build
101-
cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 \
102-
-DCMAKE_CXX_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \
103-
-DCMAKE_C_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \
104-
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all" \
105-
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all"
85+
run: cmake --preset ci-ubsan
86+
- name: build
87+
run: cmake --build --preset ci-ubsan -DCMAKE_CXX_STANDARD=20
10688

10789
- name: run
108-
working-directory: build
10990
run: |
110-
make
111-
export UBSAN_OPTIONS=print_stacktrace=1
112-
./example/rsa-create
113-
./example/rsa-verify
114-
./tests/jwt-cpp-test
91+
cmake --build --preset ci-ubsan --target private-claims-run
92+
cmake --build --preset ci-ubsan --target rsa-create-run
93+
cmake --build --preset ci-ubsan --target rsa-verify-run
94+
cmake --build --preset ci-ubsan --target jwks-verify-run
95+
cmake --build --preset ci-ubsan --target jwt-cpp-test-run

.github/workflows/lint.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
matrix:
3737
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake"]
3838
steps:
39-
- uses: actions/setup-python@v2
39+
- uses: actions/setup-python@v5
4040
with:
4141
python-version: "3.x"
4242
- run: pip install cmakelang
@@ -54,13 +54,9 @@ jobs:
5454
- uses: lukka/get-cmake@latest
5555
- uses: actions/checkout@v4
5656
- name: configure
57-
run: |
58-
mkdir build
59-
cd build
60-
cmake .. -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
57+
run: cmake --preset examples -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
6158
- name: run
62-
working-directory: build
63-
run: make
59+
run: cmake --build --preset examples
6460
- uses: ./.github/actions/process-linting-results
6561
with:
6662
linter_name: clang-tidy

.github/workflows/ssl.yml

+13-11
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
version: ${{ matrix.openssl.tag }}
2828

2929
- name: configure
30-
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp
31-
- run: make
30+
run: cmake --preset unit-tests -DOPENSSL_ROOT_DIR=/tmp
31+
- run: cmake --build --preset unit-tests
3232
- name: test
33-
run: ./tests/jwt-cpp-test
33+
run: ctest --preset unit-tests
3434

3535
- if: github.event_name == 'push' && always()
3636
uses: ./.github/actions/badge
@@ -50,8 +50,10 @@ jobs:
5050
version: "openssl-3.0.5"
5151

5252
- name: configure
53-
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED=1"
54-
- run: make
53+
run: cmake --preset unit-tests -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED=1"
54+
- run: cmake --build --preset unit-tests
55+
- name: test
56+
run: ctest --preset unit-tests
5557

5658
libressl:
5759
runs-on: ubuntu-latest
@@ -69,10 +71,10 @@ jobs:
6971
version: ${{ matrix.libressl }}
7072

7173
- name: configure
72-
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
73-
- run: make
74+
run: cmake --preset unit-tests -DJWT_SSL_LIBRARY:STRING=LibreSSL
75+
- run: cmake --build --preset unit-tests
7476
- name: test
75-
run: ./tests/jwt-cpp-test
77+
run: ctest --preset unit-tests
7678

7779
- if: github.event_name == 'push' && always()
7880
uses: ./.github/actions/badge
@@ -98,10 +100,10 @@ jobs:
98100
version: ${{ matrix.wolfssl.ref }}
99101

100102
- name: configure
101-
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=wolfSSL
102-
- run: make
103+
run: cmake --preset unit-tests -DJWT_SSL_LIBRARY:STRING=wolfSSL
104+
- run: cmake --build --preset unit-tests
103105
- name: test
104-
run: ./tests/jwt-cpp-test
106+
run: ctest --preset unit-tests
105107

106108
- if: github.event_name == 'push' && always()
107109
uses: ./.github/actions/badge

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,15 @@ $RECYCLE.BIN/
306306
test
307307
*.o
308308
*.o.d
309-
.vscode
309+
310+
# IDE-specific files
311+
.vscode/
312+
.vscode/!extensions.json # Allow to provide recommended extensions
313+
310314
# ClangD cache files
311315
.cache
312316

313317
build/*
314318
package-lock.json
319+
320+
CMakeUserPresets.json

.vscode/extensions.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"recommendations": [
3+
"ms-vscode.cpptools",
4+
"ms-vscode.cpptools-extension-pack",
5+
"ms-vscode.cmake-tools",
6+
"twxs.cmake",
7+
"matepek.vscode-catch2-test-adapter",
8+
"GitHub.vscode-github-actions"
9+
]
10+
}

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ if(JWT_BUILD_EXAMPLES)
158158
endif()
159159

160160
if(JWT_BUILD_TESTS)
161+
enable_testing()
161162
add_subdirectory(tests)
162163
endif()
163164

CMakePresets.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 25,
6+
"patch": 0
7+
},
8+
"include": [
9+
"example/CMakePresets.json",
10+
"tests/CMakePresets.json"
11+
],
12+
"configurePresets": [
13+
{
14+
"name": "dev",
15+
"displayName": "Development",
16+
"inherits": "debug",
17+
"environment": {
18+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
19+
},
20+
"cacheVariables": {
21+
"JWT_BUILD_EXAMPLES": "ON",
22+
"JWT_BUILD_TESTS": "ON"
23+
}
24+
}
25+
],
26+
"buildPresets": [
27+
{
28+
"name": "dev",
29+
"configurePreset": "dev",
30+
"configuration": "Debug"
31+
}
32+
]
33+
}

cmake/CMakePresets.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 25,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "default",
11+
"displayName": "Default Config",
12+
"hidden": true,
13+
"binaryDir": "${sourceDir}/build",
14+
"cacheVariables": {
15+
"JWT_BUILD_EXAMPLES": "OFF",
16+
"JWT_BUILD_TESTS": "OFF"
17+
}
18+
},
19+
{
20+
"name": "debug",
21+
"displayName": "Debug",
22+
"inherits": "default",
23+
"cacheVariables": {
24+
"CMAKE_BUILD_TYPE": "Debug"
25+
}
26+
},
27+
{
28+
"name": "release",
29+
"displayName": "Release",
30+
"inherits": "default",
31+
"cacheVariables": {
32+
"CMAKE_BUILD_TYPE": "Release"
33+
}
34+
}
35+
],
36+
"buildPresets": [
37+
{
38+
"name": "debug",
39+
"configurePreset": "debug",
40+
"configuration": "Debug"
41+
},
42+
{
43+
"name": "release",
44+
"configurePreset": "release",
45+
"configuration": "Release"
46+
}
47+
]
48+
}

example/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_custom_target(print-claims-run COMMAND print-claims)
1717

1818
add_executable(private-claims private-claims.cpp)
1919
target_link_libraries(private-claims jwt-cpp::jwt-cpp)
20+
add_custom_target(private-claims-run COMMAND private-claims)
2021

2122
add_executable(rsa-create rsa-create.cpp)
2223
target_link_libraries(rsa-create jwt-cpp::jwt-cpp)

0 commit comments

Comments
 (0)