Skip to content

Commit 5cca6a9

Browse files
committed
Refactor
1 parent 747be4f commit 5cca6a9

20 files changed

+192
-124
lines changed

.clang-tidy

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
---
12
Checks: >
2-
google-*,
33
modernize-*,
4-
readability-*,
54
performance-*,
6-
-google-build-using-namespace,
7-
-google-readability-function-size,
5+
cppcoreguidelines-*,
6+
readability-*,
7+
misc-*,
8+
bugprone-*,
89
-modernize-use-trailing-return-type,
9-
-readability-implicit-bool-conversion
10+
-cppcoreguidelines-pro-type-const-cast
1011
11-
WarningsAsErrors: ''
12+
# Treat warnings-as-errors for selected groups
13+
WarningsAsErrors: >
14+
modernize-*,
15+
performance-*
1216
1317
FormatStyle: file
1418
UseColor: true
19+
20+
CheckOptions:
21+
# modernize-use-nullptr: replace 0/NULL with nullptr
22+
- key: modernize-use-nullptr.NullMacros
23+
value: 'NULL'
24+
25+
# performance-unnecessary-value-param: catch expensive-by-value parameters
26+
- key: performance-unnecessary-value-param.AllowedTypes
27+
value: 'std::string;std::vector'
28+
29+
# bugprone-use-after-move: catch use-after-move mistakes
30+
- key: bugprone-use-after-move.WarnOnMacros
31+
value: 1

.clangd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# .clangd
22
CompileFlags:
3-
Add: [-Wall, -Wextra, -Wpedantic, -std=c++23]
3+
Add: [-std=c++20]
44
Diagnostics:
55
UnusedIncludes: Strict
66
Suppress: ["-Wdeprecated-copy"]

.editorconfig

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
# .editorconfig
2-
root = true
3-
1+
# Default for all files
42
[*]
53
indent_style = space
64
indent_size = 2
75
end_of_line = lf
86
charset = utf-8
97
trim_trailing_whitespace = true
108
insert_final_newline = true
9+
10+
# Tab indentation for Makefiles
11+
[Makefile]
12+
indent_style = tab
13+
14+
# Four‑space indent for C/C++ source
15+
[*.{c,cpp,h,hpp}]
16+
indent_size = 4
17+
18+
# Soft‑wrapped Markdown, trim trailing space only on non‑list lines
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
max_line_length = 120
22+
23+
# Two‑space indent for YAML and JSON
24+
[*.{yml,yaml,json}]
25+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: Install dependencies
5252
run: |
5353
sudo apt-get -qq update
54-
sudo apt-get -qq install -y clang lld gcc g++ ccache --no-install-recommends
54+
sudo apt-get -qq install -y clang gcc g++ ccache --no-install-recommends
5555
5656
- name: Cache ccache
5757
uses: actions/cache@v4
@@ -64,8 +64,9 @@ jobs:
6464
- name: Cache build directory
6565
uses: actions/cache@v4
6666
with:
67-
path: build/
68-
key: ${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ github.sha }}
67+
path: build/${{ matrix.compiler }}-${{ matrix.build_type }}
68+
key: |
69+
${{ runner.os }}-build-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
6970
restore-keys: |
7071
${{ runner.os }}-build-
7172
@@ -76,4 +77,4 @@ jobs:
7677
run: cmake --build --preset ${{ matrix.compiler }}-${{ matrix.build_type }}
7778

7879
- name: Run tests (ctest)
79-
run: ctest --preset ${{ matrix.compiler }}-${{ matrix.build_type }}
80+
run: ctest --preset ${{ matrix.compiler }}-${{ matrix.build_type }} --fail-fast

