Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress Abseil warnings. #4556

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
12 changes: 12 additions & 0 deletions cmake/Abseil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ macro(p4c_obtain_abseil)
)
fetchcontent_makeavailable_but_exclude_install(abseil)

# Suppress warnings for all Abseil targets.
get_all_targets(ABSL_BUILD_TARGETS ${absl_SOURCE_DIR})
foreach(target in ${ABSL_BUILD_TARGETS})
if(target MATCHES "absl_*")
# Do not suppress warnings for Abseil library targets that are aliased.
get_target_property(target_type ${target} TYPE)
if (NOT ${target_type} STREQUAL "INTERFACE_LIBRARY")
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "-Wno-error -w")
endif()
endif()
endforeach()

# Reset temporary variable modifications.
set(CMAKE_UNITY_BUILD ${CMAKE_UNITY_BUILD_PREV})
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV})
Expand Down
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()
15 changes: 15 additions & 0 deletions cmake/P4CUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,18 @@ macro(fetchcontent_makeavailable_but_exclude_install content)
add_subdirectory(${${content}_SOURCE_DIR} ${${content}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endmacro(fetchcontent_makeavailable_but_exclude_install)

# Collect all currently added targets in all subdirectories
#
# Parameters: - _result the list containing all found targets - _dir root directory to start
# looking from
# Sourced from https://stackoverflow.com/a/60232044
function(get_all_targets _result _dir)
get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
foreach(_subdir IN LISTS _subdirs)
get_all_targets(${_result} "${_subdir}")
endforeach()

get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS)
set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
endfunction()
Loading