Building Sourcetrail

By Abhijit Menon-Sen <>

Here's how I downloaded and built the source code for Sourcetrail and all its dependencies, as a first step towards getting involved in its continued development.

$ git clone https://github.com/CoatiSoftware/Sourcetrail.git

I started by reading the “How to build” section in README.md, which lists the required dependencies. As for tools, the Debian packages for cmake, git, and ccache will suffice (and I already had them installed).

Boost

Sourcetrail requires Boost 1.67, so I could have used the Debian package for libboost-all-dev 1.67.0.1, but I downloaded and built the latest Boost 1.74.0 instead.

$ wget https://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.bz2
$ sha256sum boost_1_74_0.tar.bz2 
83bfc1507731a0906e387fc28b7ef5417d591429e51e788417fe9ff025e116b1  boost_1_74_0.tar.bz2
$ tar xjf boost_1_74_0.tar.bz2 && cd boost_1_74
$ ./bootstrap.sh \
    --with-libraries=filesystem,program_options,system,date_time
…
$ ./b2 --link=static --variant=release \
    --threading=multi --runtime-link=static \
    --cxxflags=-fPIC
…
The Boost C++ Libraries were successfully built!

(I copied these build commands from the Sourcetrail README, but the Boost documentation also describes the process in detail.)

Qt5

Sourcetrail requires Qt 5.12.3, but the qtbase5-dev package in Debian is only for 5.11.3. You can download Qt5 binaries (which require you to create a “Qt Account” to get access to “exclusive services, support and information”), but I followed instructions to build the Qt5 source instead.

$ git clone https://code.qt.io/qt/qt5.git
Cloning into 'qt5'... […]
$ cd qt5 && git checkout 5.12
Branch '5.12' set up to track remote branch '5.12' from 'origin'.
Switched to a new branch '5.12'
$ perl init-repository --module-subset=default,-qtwebengine
…

After cloning the repository and submodules, I had a 3GB qt5 directory. Then I installed some dependency packages, created a separate qt5-build directory, and ran configure, make, and make install as shown below to install the libraries into /usr/local/lib/Qt-5.12.10.

$ sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev \
    libglu1-mesa-dev libxrender-dev libxi-dev \
    libxkbcommon-dev libxkbcommon-x11-dev
…
$ cd qt5-build
$ ../qt5/configure -ccache -release -opensource \
    -nomake examples -nomake tests
…
$ make -j3
…
$ sudo make install
…

This gave me enough time to bring in some firewood, make the fire, heat water, have a nice hot bath, find a matching pair of socks with no holes in them from the Set of All Possible Socks (which lives in my bedroom), grind some coffee beans, brew coffee, and write this article.

Although I had LLVM installed, as described below, and I set my PATH to include llvm-config and also set LLVM_INSTALL_DIR to /usr/lib/llvm-10 as instructed, configure could not find whatever it needed to build QDoc. I ignored this problem for the moment.

LLVM

Sourcetrail requires LLVM 10 in order to index C/C++ source code. The instructions link to this page about how to build LLVM from source, but I installed the llvm-10 packages from apt.llvm.org to save time.

# cat > /etc/apt/sources.list.d/llvm.list
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main
# curl https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add -
OK
# apt update && apt install -y llvm-10 llvm-10-dev \
    llvm-10-tools clang-10 libclang1-10 libclang-10-dev
…

LLVM 10 is now the “old stable” version. (After I have a working build, I'll try rebuilding using LLVM 11, the current stable version.)

Sourcetrail

Finally, with all the dependencies installed, I compiled Sourcetrail itself.

$ cd Sourcetrail
$ mkdir -p build/Release
$ cd build/Release
$ cmake -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_CXX_LANGUAGE_PACKAGE=ON \
    -DBUILD_JAVA_LANGUAGE_PACKAGE=ON \
    -DBUILD_PYTHON_LANGUAGE_PACKAGE=ON \
    -DBOOST_ROOT=/home/ams/build/boost_1_74_0 \
    -DClang_DIR=/usr/lib/llvm-10/lib/cmake/clang \
    -DQt5_DIR=/usr/local/Qt-5.12.10/lib/cmake/Qt5 \
    ../..
…
$ make -j3 Sourcetrail
…

Sourcetrail also supports Java, and I happened to have OpenJDK 11 and a recent-ish version of Maven installed, so I enabled the Java build in a fit of sheer optimism. To my surprise, it just worked.

I started build/Release/app/Sourcetrail and created a new project for the Sourcetrail source code itself to test that everything worked. I did have to spend some time adding the correct include paths to Qt and LLVM before indexing completed successfully. This was my reward:

MainView class relationships within Sourcetrail