Set CXX_INCLUDE_WHAT_YOU_USE property in CMake for every target

4.4k Views Asked by At

I have multiple CmakeLists.txt in my project and I'd like to enable iwyu.

Adding

set_property(
  TARGETS MY-TARGET
  PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path}
)

would enable it for one target. I'd like to enable it for every target to avoid redundancy in another file.cmake I include in the CMakeLists.txt which already exists.

1

There are 1 best solutions below

6
On BEST ANSWER
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

find_program(IWYU_PATH NAMES include-what-you-use iwyu)
if(NOT IWYU_PATH)
  message(FATAL_ERROR "Could not find the program include-what-you-use")
endif()
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_PATH})
set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH})

The "documentation" can be found here: CMAKE_<LANG>_INCLUDE_WHAT_YOU_USE