Just use https://github.com/rizsotto/Bear
Tools for working with compile_commands.json.
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo install --git https://github.com/korniltsev-grafanista/compdb.git filter
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo install --git https://github.com/korniltsev-grafanista/compdb.git ccThis installs three binaries:
compdb-filter- Filter compile_commands.json by regex patternscompdb-cc- C compiler wrapper for generating compile_commands.jsoncompdb-cxx- C++ compiler wrapper for generating compile_commands.json
Filter compile_commands.json by regex patterns.
compdb-filter [OPTIONS] [PATH]PATH- Path to compile_commands.json (default:./compile_commands.json)
-e, --exclude <REGEX>- Exclude files matching this regex (can be repeated)-i, --include <REGEX>- Include files matching this regex even if excluded (can be repeated)
Compiler wrappers that log compilation commands for generating compile_commands.json.
compdb-ccandcompdb-cxxact as drop-in replacements for your C/C++ compiler- They log each compilation command to a file
- After the build completes, run with
--generateto createcompile_commands.json
| Variable | Required | Description |
|---|---|---|
COMPDB_LOG |
Yes | Absolute path to the log file (e.g., /tmp/compdb.log) |
COMPDB_CC |
No | C compiler to use (default: clang) |
COMPDB_CXX |
No | C++ compiler to use (default: clang++) |
COMPDB_GENERATE |
No | Set to any non-empty value to generate compile_commands.json |
# Set up environment
export COMPDB_LOG=/tmp/compdb.log
export COMPDB_CC=gcc
export COMPDB_CXX=g++
# Build your project using the wrappers as compilers
./configure CC=compdb-cc CXX=compdb-cxx
make
# Generate compile_commands.json
compdb-cc --generate