diff --git a/AGENTS.md b/AGENTS.md index c737811..a9c9391 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 diff --git a/README.md b/README.md index f5c10d5..8940f05 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/examples/README.md b/examples/README.md index ea0e53e..50f058d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,7 @@ # Examples - [CMake project](cmake/) +- [Meson project](meson/) - [Large project `files:` regex](large-project/) — scoping hooks for speed ## Quick snippets diff --git a/examples/meson/README.md b/examples/meson/README.md new file mode 100644 index 0000000..e00090f --- /dev/null +++ b/examples/meson/README.md @@ -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.