CMake include-what-you-use (IWYU)
Include-what-you-use IWYU is a static analysis tool that helps to find missing includes in C / C++ source files. Like any tool, IWYU makes mistakes, so make changes incrementally and be ready to rollback edits. CMake has IWYU support that is enabled in project CMakeLists.txt by including this stanza BEFORE any targets are defined:
option(iwyu "Run include-what-you-use")
if(iwyu)
find_program(IWYU_EXE NAMES include-what-you-use REQUIRED)
set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_EXE})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXE})
endif()