Thanks to this answer, I learned I could run include-what-you-use on my C++ project by using the following in CMake:
set_property(TARGET ${target_name}
PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
This outputs suggestions on what to include when I run cmake --build
on my project:
Warning: include-what-you-use reported diagnostics:
/home/user/hello/main.cc should add these lines:
/home/user/hello/main.cc should remove these lines:
- #include <vector> // lines 2-2
The full include-list for /home/user/hello/main.cc:
#include <iostream> // for operator<<, basic_ostream, cout, endl, ostream
The include-what-you-use documentation explains how to automatically apply these suggestions, so that I can always use the "full include-list" specified by include-what-you-use
:
make -k CXX=/path/to/llvm/Debug+Asserts/bin/include-what-you-use > /tmp/iwyu.out
python fix_includes.py < /tmp/iwyu.out
Is there a way to automatically apply suggestions when using the CMake CXX_INCLUDE_WHAT_YOU_USE
property? If not, is there a way I can apply suggestions as part of my CMake build?