Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A pre-commit hook repo that auto-installs and runs `clang-format` and `clang-tid
| `cpp_linter_hooks/clang_tidy.py` | clang-tidy wrapper (`--compile-commands`, `--jobs`, `--fix`, error hints) |
| `.pre-commit-hooks.yaml` | Hook metadata for pre-commit framework |
| `testing/` | Test fixtures (`main.c`, `good.c`, `.clang-format`, `.clang-tidy`, CMakeLists) |
| `examples/` | Example configs (CMake, large-project scoping) |
| `examples/` | Example configs (CMake, Meson, large-project scoping) |

## Development

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ To disable auto-detection (e.g. in a monorepo where auto-detect might pick the w

### Examples

Two self-contained templates plus quick snippets for other common setups.
Three self-contained templates plus quick snippets for other common setups.

- [CMake minimal config](https://github.com/cpp-linter/cpp-linter-hooks/tree/main/examples/cmake)
- [Meson minimal config](https://github.com/cpp-linter/cpp-linter-hooks/tree/main/examples/meson)
- [Large project `files:` regex](https://github.com/cpp-linter/cpp-linter-hooks/tree/main/examples/large-project) — scoping hooks for speed
- [Quick snippets](https://github.com/cpp-linter/cpp-linter-hooks/blob/main/examples/README.md) — Meson, clang-format-only, monorepo, CI, `compile_commands.json`

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Examples

- [CMake project](cmake/)
- [Meson project](meson/)
- [Large project `files:` regex](large-project/) — scoping hooks for speed

## Quick snippets
Expand Down
42 changes: 42 additions & 0 deletions examples/meson/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Meson Project

If you already have a Meson project, configure the hooks and generate a compilation database.

## .pre-commit-config.yaml

```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.6.1
hooks:
- id: clang-format
args: [--style=file, --version=21]
files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$

- id: clang-tidy
args: [--version=21, --compile-commands=builddir]
files: ^(src|include)/.*\.(cpp|cc|cxx)$
```

## Generate the compilation database

Run from the project root, where `meson.build` lives:

```bash
meson setup builddir
pre-commit install
pre-commit run --all-files
```

Meson's default Ninja backend writes `builddir/compile_commands.json` during setup.
This gives `clang-tidy` the compiler flags and include paths for each source file.
No separate compilation step is required to generate the database. If the project
needs generated headers, build those first with `meson compile -C builddir`.

`--compile-commands` takes the **directory** containing `compile_commands.json`,
not the file path. `builddir/` is not one of the auto-detected directories, so the
explicit argument above is required. If you use `meson setup build` instead,
`build/` is auto-detected and the argument can be omitted.

To regenerate the database after changing build options, run
`meson setup --reconfigure builddir` before the hooks.
Loading