By default, clang-uml
will look for file .clang-uml
in the project's directory and read all diagram definitions configuration from it. The file must be specified in YAML and it's overall structure is as follows:
The top level common options are inherited by specific diagrams, if the option is applicable to them and they themselves do not override this option.
For detailed reference of all configuration options see here.
Effective configuration, including default values can be printed out in YAML format using the following option:
Each type of diagram can have a title
property, which will be generated in the diagram using directives specific to a given diagram generator, for instance:
One of the key options of the diagram configuration is the list of translation units, which should be parsed to get all necessary information for a diagram.
The syntax is simple and based on glob patterns, which can be added to the configuration file as follows:
The glob patterns only need to match the translation units, which are also in the compile_commands.json
file, i.e. any files that match the glob patterns, but are not in compile_commands.json
will be ignored. In case the glob
pattern set does not match any translation units an error will be printed on the standard output.
For more advanced control over the glob
pattern, instead of simple glob style pattern, a full regular expression can be provided as an object with a single key r
. In such case, the pattern will not be checked against file system at all but will only filter the compile commands database entries. This can significantly improve performance on projects with tens of thousands of translation units.
For small projects, the glob
property can be omitted, which will result in clang-uml
parsing all translation units from compile_commands.json
for the diagram. However, for large projects, constraining the number of translation units for each diagram to minimum necessary to discover all necessary diagram elements will significantly decrease the diagram generation times.
In case it's necessary to add some custom PlantUML or MermaidJS declarations before or after the generated diagram content, it can be achieved using the plantuml
or mermaid
configuration properties, for instance for PlantUML:
or for MermaidJS:
These directives are useful for instance for adding notes to elements in the diagrams or customizing diagram layout and style.
Please note that when referring to diagram elements in PlantUML or MermaidJS directives, they must be added using Jinja templates alias
command as in the example above.
More options can be found in the official docs for each respective generator:
Sometimes it is useful for debugging issues with the diagrams to have information on the exact source location, from which given declaration or call expression was derived. By adding option:
the generated PlantUML diagram will contain comments before each line containing the source location of the specific diagram element.
Due to the fact, that a project can be compiled with different compilers and toolchains, the system paths and compilation flags detected by the Clang version linked to your clang-uml
installation might differ from the ones actually used to compile your project.
This is often an issue on macOS, when
clang-uml
uses Homebrew version of LLVM and a project was built using system Apple Clang.
Typically, this results in error messages on the console during diagram generation, such as:
or
These errors can be overcome, by ensuring that the Clang parser has the correct include paths to analyse your code base on the given platform. clang-uml
provides several mechanisms to resolve this issue:
This option is not available on Windows.
Providing this option on the clang-uml
command line will result in clang-uml
executing the specified compiler with the following command, e.g.:
and extracting from the output the target and system include paths, which are then injected to each entry of the compilation database. For instance, on my system, when generating diagrams for an embedded project and providing arm-none-eabi-gcc
as driver:
the following options are appended to each command line after argv[0]
of the command:
If you want to include the system headers reported by the compiler specified already as first argument of each compile command in your compile_commands.json
, you can simply invoke clang-uml
as:
however please make sure that the compile_commands.json
contains a command, which is safe to execute.
If the system paths extracted from the compiler are not sufficient to resolve include paths issues, it is possible to manually adjust the compilation flags by providing add_compile_flags
and remove_compile_flags
in the configuration file, or providing --add-compile-flag
and --remove-compile-flag
on the clang-uml
command line.
For instance:
remove_compile_flags
also accepts regular expression, so a single entry can remove a whole set of flags, e.g.:
These options can be also passed on the command line, for instance:
Yet another option, for CMake based projects, is to use the following CMake option:
On NixOS or when using nix
, clang-uml
uses a wrapper script, which builds and exports CPATH
and CPLUS_INCLUDE_PATH
environment variables before running clang-uml
, which contain valid system header Clang paths for the current Nix environment.
If you want to use an unwrapped version, the clang-uml-unwrapped
binary can be called the same way as clang-uml
.