Skip to content

Instantly share code, notes, and snippets.

@mortie
Created December 6, 2022 10:14
Show Gist options
  • Save mortie/62dabf3baf0305a92c1ca7cf8fe76777 to your computer and use it in GitHub Desktop.
Save mortie/62dabf3baf0305a92c1ca7cf8fe76777 to your computer and use it in GitHub Desktop.
Meson project with clang-tidy and clang-format integration
project('test', 'cpp')
clang_tidy_prog = find_program('clang-tidy', required: false)
run_clang_tidy_prog = find_program('./run-clang-tidy.sh')
clang_format_prog = find_program('clang-format', required: false)
run_clang_format_prog = find_program('./run-clang-format.sh')
srcs = [
'src/foo.cc',
'src/bar.cc',
'src/main.cc',
]
hdrs = [
'src/foo.h',
'src/bar.h',
]
executable('test', srcs)
if clang_format_prog.found()
format_deps = []
foreach path: srcs + hdrs
stamp = 'format__' + path.replace('/', '__')
format_deps += custom_target(
stamp,
input: path,
output: stamp,
command: [
run_clang_format_prog, clang_format_prog, '@OUTPUT@',
'--style=file:' + meson.current_source_dir() + '/.clang-format',
'-i', '@INPUT@',
],
)
endforeach
alias_target('format', format_deps)
endif
if clang_tidy_prog.found()
tidy_deps = []
foreach path: srcs
stamp = 'tidy__' + path.replace('/', '__')
tidy_deps += custom_target(
stamp,
input: path,
output: stamp,
command: [
run_clang_tidy_prog, clang_tidy_prog, '@OUTPUT@', '--use-color', '--quiet',
'-p', meson.project_build_root(),
'--config-file=' + meson.current_source_dir() + '/.clang-tidy',
'@INPUT@',
],
)
endforeach
alias_target('tidy', tidy_deps)
endif
#!/bin/bash
set -eo pipefail
clang_format="$1"
shift
outfile="$1"
shift
"$clang_format" "$@" 2>&1 | tee "$outfile" >&2
#!/bin/bash
set -eo pipefail
clang_tidy="$1"
shift
outfile="$1"
shift
"$clang_tidy" "$@" 2>&1 | tee "$outfile" | sed '/[0-9]\+ warnings\{0,1\} generated\./d' >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment