Make IWYU analyze included headers, not just main program

Viewed 38

I have a project which I compile with

CXX=clang++ cmake .. -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="iwyu"
make

The problem is that iwyu seems to be only looking at the *.cpp files being compiled and not at headers included from the cpp itself. What option you I pass to iwyu to force to analyze included headers. Of course I wouldn't be interested in reports of system headers (-isystem) but I am interested in headers that belong to the same project.

I tried with the option --check_also=*.hpp but I get the message error: unsupported option '--check_also=hpp'.


I realized that I have to put -Xiwyu in front any option. So, I have to do -Xiwyu --check_also=*.hpp but now I get this error:

Error running 'iwyu': iwyu: /usr/lib/llvm-11/include/clang/AST/Decl.h:251: llvm::StringRef clang::NamedDecl::getName() const: Assertion `Name.isIdentifier() && "Name is not a simple identifier"' failed.

which makes me think that this doesn't support patterns but individual files.

So, it seems that the use through cmake is not very useful for this case and it is better to check the whole project using:

find ./include -name '*.hpp' -exec iwyu -Xiwyu --cxx17ns -Xiwyu --quoted_includes_first -std=c++17 {} \;
0 Answers
Related