Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang-Tidy llvm-header-guard directory configuration

Is there a way to remove the suggested computer specific path on the suggested llvm-header-guard string when running static analysis with clang-tidy?

For example the suggested header guard for the file (cls/math/matrix.hpp) is: _USERS_NAME_DESKTOP_PROJECT_SRC_CLS_MATH_MATRIX_HPP

But to avoid making this specific to my computer it should only be: _PROJECT_SRC_CLS_MATH_MATRIX_HPP

Is there a way to configure clang-tidy such that it suggests header guards starting from the /project/ directory rather than the /users/ directory?

I am using clang 5.0.0, running from cmake.

like image 804
user7119460 Avatar asked Sep 28 '17 11:09

user7119460


1 Answers

I've also had this problem for ages and finally figured it out, at least for public includes: clang-tidy assumes that headers are within a directory called include.

So, if your headers are like /home/me/myproject/include/myproject/header.h then it will work properly and recommend MYPROJECT_HEADER_H. If it doesn't find an include directory to treat as the root, then it falls back to the absolute path.

So the solution for libraries is to use that structure (which is probably a good idea anyway). I am still not sure about headers inside a project's source though.

like image 109
drobilla Avatar answered Sep 29 '22 14:09

drobilla