How to use the tool include-what-you-use together with CMake to detect unused headers?
The tool include-what-you-use can be used to detect unneeded headers. I am using CMake for my C++ software project. How can I instruct CMake to run include-what-you-use automatically on the source files of my software project? CMake 3.3 introduced the new target property CXX_INCLUDE_WHAT_YOU_USE that can be set to the path of the program include-what-you-use . For instance this CMakeLists.txt cmake_minimum_required(VERSION 3.3 FATAL_ERROR) add_executable(hello main.cc) find_program(iwyu_path NAMES include-what-you-use iwyu) if(NOT iwyu_path) message(FATAL_ERROR "Could not find the program