Clang-Tidy llvm-header-guard directory configuration
Asked Answered
G

1

17

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.

Gregale answered 28/9, 2017 at 11:57 Comment(2)
Did you ever resolve this? If so, please let me know how!Unproductive
Unfortunately not, sorry! My work around was to settle to creating a file template script.Gregale
W
6

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.

Wexler answered 20/11, 2019 at 21:4 Comment(3)
"which is probably a good idea anyway" not if you have headers which you want to keep internal to your project, surely. It's often preferable to keep MyApi.cpp and MyApi.h together in a src folder away from externally-facing interfaces.Dreamworld
Sure, I just meant for public includes, obviously that doesn't apply for side-by-side headers and implementations. I'm guessing this is a symptom of the check being implemented specifically for LLVM which doesn't do that. It would be nice if it were more general, or at least better documented.Wexler
Yes, I agree. This test is almost very useful but instead is not much use at all.Dreamworld

© 2022 - 2024 — McMap. All rights reserved.