.github/workflows/clang-format.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ jobs:
4949
uses: actions/cache@v4
5050
with:
5151
path: build/
52-
key: ${{ runner.os }}-build-${{ github.sha }}
52+
key: |
53+
${{ runner.os }}-clang-format-${{ hashFiles('**/.clang-format','cmake/Tooling.cmake') }}
5354
restore-keys: |
54-
${{ runner.os }}-build-
55+
${{ runner.os }}-clang-format-
5556
5657
- name: Configure with CMake Preset
5758
run: cmake --preset $CMAKE_PRESET_NAME -DENABLE_CLANG_FORMAT=ON

.github/workflows/clang-tidy.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
name: clang-tidy
22

3-
on:
4-
push:
5-
branches: [ master ]
6-
paths:
7-
- '**/*.cpp'
8-
- '**/*.hpp'
9-
- '.clang-tidy'
10-
- 'cmake/Tooling.cmake'
11-
- '.github/workflows/clang-tidy.yml'
12-
13-
pull_request:
14-
branches: [ master ]
15-
paths:
16-
- '**/*.cpp'
17-
- '**/*.hpp'
18-
- '.clang-tidy'
19-
- 'cmake/Tooling.cmake'
20-
- '.github/workflows/clang-tidy.yml'
3+
on: [push, pull_request]
214

225
jobs:
236
lint:
@@ -47,9 +30,10 @@ jobs:
4730
uses: actions/cache@v4
4831
with:
4932
path: build/
50-
key: ${{ runner.os }}-build-${{ github.sha }}
33+
key: |
34+
${{ runner.os }}-clang-tidy-${{ hashFiles('**/CMakeLists.txt','cmake/**/*.cmake','.clang-tidy') }}
5135
restore-keys: |
52-
${{ runner.os }}-build-
36+
${{ runner.os }}-clang-tidy-
5337
5438
- name: Configure project
5539
run: cmake --preset $CMAKE_PRESET_NAME -DENABLE_CLANG_TIDY=ON

.github/workflows/coverage.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- '**/*.cpp'
88
- '**/*.hpp'
9+
- 'tests/**'
910
- 'CMakeLists.txt'
1011
- 'cmake/Coverage.cmake'
1112
- '.github/workflows/coverage.yml'
@@ -39,15 +40,17 @@ jobs:
3940
uses: actions/cache@v4
4041
with:
4142
path: $CACHE_DIR
42-
key: ${{ runner.os }}-ccache-${{ github.sha }}
43+
key: |
44+
${{ runner.os }}-ccache-${{ hashFiles('**/CMakeLists.txt','cmake/Coverage.cmake') }}
4345
restore-keys: |
4446
${{ runner.os }}-ccache-
4547
4648
- name: Cache build directory
4749
uses: actions/cache@v4
4850
with:
4951
path: build/
50-
key: ${{ runner.os }}-build-${{ github.sha }}
52+
key: |
53+
${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt','cmake/Coverage.cmake') }}
5154
restore-keys: |
5255
${{ runner.os }}-build-
5356

.gitignore

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# === CMake build artifacts ===
1+
# === Build Artifacts ===
2+
3+
# CMake out-of-source dirs
24
build/
5+
out*/
6+
cmake-build-*/
37
CMakeFiles/
48
CMakeCache.txt
59
cmake_install.cmake
@@ -8,49 +12,66 @@ compile_commands.json
812
install/
913
!cmake/install
1014

11-
# === Ninja build ===
15+
# Ninja
1216
*.ninja
13-
.ninja_deps
14-
.ninja_log
15-
rules.ninja
17+
.ninja_*
18+
19+
# === IDEs & Editors ===
1620

17-
# === VS Code ===
18-
.vscode/*.code-workspace
19-
.vscode/ipch/
20-
.vscode/cmakesettings.json
21+
# VS Code
22+
.vscode/
23+
# JetBrains
24+
.idea/
25+
*.iml
2126

22-
# === Editor backups ===
27+
# Editor backups
2328
*~
2429
*.swp
2530
*.bak
2631
*.tmp
2732

28-
# === Logs and crash reports ===
29-
*.log
30-
*.core
31-
32-
# === clangd index ===
33-
.clangd/
34-
.cache/
35-
.clangd/index/
33+
# === OS-specific ===
34+
.DS_Store
35+
Thumbs.db
36+
ehthumbs.db
3637

37-
# === Sanitizer dumps (optional) ===
38+
# === Tools & Packages ===
39+
# Sanitizer dumps
3840
leak*.txt
3941
san.*.log
4042

41-
# === Precompiled headers (if used) ===
42-
*.gch
43-
*.pch
43+
# Coverage & profiler
44+
coverage/
45+
*.info
46+
*.gcno
47+
*.gcda
48+
profiler.*
4449

45-
# === Conan (optional for later) ===
50+
# Conan & vcpkg
4651
conanbuildinfo.*
4752
.cmake/conan*
53+
vcpkg_installed/
54+
vcpkg_buildtrees/
4855

49-
# === CTest / testing output ===
56+
# === Testing & Logs ===
5057
Testing/
5158
test_output/
59+
*.log
60+
*.core
61+
62+
# === Packaging & Archives ===
63+
*.zip
64+
*.tar.gz
65+
*.tgz
66+
*.rpm
67+
68+
# === Documentation Builds ===
69+
docs/_build/
70+
docs/html/
71+
docs/latex/
5272

53-
# === Docs ===
54-
docs/*
55-
!docs/Doxyfile.in
56-
!docs/mainpage.md
73+
# === Miscellaneous ===
74+
tmp/
75+
temp/
76+
__pycache__/
77+
*.lock

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
2-
project(modern_cpp LANGUAGES CXX VERSION 0.1.0)
2+
project(modern_cpp
3+
LANGUAGES CXX
4+
VERSION 0.1.0
5+
DESCRIPTION "Modern C++ project template"
6+
HOMEPAGE_URL "https://github.com/ramsafin/modern-cpp-project-template"
7+
)
8+
9+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
10+
message(FATAL_ERROR "In-source builds are not allowed! Retry in a separate build directory.")
11+
endif()
312

413
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
514

@@ -20,9 +29,6 @@ include(Helpers)
2029
# === Coverage ===
2130
include(Coverage)
2231

23-
# === Logging ===
24-
include(Logging)
25-
2632
# === Library ===
2733
add_subdirectory(src)
2834

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
- [Contributing](#contributing)
2626
- [License](#license)
2727

28-
2928
## Features
3029

3130
- **Modern C++20+**: fully enabled C++20 with support for upgrading to C++23
@@ -40,22 +39,27 @@
4039
- **Installation**: provides `find_package(...)` integration with proper exports
4140
- **CI-Ready**: GitHub Actions for builds, linting, testing, and formatting
4241

43-
4442
## Project Structure
4543

4644
```text
4745
modern-cpp-project-template/
46+
├── .github/workflows/ # CI pipelines for GitHub Actions
47+
├── .vscode/ # VS Code workspace settings
4848
├── app/ # Optional demo application
4949
├── benchmarks/ # Google Benchmark performance tests
50-
├── cmake/ # Custom CMake modules (warnings, sanitizers, tooling)
51-
├── include/ # Public headers
50+
├── cmake/ # Custom CMake modules (Options, Flags, Helpers, etc.)
51+
├── include/ # Public library headers
5252
├── src/ # Library source files
53-
├── tests/ # Unit tests using GoogleTest
53+
├── tests/ # Unit tests (GoogleTest)
5454
├── .clang-format # Formatting rules
5555
├── .clang-tidy # Static analysis configuration
56-
├── CMakeLists.txt # Top-level CMake build configuration
56+
├── .clangd # Clangd language server settings
57+
├── .editorconfig # Editor consistency rules
58+
├── .gitignore # Git ignore patterns
59+
├── CMakeLists.txt # Top-level build configuration
5760
├── CMakePresets.json # Build, test, and workflow presets
58-
└── README.md
61+
├── LICENSE # Apache 2.0 license
62+
└── README.md # Project documentation
5963
```
6064

6165
## Prerequisites

0 commit comments

Comments
 (0)