I did not know any tool which can easily do this kind of validations for C/C++ source code, so I came up with a small bash script that does exactly this. The only configuration needed are some rules that define the architecture. Architecture is in this case a layered architecture where certain modules are only allowed to include certain other modules. See image 1 for a small UML diagram of the architecture.
These rules can be edited at the top of the script:
RULES="content->structure \
content->datatype \
content->io \
content->util \
structure->datatype \
structure->io \
structure->util \
datatype->io \
datatype->util \
io->util \
content->fontconfig \
content->Carbon \
util->\.\. \
src->.* \
.*->tr1 \
.*->sys"
As you can see, it is also possible to use regular expressions. Also, I had to add some rules for includes like fontconfig (external libraries) that are not available in the UML diagram above.
The script produces quite a lot of output, but grepping for "violation" shows only the important results:
If you are interested you can get the bash script from here: check_architecture.sh The script should be self-explaining and pretty easy to adapt to your needs.