Skip to content

Commit

Permalink
Use the new helper for IWYU. Move it to the Linters CMake.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Mar 24, 2024
1 parent b0fd1db commit 7f68568
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 50 deletions.
50 changes: 0 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -620,53 +620,3 @@ SET(CPACK_SOURCE_IGNORE_FILES
INCLUDE(CPack)

ADD_CUSTOM_TARGET(dist COMMAND ${CMAKE_MAKE_PROGRAM} clean package_source)

#################### IWYU
# Needs to be part of the top-level to be able to find all targets in the compiler framework.
if(ENABLE_IWYU)
# Set up IWYU for P4C.
message("Enabling IWYU checks.")
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path
${iwyu_path}
-Xiwyu
--max_line_length=100
-Xiwyu
--no_fwd_decls
-Xiwyu
--cxx17ns
-Xiwyu
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/p4c.imp
)
message("IWYU command: ${iwyu_path}")
function(get_all_targets var)
set(targets)
get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()

macro(get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
get_all_targets_recursive(${targets} ${subdir})
endforeach()

get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()

# Apply IWYU to all targets.
get_all_targets(all_targets)
# Remove generated files from IWYU.
list(FILTER all_targets EXCLUDE REGEX "controlplane-gen")
list(FILTER all_targets EXCLUDE REGEX "dpdk_runtime")
list(FILTER all_targets EXCLUDE REGEX "ir-generated")
list(FILTER all_targets EXCLUDE REGEX "genIR")
list(FILTER all_targets EXCLUDE REGEX "parser-gen")
list(FILTER all_targets EXCLUDE REGEX "gtest")
message("Applying IWYU to targets: ${all_targets}")
foreach(target ${all_targets})
set_property(TARGET ${target} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endforeach()

endif()
36 changes: 36 additions & 0 deletions cmake/Linters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,39 @@ if(NOT ${BLACK_CMD} OR NOT (NOT ${ISORT_CMD}))
else()
message(WARNING "black or isort executable not found. Disabling black/isort checks. black/isort can be installed with \"pip3 install --user --upgrade black\" and \"pip3 install --user --upgrade isort\" ")
endif()

#################### IWYU
if(ENABLE_IWYU)
# Set up IWYU for P4C.
message("Enabling IWYU checks.")
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path
${iwyu_path}
-Xiwyu
--max_line_length=100
-Xiwyu
--no_fwd_decls
-Xiwyu
--cxx17ns
-Xiwyu
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/p4c.imp
)
message("IWYU command: ${iwyu_path}")


get_all_targets(ALL_IWYU_TARGETS ${CMAKE_CURRENT_SOURCE_DIR})
# Apply IWYU to all targets.
get_all_targets(ALL_IWYU_TARGETS)
# Remove generated files from IWYU.
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "controlplane-gen")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "dpdk_runtime")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "ir-generated")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "genIR")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "parser-gen")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "gtest")
message("Applying IWYU to targets: ${all_targets}")
foreach(target ${ALL_IWYU_TARGETS})
set_property(TARGET ${target} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endforeach()

endif()

0 comments on commit 7f68568

Please sign in to comment.