include-what-you-use (also referred to as iwyu or Iwyu in other places in this documentation) is an open-source tool which allows you to ensure very strict checks on what you do and do not include in a C/C++ source file.
For a successful include-what-you-use integration, the following prerequisites
must be met:
First and foremost, the include-what-you-use artifact must be made available to TICS. To do this, add the include-what-you-use artifact to config.yaml as shown in the example below. Note that different versions may apply to your situation.
versions:
checkers:
iwyu:
artifacts:
- version: '0.12'
platform: ubuntu-clang-8
Next, include-what-you-use needs to be configured for the Fan Out and/or Coding Standards metric. Configuration for these metrics is done in SERVER.yaml.
To utilize include-what-you-use for the Fan Out metric, set the FANOUT property of the C and/or C++ Language to Iwyu in SERVER.yaml.
Below an example for the C language:
LANGUAGES:
C:
FANOUT:
TOOL: Iwyu
By default, include-what-you-use is not included in any coding standard. To make use of include-what-you-use for coding standards, include-what-you-use coding standard rules have to be added to the coding standard.
The applied coding standard is specified in the RULESET → RULESDIR property of the C and C++ Language in SERVER.yaml.
LANGUAGES:
C:
RULESETS:
- METRIC: CODINGSTANDARD
RULESDIR: 4.0/codingstandards/C
At this location inside you will find the coding standard configuration files IMPL.txt and RULES.txt. Add the lines depicted below to these files respectively:
IWYU-MISSING Iwyu IWYU-MISSING IWYU-REMOVE Iwyu IWYU-REMOVE
IWYU-MISSING 3 Dependency management Header should be included directly. IWYU-REMOVE 3 Dependency management Superflous inclusion of header.
A mapping file can be added in any configuration directory that will be used by
TICS. This file must have the name iwyu_mapping.imp and have the
specified content format. If no iwyu_mapping.imp file is present
in the configuration, TICS will use a default file.
The contents of mapping files are better explained at include-what-you-use's own documentation. Specifically, an explanation of the contents of a mapping file can be found here: IWYUMappings