Skip to content

Commit

Permalink
Add support for include-what-you-use (#61)
Browse files Browse the repository at this point in the history
include-what-you-use is a utility developed at Google that analyzes C and C++ source files, looking for violations of the Include What You Use rule, and recommends fixes for them.

"The main goal of include-what-you-use is to remove superfluous #includes. It does this both by figuring out what #includes are not actually needed for this file (for both .cc and .h files), and replacing #includes with forward-declares when possible."

This CL implements a cmake option that can be used to run include-what-you-use on krnlmon. It requires standalone build support, plus a trivial change to FindDpdkDriver in order to analyze krnlmon for DPDK.

Signed-off-by: Derek G Foster <[email protected]>
  • Loading branch information
ffoulkes authored Oct 17, 2023
1 parent 47c61cc commit f84a456
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cmake_minimum_required(VERSION 3.15)
project(krnlmon LANGUAGES C CXX)

include(FindPkgConfig)
include(cmake/iwyu.cmake)

# Find netlink libraries
pkg_check_modules(nl3 REQUIRED IMPORTED_TARGET libnl-3.0)
Expand Down
15 changes: 15 additions & 0 deletions cmake/iwyu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# cmake -B build <other options> -DIWYU=ON
# cmake --build build >& iwyu.log

option(IWYU "Run include-what-you-use" OFF)

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

0 comments on commit f84a456

Please sign in to comment.