感谢this answer,我了解到我可以通过在CMake中使用以下内容在我的C ++项目上运行include-what-you-use:
set_property(TARGET ${target_name}
PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
这会在我对项目运行cmake --build
时输出有关包含内容的建议:
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
include-what-you-use documentation说明了如何自动应用这些建议,以便我始终可以使用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
使用CMake CXX_INCLUDE_WHAT_YOU_USE
属性时,有没有办法自动应用建议?如果没有,有没有办法可以将建议作为我的CMake构建的一部分来应用?