Konfekt | af449f6 | 2024-10-05 17:09:21 +0200 | [diff] [blame] | 1 | " vim compiler file |
| 2 | " Compiler: cppcheck (C++ static checker) |
| 3 | " Maintainer: Vincent B. (twinside@free.fr) |
Konfekt | 5e48e97 | 2024-10-17 20:54:00 +0200 | [diff] [blame] | 4 | " Last Change: 2024 oct 17 by @Konfekt |
Konfekt | af449f6 | 2024-10-05 17:09:21 +0200 | [diff] [blame] | 5 | |
| 6 | if exists("cppcheck") |
| 7 | finish |
| 8 | endif |
| 9 | let current_compiler = "cppcheck" |
| 10 | |
| 11 | let s:cpo_save = &cpo |
| 12 | set cpo-=C |
| 13 | |
Konfekt | 5e48e97 | 2024-10-17 20:54:00 +0200 | [diff] [blame] | 14 | let s:slash = has('win32')? '\' : '/' |
| 15 | |
Konfekt | af449f6 | 2024-10-05 17:09:21 +0200 | [diff] [blame] | 16 | if !exists('g:c_cppcheck_params') |
| 17 | let g:c_cppcheck_params = '--verbose --force --inline-suppr' |
| 18 | \ ..' '..'--enable=warning,style,performance,portability,information,missingInclude' |
| 19 | \ ..' '..(executable('getconf') ? '-j' .. systemlist('getconf _NPROCESSORS_ONLN')[0] : '') |
| 20 | let s:undo_compiler = 'unlet! g:c_cppcheck_params' |
| 21 | endif |
| 22 | |
| 23 | let &l:makeprg = 'cppcheck --quiet' |
| 24 | \ ..' --template="{file}:{line}:{column}: {severity}: [{id}] {message} {callstack}"' |
Konfekt | 5e48e97 | 2024-10-17 20:54:00 +0200 | [diff] [blame] | 25 | \ ..' '..get(b:, 'c_cppcheck_params', get(g:, 'c_cppcheck_params', (&filetype ==# 'cpp' ? ' --language=c++' : ''))) |
Konfekt | af449f6 | 2024-10-05 17:09:21 +0200 | [diff] [blame] | 26 | \ ..' '..get(b:, 'c_cppcheck_includes', get(g:, 'c_cppcheck_includes', |
| 27 | \ (filereadable('compile_commands.json') ? '--project=compile_commands.json' : |
Konfekt | 5e48e97 | 2024-10-17 20:54:00 +0200 | [diff] [blame] | 28 | \ (!empty(glob('*'..s:slash..'compile_commands.json', 1, 1)) ? '--project='..glob('*'..s:slash..'compile_commands.json', 1, 1)[0] : |
| 29 | \ (empty(&path) ? '' : '-I')..join(map(filter(split(&path, ','), 'isdirectory(v:val)'),'shellescape(v:val)'), ' -I'))))) |
Konfekt | af449f6 | 2024-10-05 17:09:21 +0200 | [diff] [blame] | 30 | silent CompilerSet makeprg |
| 31 | |
| 32 | CompilerSet errorformat= |
| 33 | \%f:%l:%c:\ %tarning:\ %m, |
| 34 | \%f:%l:%c:\ %trror:\ %m, |
| 35 | \%f:%l:%c:\ %tnformation:\ %m, |
| 36 | \%f:%l:%c:\ %m, |
| 37 | \%.%#\ :\ [%f:%l]\ %m |
| 38 | |
| 39 | exe get(s:, 'undo_compiler', '') |
| 40 | |
| 41 | let &cpo = s:cpo_save |
| 42 | unlet s:cpo_save |