Skip to content

Commit a84f4af

Browse files
authored
Setup CMake and CI (#1)
* Setup CMake * Add CI * clang-format changes
1 parent a25647b commit a84f4af

File tree

17 files changed

+493
-114
lines changed

17 files changed

+493
-114
lines changed

.clang-format

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
AlwaysBreakTemplateDeclarations: Yes
5+
BreakBeforeBraces: Attach
6+
ColumnLimit: 160
7+
SpaceAfterTemplateKeyword: true
8+
Standard: c++23
9+
TabWidth: 4
10+
IndentWidth: 4
11+
UseTab: Always
12+
AllowShortEnumsOnASingleLine: true
13+
AllowShortCaseLabelsOnASingleLine: true
14+
AllowShortFunctionsOnASingleLine: All
15+
AllowShortLambdasOnASingleLine: All
16+
AllowShortBlocksOnASingleLine: Always
17+
AllowShortIfStatementsOnASingleLine: Always
18+
AllowShortLoopsOnASingleLine: true
19+
IndentRequires: true
20+
IncludeCategories:
21+
# Headers in <> with .h extension.
22+
- Regex: '<([A-Za-z0-9\/-_])+\.h>'
23+
Priority: 10
24+
# Headers in <> with .hpp extension.
25+
- Regex: '<([A-Za-z0-9\/-_])+\.hpp>'
26+
Priority: 20
27+
# Headers in <> without extension.
28+
- Regex: '<([A-Za-z0-9\/-_])+>'
29+
Priority: 30
30+
PointerAlignment: Left
31+
QualifierAlignment: Left

.clang-tidy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
Checks: 'clang-analyzer-*,
3+
concurrency-*,
4+
cppcoreguidelines-*,
5+
-cppcoreguidelines-non-private-member-variables-in-classes,
6+
-cppcoreguidelines-avoid-magic-numbers,
7+
-cppcoreguidelines-avoid-const-or-ref-data-members,
8+
-cppcoreguidelines-avoid-do-while,
9+
misc-*,
10+
-misc-non-private-member-variables-in-classes,
11+
-misc-no-recursion,
12+
modernize-*,
13+
-modernize-use-trailing-return-type,
14+
performance-*,
15+
portability-*,
16+
readability-*,
17+
-readability-identifier-length,
18+
-readability-implicit-bool-conversion,
19+
-readability-magic-numbers,
20+
-readability-redundant-member-init,
21+
-readability-uppercase-literal-suffix'
22+
...

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[*]
2+
insert_final_newline = true
3+
charset = utf-8
4+
indent_size = 4
5+
indent_style = tab
6+
# Optional: git will commit as lf, this will only affect local files
7+
end_of_line = lf
8+
9+
[*.{py,md,yml,sh,cmake,json}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.{py,md,yml,sh,cmake,json}.in]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[CMakeLists.txt]
18+
indent_style = space
19+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: ci-pr
2+
on: [pull_request, workflow_dispatch]
3+
jobs:
4+
x64-linux-gcc:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: init
9+
run: uname -m; sudo apt install -yqq ninja-build
10+
- name: configure
11+
run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14
12+
- name: build debug
13+
run: cmake --build build --config=Debug -- -v
14+
- name: build release
15+
run: cmake --build build --config=Release -- -v
16+
- name: test debug
17+
run: cd build && ctest -V -C Debug
18+
- name: test release
19+
run: cd build && ctest -V -C Release
20+
x64-linux-clang:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: init
25+
run: |
26+
uname -m
27+
sudo apt update -yqq && sudo apt install -yqq clang-19 ninja-build
28+
sudo update-alternatives --remove-all clang++
29+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10
30+
- name: configure
31+
run: cmake -S . --preset=ninja-clang -B build
32+
- name: build debug
33+
run: cmake --build build --config=Debug -- -v
34+
- name: build release
35+
run: cmake --build build --config=Release -- -v
36+
- name: test debug
37+
run: cd build && ctest -V -C Debug
38+
- name: test release
39+
run: cd build && ctest -V -C Release
40+
arm64-linux-gcc:
41+
runs-on: ubuntu-24.04-arm
42+
steps:
43+
- uses: actions/checkout@v4
44+
- name: init
45+
run: uname -m
46+
- name: configure
47+
run: cmake -S . --preset=ninja-gcc -B build -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14
48+
- name: build debug
49+
run: cmake --build build --config=Debug -- -v
50+
- name: build release
51+
run: cmake --build build --config=Release -- -v
52+
- name: test debug
53+
run: cd build && ctest -V -C Debug
54+
- name: test release
55+
run: cd build && ctest -V -C Release
56+
arm64-linux-clang:
57+
runs-on: ubuntu-24.04-arm
58+
steps:
59+
- uses: actions/checkout@v4
60+
- name: init
61+
run: |
62+
uname -m
63+
sudo apt update -yqq && sudo apt install -yqq clang-19 ninja-build
64+
sudo update-alternatives --remove-all clang++
65+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 10
66+
- name: configure
67+
run: cmake -S . --preset=ninja-clang -B build
68+
- name: build debug
69+
run: cmake --build build --config=Debug -- -v
70+
- name: build release
71+
run: cmake --build build --config=Release -- -v
72+
- name: test debug
73+
run: cd build && ctest -V -C Debug
74+
- name: test release
75+
run: cd build && ctest -V -C Release
76+
x64-windows-vs22:
77+
runs-on: windows-latest
78+
steps:
79+
- uses: actions/checkout@v4
80+
- name: configure
81+
run: cmake -S . --preset=vs22 -B build
82+
- name: build debug
83+
run: cmake --build build --config=Debug --parallel
84+
- name: build release
85+
run: cmake --build build --config=Release --parallel
86+
- name: test debug
87+
run: cd build && ctest -V -C Debug
88+
- name: test release
89+
run: cd build && ctest -V -C Release
90+
x64-windows-clang:
91+
runs-on: windows-latest
92+
steps:
93+
- uses: actions/checkout@v4
94+
- name: init
95+
run: choco install ninja
96+
- name: configure
97+
run: cmake -S . --preset=ninja-clang -B clang
98+
- name: build debug
99+
run: cmake --build clang --config=Debug -- -v
100+
- name: build release
101+
run: cmake --build clang --config=Release -- -v
102+
- name: test debug
103+
run: cd clang && ctest -V -C Debug
104+
- name: test release
105+
run: cd clang && ctest -V -C Release

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@
3636
/Test/out/build/x64-debug
3737
/cppjson/out/build/x64-debug
3838
/out/build/x64-Debug
39+
40+
# clangd
41+
/.cache
42+
compile_commands.json
43+
44+
# CMake presets
45+
CMakeUserPresets.json
46+
47+
# CMake build output
48+
/out

CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
cmake_minimum_required (VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.24)
22

3-
add_subdirectory("cppjson")
4-
add_subdirectory("Test")
3+
set(CMAKE_CXX_STANDARD 23)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
set(CMAKE_CXX_EXTENSIONS OFF)
6+
set(CMAKE_DEBUG_POSTFIX "-d")
7+
8+
include(version.cmake)
9+
10+
project(cppjson VERSION ${cppjson_version})
11+
12+
option(CPPJSON_BUILD_TESTS "Build cppjson tests" ${PROJECT_IS_TOP_LEVEL})
13+
14+
add_subdirectory(cppjson)
15+
16+
if(CPPJSON_BUILD_TESTS)
17+
enable_testing()
18+
add_subdirectory(Test)
19+
endif()

0 commit comments

Comments
 (0)