Codebrowser(woboq) setup for C/C++ code

1. Install codebrowser

First, we need to install codebrowser along with dependancies. We can install from binary (.deb) file at this link. Note that the binary available at this location is an old build.

sudo dpkg -i woboq-codebrowser_2.1_amd64.deb
sudo apt install libtinfo5

OR
We can build it using the source code,

sudo apt install  llvm-7 clang-7 libclang-7-dev
git clone https://github.com/KDAB/codebrowser.git
cd codebrowser
cmake . -DCMAKE_BUILD_TYPE=Release
make
sudo make install

For woboq enhancements, please refer to Deployment Tips

2. Generate compile_commands.json

The next most important thing is to generate compile_commands.json for our project. For woboq tools, the format of compile_commands.json entry should of the following template:

{
    "directory": "/home/user/dev/llvm/build",
    "file": "/home/user/dev/llvm/llvm/lib/Support/APFloat.cpp",
    "command": "/usr/bin/g++ ... /dev/llvm/llvm/lib/Support/APFloat.cpp"
}

Note that woboq currently doesn't support the latest format of compile_commands entries with output field as shown below,

{
  "directory": "/home/user/dev/llvm/build",
  "file": "/tmp/foo.cpp",
  "output": "foo.o",
  "arguments": ["/usr/bin/g++", ... ]
}

3. Run woboq generators

Now we can generate browsable code files for our project
OUTPUT_DIRECTORY=~/public_html/postgres
DATA_DIRECTORY=$OUTPUT_DIRECTORY/../data
mkdir -p $OUTPUT_DIRECTORY
mkdir -p $DATA_DIRECTORY


BUILD_DIRECTORY=$PWD
SOURCE_DIRECTORY=$PWD
VERSION=`git describe --always --tags`

codebrowser_generator -b $BUILD_DIRECTORY -a \
-o $OUTPUT_DIRECTORY \
-p postgres:$SOURCE_DIRECTORY:$VERSION


codebrowser_indexgenerator $OUTPUT_DIRECTORY
Copy required css/js files
cp -rv /usr/share/woboq/data/.* $DATA_DIRECTORY/
Alternatively, we can also use the latest css/js files from woboq repository
git clone https://github.com/KDAB/codebrowser
cd codebrowser
cp -rv data/.* $DATA_DIRECTORY/

4. Start a webserver

cd ~/public_html
python3 -m http.server 8000
Now we can browse through generated files :)