Code Browser with KDE or Qt Projects
In my previous post I talked about the Woboq Code Browser.
While the instructions for compilation and usage are quite good, in this post I will try to summarize them for a specific use case: the generation of HTML files for a KDE/Qt application using the CMake
build system, on the Linux platform. These instructions should also works for a generic CMake
project using plain C++.
Requirements
This post assumes that you are a Qt/KDE developer on a Linux system. This means that you should already have all the needed stuff (git
, cmake
, etc.). Just make sure to have clang
(and llvm-config
) installed under /usr/bin
. This makes the process easier.
Compilation
First of all, you need to compile the codebrowser.
Clone the codebrowser source files:
Start compiling:
Now you have the two codebrowser components: build/generator/codebrowser_generator
and build/indexgenerator/codebrowser_indexgenerator
.
Installation
Since clang
expects to find the system libraries in ../lib
relative to the executable, you have two choices:
Option 1: install the codebrowser components.
In this way you can use the codebrowser everywhere:
Option 2: link the system libraries to the build/
directory:
I don’t like the latter because you need to type the extended path when using the codebrowser; but it’s up to you.
In either cases, you need to copy the data/
directory to the directory that will contain the generated HTML files. The output directory in this example will be ~/public_html
:
Usage
Now you are ready to generate the HTML for your KDE or Qt foo
project. Just make sure that you have a git
local repository for foo
.
Generate the compile_commands.json
. This will tell to the codebrowser which source files has to process:
Then generate the source code HTML pages. The output directory in this example will be ~/public_html
:
If you are interested, codebrowser_generator -help
will explain the meaning of the used options.
Last step: generate the HTML index:
Done. Simply open in your preferred browser ~/public_html/foo/index.html
and enjoy it!
(Optional) Optimization
By default, for (e.g.) a KDE project the codebrowser generates not only the code for the project itself, but also for all the included libraries. This translates in (at least) the whole KDE, the whole Qt and many C++ standard headers. If you want to upload the generated HTML on your webserver, this might be a problem if you have storage concerns, for example if you are on a shared server.
Fortunately, the codebrowser gives you the option to link external generated libraries. Just use the -e
option like in this way: