Skip to content

Commit adbf9a9

Browse files
committed
README: Add compile_commands.json chapter
1 parent 23601be commit adbf9a9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ cmake . -DLLVM_CONFIG_EXECUTABLE=/usr/local/Cellar/llvm/<your_llvm_version>/bin/
7272
make
7373
```
7474

75+
compile_commands.json
76+
=====================
77+
We need a compile_commands.json file to know how your project is usually compiled.
78+
There are multiple ways to get this file:
79+
80+
* For cmake, pass -DCMAKE_EXPORT_COMPILE_COMMANDS=ON as a cmake parameter
81+
* For qmake, configure/autoconf and others, follow the instructions in scripts/fake_compiler.sh or scripts/woboq_cc.js.
82+
These are fake compilers that append the compiler invocation to the json file and forward to the real compiler.
83+
Your real compiler is overriden using the CC/CXX environment variables
84+
Make sure to have the json file properly terminated.
85+
* There is also a project called Build EAR (Bear) that achieves a similar thing as our fake compilers
86+
but is using LD_PRELOAD to inject itself into the build process to catch how the compiler is invoked.
87+
https://github.com/rizsotto/Bear
88+
7589

7690
Using the generator
7791
===================

scripts/fake_compiler.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
#
44
# This script can be used to generate the compile_commands.json file.
5-
# Configure this script as the compiler.
5+
# Configure this script as the compiler, e.g. with the CC/CXX environment variables.
66
# Export the $COMPILATION_COMMANDS environement variable to the full path of the compile_commands.json file.
77
# set $FORWARD_COMPILER to the path of the actual compiler to perform the actual compilation.
88
#
9-
# Example:
9+
# Example using configure (similar when using qmake):
1010
#
1111
# export COMPILATION_COMMANDS=/path/to/compile_commands.json
1212
# export FORWARD_COMPILER=g++
13-
# CXX=/path/to/fake_compiler.sh ./configure
13+
# CC=/path/to/fake_compiler.sh CXX=/path/to/fake_compiler.sh ./configure
1414
# echo "[" > $COMPILATION_COMMANDS
1515
# make -j1
1616
# echo " { \"directory\": \".\", \"command\": \"true\", \"file\": \"/dev/null\" } ]" >> $COMPILATION_COMMANDS

0 commit comments

Comments
 (0)