diff --git a/.cmake-format b/.cmake-format deleted file mode 100644 index 3eee8a7e58..0000000000 --- a/.cmake-format +++ /dev/null @@ -1,75 +0,0 @@ -# -------------------------- -# General Formatting Options -# -------------------------- -# How wide to allow formatted cmake files -line_width = 120 - -# How many spaces to tab for indent -tab_size = 2 - -# If an argument group contains more than this many sub-groups (parg or kwarg -# groups), then force it to a vertical layout. -max_subgroups_hwrap = 2 - -# If a positional argument group contains more than this many arguments, then -# force it to a vertical layout. -max_pargs_hwrap = 3 - -# If true, separate flow control names from their parentheses with a space -separate_ctrl_name_with_space = False - -# If true, separate function names from parentheses with a space -separate_fn_name_with_space = False - -# If a statement is wrapped to more than one line, than dangle the closing -# parenthesis on it's own line. -dangle_parens = False - -# If the trailing parenthesis must be 'dangled' on it's on line, then align it -# to this reference: `prefix`: the start of the statement, `prefix-indent`: the -# start of the statement, plus one indentation level, `child`: align to the -# column of the arguments -dangle_align = 'prefix' - -min_prefix_chars = 4 - -# If the statement spelling length (including space and parenthesis) is larger -# than the tab width by more than this amount, then force reject un-nested -# layouts. -max_prefix_chars = 10 - -# If a candidate layout is wrapped horizontally but it exceeds this many lines, -# then reject the layout. -max_lines_hwrap = 2 - -# What style line endings to use in the output. -line_ending = 'unix' - -# Format command names consistently as 'lower' or 'upper' case -command_case = 'lower' - -# Format keywords consistently as 'lower' or 'upper' case -keyword_case = 'unchanged' - -# If true, the argument lists which are known to be sortable will be sorted -# lexicographicall -enable_sort = True - -# If true, the parsers may infer whether or not an argument list is sortable -# (without annotation). -autosort = True - -# By default, if cmake-format cannot successfully fit everything into the -# desired linewidth it will apply the last, most aggressive attempt that it -# made. If this flag is True, however, cmake-format will print error, exit -# with non-zero status code, and write-out nothing -require_valid_layout = False - -# Specify structure for custom cmake functions -additional_commands = { - "pkg_find": { - "kwargs": { - "PKG": "*" - } - } -} diff --git a/.codespellrc b/.codespellrc index 65f2ea47f9..c7019c766a 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,4 +1,4 @@ [codespell] -skip = *.dat,typos-config.toml,.git,./ci,./Dist,./mk,./Tests/ExamplesTest/expected_output,./Tests/ExamplesTest/pcap_examples,./Tests/Packet++Test/PacketExamples,./Tests/Pcap++Test/PcapExamples,./3rdParty,./Examples/PcapSearch/dirent-for-Visual-Studio +skip = *.dat,typos-config.toml,.git,.venv,./ci,./Dist,./mk,./Tests/ExamplesTest/expected_output,./Tests/ExamplesTest/pcap_examples,./Tests/Packet++Test/PacketExamples,./Tests/Pcap++Test/PcapExamples,./3rdParty,./Examples/PcapSearch/dirent-for-Visual-Studio ignore-words = codespell-ignore-list.txt count = diff --git a/.gersemirc b/.gersemirc new file mode 100644 index 0000000000..5259291f50 --- /dev/null +++ b/.gersemirc @@ -0,0 +1,6 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json + +indent: 2 +line_length: 120 +list_expansion: favour-inlining +warn_about_unknown_commands: false diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 7f96abd31f..43e4027b63 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -34,23 +34,21 @@ jobs: - name: Install dependencies run: | apk update && apk add cppcheck python3-dev - python3 -m pip install cmake-format clang-format==18.1.6 + python3 -m venv .venv + . .venv/bin/activate + python3 -m pip install pre-commit setuptools clang-format==18.1.6 clang-tidy==18.1.8 - # TODO: investigate how to run pre-commit with `venv` - - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - - - name: CMake format + - name: Run pre-commit run: | - ./ci/cmake-format-all.sh - git diff --exit-code + . .venv/bin/activate + pre-commit run --all-files - name: Configure PcapPlusPlus for Static analysis - run: CXX=clang++ CC=clang cmake -DLIGHT_PCAPNG_ZSTD=ON -DPCAPPP_ENABLE_CLANG_TIDY=ON -S . -B "$BUILD_DIR" + run: cmake -S . -B "$BUILD_DIR" - - name: Build PcapPlusPlus and check any diff + - name: Run clang-tidy on changed files run: | - cmake --build "$BUILD_DIR" -j - git diff --exit-code + ./ci/clang-tidy-all.sh changed "$BUILD_DIR" linux: runs-on: ubuntu-latest @@ -111,18 +109,18 @@ jobs: - name: Prepare environment for tests run: | - python3 -m venv ./venv - . ./venv/bin/activate + python3 -m venv .venv + . .venv/bin/activate python3 -m pip install -r ci/run_tests/requirements.txt - name: Test PcapPlusPlus run: | - . ./venv/bin/activate + . .venv/bin/activate python3 ci/run_tests/run_tests.py --interface eth0 ${{ matrix.test-flags }} - name: Test Examples run: | - . ./venv/bin/activate + . .venv/bin/activate cd Tests/ExamplesTest python3 -m pip install -r requirements.txt python3 -m pytest --interface eth0 --root-path=../../Dist/examples_bin @@ -143,7 +141,7 @@ jobs: - name: Create Cobertura Report run: | - . ./venv/bin/activate + . .venv/bin/activate python3 -m pip install gcovr gcovr -v -r . ${{ matrix.additional-gcov-flags }} $GCOVR_FLAGS -o coverage.xml @@ -351,15 +349,15 @@ jobs: - name: Prepare environment for tests run: | - python -m venv ./venv - . ./venv/bin/activate + python -m venv .venv + . .venv/bin/activate python -m pip install -r ci/run_tests/requirements.txt - name: Test PcapPlusPlus # We can't run cross compiled binaries if: ${{ matrix.host-arch == matrix.arch }} run: | - . ./venv/bin/activate + . .venv/bin/activate python ci/run_tests/run_tests.py --interface en0 - name: Test Examples @@ -720,13 +718,13 @@ jobs: - name: Prepare environment for tests run: | - python -m venv ./venv - . ./venv/bin/activate + python -m venv .venv + . .venv/bin/activate python -m pip install -r ci/run_tests/requirements.txt - name: Test PcapPlusPlus run: | - . ./venv/bin/activate + . .venv/bin/activate python ci/run_tests/run_tests.py --interface eth0 --use-sudo --pcap-test-args="-t xdp" - name: Create Cobertura Report diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dba90e8437..c13fc1e55c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,6 +37,10 @@ repos: files: ^(Common\+\+|Packet\+\+|Pcap\+\+|Tests|Examples)/.*\.(cpp|h)$ - id: cppcheck args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force"] + - repo: https://github.com/BlankSpruce/gersemi + rev: 0.15.1 + hooks: + - id: gersemi - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: diff --git a/3rdParty/CMakeLists.txt b/3rdParty/CMakeLists.txt index 223335326a..9af23e6138 100644 --- a/3rdParty/CMakeLists.txt +++ b/3rdParty/CMakeLists.txt @@ -1,6 +1,3 @@ -# Disable Clang-tidy for 3rdParty modules -set(CMAKE_CXX_CLANG_TIDY "") - add_subdirectory(EndianPortable) add_subdirectory(Getopt-for-Visual-Studio) add_subdirectory(hash-library) diff --git a/3rdParty/LightPcapNg/LightPcapNg/cmake/FindZSTD.cmake b/3rdParty/LightPcapNg/LightPcapNg/cmake/FindZSTD.cmake index a4066300a8..2255241312 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/cmake/FindZSTD.cmake +++ b/3rdParty/LightPcapNg/LightPcapNg/cmake/FindZSTD.cmake @@ -37,18 +37,12 @@ This module defines the following variables: set(ZSTD_NAMES zstd zstd_static) set(ZSTD_NAMES_DEBUG zstdd zstd_staticd) -find_path(ZSTD_INCLUDE_DIR - NAMES zstd.h - PATH_SUFFIXES include) +find_path(ZSTD_INCLUDE_DIR NAMES zstd.h PATH_SUFFIXES include) # Allow ZSTD_LIBRARY to be set manually, as the location of the zstd library if(NOT ZSTD_LIBRARY) - find_library(ZSTD_LIBRARY_RELEASE - NAMES ${ZSTD_NAMES} - PATH_SUFFIXES lib) - find_library(ZSTD_LIBRARY_DEBUG - NAMES ${ZSTD_NAMES_DEBUG} - PATH_SUFFIXES lib) + find_library(ZSTD_LIBRARY_RELEASE NAMES ${ZSTD_NAMES} PATH_SUFFIXES lib) + find_library(ZSTD_LIBRARY_DEBUG NAMES ${ZSTD_NAMES_DEBUG} PATH_SUFFIXES lib) include(SelectLibraryConfigurations) select_library_configurations(ZSTD) @@ -60,48 +54,40 @@ unset(ZSTD_NAMES_DEBUG) mark_as_advanced(ZSTD_INCLUDE_DIR) if(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h") - file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_H REGEX "^#define ZSTD_VERSION_.*$") + file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_H REGEX "^#define ZSTD_VERSION_.*$") - string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" "\\1" ZSTD_MAJOR_VERSION "${ZSTD_H}") - string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" "\\1" ZSTD_MINOR_VERSION "${ZSTD_H}") - string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" "\\1" ZSTD_PATCH_VERSION "${ZSTD_H}") - set(ZSTD_VERSION_STRING "${ZSTD_MAJOR_VERSION}.${ZSTD_MINOR_VERSION}.${ZSTD_PATCH_VERSION}") + string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" "\\1" ZSTD_MAJOR_VERSION "${ZSTD_H}") + string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" "\\1" ZSTD_MINOR_VERSION "${ZSTD_H}") + string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" "\\1" ZSTD_PATCH_VERSION "${ZSTD_H}") + set(ZSTD_VERSION_STRING "${ZSTD_MAJOR_VERSION}.${ZSTD_MINOR_VERSION}.${ZSTD_PATCH_VERSION}") endif() include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD - REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR - VERSION_VAR ZSTD_VERSION_STRING) +find_package_handle_standard_args(ZSTD REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR VERSION_VAR ZSTD_VERSION_STRING) if(ZSTD_FOUND) - set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR}) + set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR}) - if(NOT ZSTD_LIBRARIES) - set(ZSTD_LIBRARIES ${ZSTD_LIBRARY}) + if(NOT ZSTD_LIBRARIES) + set(ZSTD_LIBRARIES ${ZSTD_LIBRARY}) + endif() + + if(NOT TARGET ZSTD::ZSTD) + add_library(ZSTD::ZSTD UNKNOWN IMPORTED) + set_target_properties(ZSTD::ZSTD PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}") + + if(ZSTD_LIBRARY_RELEASE) + set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}") + endif() + + if(ZSTD_LIBRARY_DEBUG) + set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}") endif() - if(NOT TARGET ZSTD::ZSTD) - add_library(ZSTD::ZSTD UNKNOWN IMPORTED) - set_target_properties(ZSTD::ZSTD PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}") - - if(ZSTD_LIBRARY_RELEASE) - set_property(TARGET ZSTD::ZSTD APPEND PROPERTY - IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(ZSTD::ZSTD PROPERTIES - IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}") - endif() - - if(ZSTD_LIBRARY_DEBUG) - set_property(TARGET ZSTD::ZSTD APPEND PROPERTY - IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(ZSTD::ZSTD PROPERTIES - IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}") - endif() - - if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG) - set_target_properties(ZSTD::ZSTD PROPERTIES - IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY}") - endif() + if(NOT ZSTD_LIBRARY_RELEASE AND NOT ZSTD_LIBRARY_DEBUG) + set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY}") endif() + endif() endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 06c257cac1..2403dc5bca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,8 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS ON) # Set Position Independent Code for static libraries set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Export compile commands for external tools +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Usually on Windows PCAP_ROOT and Packet_ROOT are at the same location if(WIN32 @@ -171,17 +173,6 @@ if(PCAPPP_ENABLE_PCAP_SET_DIRECTION) add_definitions(-DHAS_SET_DIRECTION_ENABLED) endif() -option(PCAPPP_ENABLE_CLANG_TIDY "Run Clang-Tidy static analysis during build" OFF) - -if(PCAPPP_ENABLE_CLANG_TIDY) - find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED) - set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" - "--checks=modernize-use-nullptr,modernize-use-override,performance-unnecessary-value-param") - set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND}) - # Force to recompile all files with clang-tidy by setting a dummy definition variable - add_definitions(-DUSE_CLANG_TIDY) -endif() - set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) if(MSVC) diff --git a/ci/clang-tidy-all.sh b/ci/clang-tidy-all.sh new file mode 100755 index 0000000000..7c19ab3644 --- /dev/null +++ b/ci/clang-tidy-all.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +SCRIPT=$(readlink -f "$0") +SCRIPTPATH=$(dirname "${SCRIPT}") +ROOTPATH=$(realpath "${SCRIPTPATH}"/..) +if ! command -v clang-tidy; then + echo "clang-tidy is not found!" + exit 1 +fi + +# Determine the mode (all files or changed files) +MODE=${1:-all} +BUILD_DIR=${2:-build} + +if [ "$MODE" = "changed" ]; then + # Get the list of changed files from origin/dev + git fetch origin dev + files=$(git diff --name-only origin/dev -- '*.cpp' '*.h' | grep -v '3rdParty/' || true) +else + # Find all relevant files + files=$(find "${ROOTPATH}" -type f \( -name '*.cpp' -o -name '*.h' \) -not -path "*/3rdParty/*") +fi + +# Check if there are any files to process +if [ -z "$files" ]; then + echo "No files to process." + exit 0 +fi + +# Process each file +echo "$files" | while IFS= read -r file; do + echo "Checking: $file" + clang-tidy "$file" -p $BUILD_DIR --fix --checks=modernize-use-nullptr,modernize-use-override,performance-unnecessary-value-param +done diff --git a/ci/cmake-format-all.sh b/ci/cmake-format-all.sh deleted file mode 100755 index 94a30393d6..0000000000 --- a/ci/cmake-format-all.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -set -e - -SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "${SCRIPT}") -ROOTPATH=$(realpath "${SCRIPTPATH}"/..) -if ! command -v cmake-format; then - echo "cmake-format is not found!" - exit 1 -fi - -find "${ROOTPATH}" -type f \( -name '*.cmake' -o -name 'CMakeLists.txt' \) -not -path "*/3rdParty/*" -exec echo 'Formatting:' {} ';' -exec cmake-format -i {} ';' diff --git a/cmake/modules/FindBPF.cmake b/cmake/modules/FindBPF.cmake index 80daedc211..d50bb1bfb1 100644 --- a/cmake/modules/FindBPF.cmake +++ b/cmake/modules/FindBPF.cmake @@ -11,25 +11,22 @@ find_package(PkgConfig QUIET) pkg_check_modules(PC_LIBBPF libbpf) -find_path( - BPF_INCLUDE_DIRS - NAMES bpf/bpf.h - HINTS ${PC_LIBBPF_INCLUDE_DIRS}) +find_path(BPF_INCLUDE_DIRS NAMES bpf/bpf.h HINTS ${PC_LIBBPF_INCLUDE_DIRS}) -find_library( - BPF_LIBRARIES - NAMES bpf - HINTS ${PC_LIBBPF_LIBRARY_DIRS}) +find_library(BPF_LIBRARIES NAMES bpf HINTS ${PC_LIBBPF_LIBRARY_DIRS}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( BPF REQUIRED_VARS BPF_LIBRARIES BPF_INCLUDE_DIRS VERSION_VAR BPF_VERSION - FAIL_MESSAGE "libbpf not found!") + FAIL_MESSAGE "libbpf not found!" +) if(BPF_FOUND AND NOT TARGET BPF::BPF) add_library(BPF::BPF INTERFACE IMPORTED) - set_target_properties(BPF::BPF PROPERTIES INTERFACE_LINK_LIBRARIES "${BPF_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES - "${BPF_INCLUDE_DIRS}") + set_target_properties( + BPF::BPF + PROPERTIES INTERFACE_LINK_LIBRARIES "${BPF_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${BPF_INCLUDE_DIRS}" + ) endif() diff --git a/cmake/modules/FindDPDK.cmake b/cmake/modules/FindDPDK.cmake index 48f9814f32..b67b6880a5 100644 --- a/cmake/modules/FindDPDK.cmake +++ b/cmake/modules/FindDPDK.cmake @@ -18,40 +18,22 @@ function(DPDK_READ_VERSION DPDK_VERSION DPDK_VERSION_FILE) endif() file(READ "${DPDK_VERSION_FILE}" DPDK_VERSION_STR) - string( - REGEX MATCH - "#define RTE_VER_YEAR ([0-9]+)" - _ - ${DPDK_VERSION_STR}) + string(REGEX MATCH "#define RTE_VER_YEAR ([0-9]+)" _ ${DPDK_VERSION_STR}) set(DPDK_VERSION_MAJOR ${CMAKE_MATCH_1}) - string( - REGEX MATCH - "#define RTE_VER_MONTH ([0-9]+)" - _ - ${DPDK_VERSION_STR}) + string(REGEX MATCH "#define RTE_VER_MONTH ([0-9]+)" _ ${DPDK_VERSION_STR}) set(DPDK_VERSION_MINOR ${CMAKE_MATCH_1}) - string( - REGEX MATCH - "#define RTE_VER_MINOR ([0-9]+)" - _ - ${DPDK_VERSION_STR}) + string(REGEX MATCH "#define RTE_VER_MINOR ([0-9]+)" _ ${DPDK_VERSION_STR}) set(DPDK_VERSION_PATCH ${CMAKE_MATCH_1}) - set(DPDK_VERSION - "${DPDK_VERSION_MAJOR}.${DPDK_VERSION_MINOR}.${DPDK_VERSION_PATCH}" - PARENT_SCOPE) + set(DPDK_VERSION "${DPDK_VERSION_MAJOR}.${DPDK_VERSION_MINOR}.${DPDK_VERSION_PATCH}" PARENT_SCOPE) endfunction() # Try to find DPDK with pkg-config first! find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) - pkg_check_modules( - DPDK - QUIET - IMPORTED_TARGET - libdpdk>=18.11) + pkg_check_modules(DPDK QUIET IMPORTED_TARGET libdpdk>=18.11) endif() # We found using Pkg-Config! @@ -110,7 +92,8 @@ else() pci bus_pci bus_vdev - mempool_ring) + mempool_ring + ) if(DPDK_VERSION VERSION_LESS "20.11") list( @@ -125,18 +108,14 @@ else() pmd_ixgbe pmd_e1000 pmd_ring - pmd_af_packet) + pmd_af_packet + ) endif() # Check that all libraries exists foreach(lib ${_DPDK_LOOK_FOR_LIBS}) # Regarding the build system used make or meson the librte_pmd_vmxnet3 could be named librte_pmd_vmxnet3_uio - find_library( - rte_${lib} - NAMES rte_${lib} - rte_${lib}_uio - NAMES_PER_DIR - REQUIRED) + find_library(rte_${lib} NAMES rte_${lib} rte_${lib}_uio NAMES_PER_DIR REQUIRED) list(APPEND DPDK_LIBRARIES ${rte_${lib}}) get_filename_component(_DPDK_LIBRARY_DIR ${rte_${lib}} PATH) @@ -175,19 +154,18 @@ else() endif() endif() -find_package_handle_standard_args( - DPDK - REQUIRED_VARS DPDK_INCLUDE_DIRS DPDK_LIBRARIES - VERSION_VAR DPDK_VERSION) +find_package_handle_standard_args(DPDK REQUIRED_VARS DPDK_INCLUDE_DIRS DPDK_LIBRARIES VERSION_VAR DPDK_VERSION) if(NOT TARGET DPDK::DPDK) add_library(DPDK::DPDK INTERFACE IMPORTED) find_package(Threads QUIET) set_target_properties( DPDK::DPDK - PROPERTIES INTERFACE_LINK_LIBRARIES "${DPDK_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${DPDK_INCLUDE_DIRS}" - INTERFACE_COMPILE_OPTIONS "${DPDK_CFLAGS_OTHER}") + PROPERTIES + INTERFACE_LINK_LIBRARIES "${DPDK_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${DPDK_INCLUDE_DIRS}" + INTERFACE_COMPILE_OPTIONS "${DPDK_CFLAGS_OTHER}" + ) # At this steps DPDK is found check if KNI is supported include(CheckIncludeFiles) @@ -196,6 +174,8 @@ endif() if(DPDK_DEBUG) include(CMakePrintHelpers) - cmake_print_properties(TARGETS DPDK::DPDK PROPERTIES INTERFACE_LINK_LIBRARIES INTERFACE_COMPILE_OPTIONS - INTERFACE_INCLUDE_DIRECTORIES) + cmake_print_properties( + TARGETS DPDK::DPDK + PROPERTIES INTERFACE_LINK_LIBRARIES INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES + ) endif() diff --git a/cmake/modules/FindNUMA.cmake b/cmake/modules/FindNUMA.cmake index c100212381..5ceaf6cc1b 100644 --- a/cmake/modules/FindNUMA.cmake +++ b/cmake/modules/FindNUMA.cmake @@ -16,10 +16,7 @@ find_library(NUMA_LIBRARY numa) find_path(NUMA_INCLUDE_DIR numa.h) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - NUMA - REQUIRED_VARS NUMA_INCLUDE_DIR NUMA_LIBRARY - FAIL_MESSAGE "NUMA not found!") +find_package_handle_standard_args(NUMA REQUIRED_VARS NUMA_INCLUDE_DIR NUMA_LIBRARY FAIL_MESSAGE "NUMA not found!") if(NUMA_FOUND AND NOT TARGET NUMA::NUMA) add_library(NUMA::NUMA INTERFACE IMPORTED) diff --git a/cmake/modules/FindPCAP.cmake b/cmake/modules/FindPCAP.cmake index 9d65a37953..b4b08f4104 100644 --- a/cmake/modules/FindPCAP.cmake +++ b/cmake/modules/FindPCAP.cmake @@ -30,10 +30,7 @@ # -DPCAP_ROOT=C:\path\to\packet [...]) # ~~~ -find_path( - PCAP_INCLUDE_DIR - NAMES pcap/pcap.h pcap.h - PATH_SUFFIXES include Include) +find_path(PCAP_INCLUDE_DIR NAMES pcap/pcap.h pcap.h PATH_SUFFIXES include Include) # The 64-bit Wpcap.lib is located under /x64 if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -70,9 +67,7 @@ if(NOT PCAP_LINKS_SOLO) if(THREADS_FOUND AND PCAP_NEEDS_THREADS) set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) list(REMOVE_DUPLICATES _tmp) - set(PCAP_LIBRARY - ${_tmp} - CACHE STRING "Libraries needed to link against libpcap" FORCE) + set(PCAP_LIBRARY ${_tmp} CACHE STRING "Libraries needed to link against libpcap" FORCE) else(THREADS_FOUND AND PCAP_NEEDS_THREADS) message(FATAL_ERROR "Couldn't determine how to link against libpcap") endif(THREADS_FOUND AND PCAP_NEEDS_THREADS) @@ -88,8 +83,9 @@ set(CMAKE_REQUIRED_LIBRARIES) # Check libPCAP version if(HAVE_PCAP_LIB_VERSION AND NOT CMAKE_CROSSCOMPILING) # Simple C code to extract the libpcap version - set(PCAP_VERSION_CODE - " + set( + PCAP_VERSION_CODE + " #include #include #include @@ -103,7 +99,8 @@ if(HAVE_PCAP_LIB_VERSION AND NOT CMAKE_CROSSCOMPILING) printf(\"%s\", version); return 0; } - ") + " + ) # Write the code to a temporary file set(detect_pcap_version_file "${PROJECT_BINARY_DIR}/detect_pcap_version.cpp") @@ -115,8 +112,10 @@ if(HAVE_PCAP_LIB_VERSION AND NOT CMAKE_CROSSCOMPILING) COMPILE_RESULT_VAR "${CMAKE_BINARY_DIR}" "${detect_pcap_version_file}" - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PCAP_INCLUDE_DIR}" LINK_LIBRARIES ${PCAP_LIBRARY} - RUN_OUTPUT_VARIABLE PCAP_VERSION_OUTPUT) + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PCAP_INCLUDE_DIR}" + LINK_LIBRARIES ${PCAP_LIBRARY} + RUN_OUTPUT_VARIABLE PCAP_VERSION_OUTPUT + ) # If successful, parse the output to get the version string if(COMPILE_RESULT_VAR AND RUN_RESULT_VAR EQUAL 0) @@ -125,19 +124,18 @@ if(HAVE_PCAP_LIB_VERSION AND NOT CMAKE_CROSSCOMPILING) endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - PCAP - REQUIRED_VARS PCAP_LIBRARY PCAP_INCLUDE_DIR - VERSION_VAR PCAP_VERSION) +find_package_handle_standard_args(PCAP REQUIRED_VARS PCAP_LIBRARY PCAP_INCLUDE_DIR VERSION_VAR PCAP_VERSION) # create IMPORTED target for libpcap dependency if(NOT TARGET PCAP::PCAP) add_library(PCAP::PCAP IMPORTED SHARED) set_target_properties( PCAP::PCAP - PROPERTIES IMPORTED_LOCATION ${PCAP_LIBRARY} - IMPORTED_IMPLIB ${PCAP_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${PCAP_INCLUDE_DIR}) + PROPERTIES + IMPORTED_LOCATION ${PCAP_LIBRARY} + IMPORTED_IMPLIB ${PCAP_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${PCAP_INCLUDE_DIR} + ) endif() mark_as_advanced(PCAP_INCLUDE_DIR PCAP_LIBRARY) diff --git a/cmake/modules/FindPF_RING.cmake b/cmake/modules/FindPF_RING.cmake index 5f98c128af..1a5c1abb9b 100644 --- a/cmake/modules/FindPF_RING.cmake +++ b/cmake/modules/FindPF_RING.cmake @@ -23,7 +23,8 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args( PF_RING REQUIRED_VARS PF_RING_LIBRARIES PF_RING_KERNEL_INCLUDE_DIR PF_RING_USER_INCLUDE_DIR - FAIL_MESSAGE "PF_RING not found! Please specify PF_RING_ROOT.") + FAIL_MESSAGE "PF_RING not found! Please specify PF_RING_ROOT." +) set(PF_RING_LIBRARIES ${PF_RING_LIBRARIES} ${CMAKE_DL_LIBS}) diff --git a/cmake/modules/FindPacket.cmake b/cmake/modules/FindPacket.cmake index a1740e9bbf..ab3ef9c67b 100644 --- a/cmake/modules/FindPacket.cmake +++ b/cmake/modules/FindPacket.cmake @@ -65,20 +65,18 @@ find_library(Packet_LIBRARY NAMES Packet packet NAMES_PER_DIR) # Set Packet_FOUND to TRUE if Packet_INCLUDE_DIR and Packet_LIBRARY are TRUE. include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - Packet - DEFAULT_MSG - Packet_LIBRARY - Packet_INCLUDE_DIR) +find_package_handle_standard_args(Packet DEFAULT_MSG Packet_LIBRARY Packet_INCLUDE_DIR) # create IMPORTED target for libpcap dependency if(NOT TARGET Packet::Packet) add_library(Packet::Packet IMPORTED SHARED) set_target_properties( Packet::Packet - PROPERTIES IMPORTED_LOCATION ${Packet_LIBRARY} - IMPORTED_IMPLIB ${Packet_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${Packet_INCLUDE_DIR}) + PROPERTIES + IMPORTED_LOCATION ${Packet_LIBRARY} + IMPORTED_IMPLIB ${Packet_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${Packet_INCLUDE_DIR} + ) endif() mark_as_advanced(Packet_INCLUDE_DIR Packet_LIBRARY) diff --git a/cmake/modules/FindZSTD.cmake b/cmake/modules/FindZSTD.cmake index a1a005124e..a3216bb138 100644 --- a/cmake/modules/FindZSTD.cmake +++ b/cmake/modules/FindZSTD.cmake @@ -37,21 +37,12 @@ This module defines the following variables: set(ZSTD_NAMES zstd zstd_static) set(ZSTD_NAMES_DEBUG zstdd zstd_staticd) -find_path( - ZSTD_INCLUDE_DIR - NAMES zstd.h - PATH_SUFFIXES include) +find_path(ZSTD_INCLUDE_DIR NAMES zstd.h PATH_SUFFIXES include) # Allow ZSTD_LIBRARY to be set manually, as the location of the zstd library if(NOT ZSTD_LIBRARY) - find_library( - ZSTD_LIBRARY_RELEASE - NAMES ${ZSTD_NAMES} - PATH_SUFFIXES lib) - find_library( - ZSTD_LIBRARY_DEBUG - NAMES ${ZSTD_NAMES_DEBUG} - PATH_SUFFIXES lib) + find_library(ZSTD_LIBRARY_RELEASE NAMES ${ZSTD_NAMES} PATH_SUFFIXES lib) + find_library(ZSTD_LIBRARY_DEBUG NAMES ${ZSTD_NAMES_DEBUG} PATH_SUFFIXES lib) include(SelectLibraryConfigurations) select_library_configurations(ZSTD) @@ -65,32 +56,14 @@ mark_as_advanced(ZSTD_INCLUDE_DIR) if(ZSTD_INCLUDE_DIR AND EXISTS "${ZSTD_INCLUDE_DIR}/zstd.h") file(STRINGS "${ZSTD_INCLUDE_DIR}/zstd.h" ZSTD_H REGEX "^#define ZSTD_VERSION_.*$") - string( - REGEX - REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" - "\\1" - ZSTD_MAJOR_VERSION - "${ZSTD_H}") - string( - REGEX - REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" - "\\1" - ZSTD_MINOR_VERSION - "${ZSTD_H}") - string( - REGEX - REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" - "\\1" - ZSTD_PATCH_VERSION - "${ZSTD_H}") + string(REGEX REPLACE "^.*ZSTD_VERSION_MAJOR *([0-9]+).*$" "\\1" ZSTD_MAJOR_VERSION "${ZSTD_H}") + string(REGEX REPLACE "^.*ZSTD_VERSION_MINOR *([0-9]+).*$" "\\1" ZSTD_MINOR_VERSION "${ZSTD_H}") + string(REGEX REPLACE "^.*ZSTD_VERSION_RELEASE *([0-9]+).*$" "\\1" ZSTD_PATCH_VERSION "${ZSTD_H}") set(ZSTD_VERSION_STRING "${ZSTD_MAJOR_VERSION}.${ZSTD_MINOR_VERSION}.${ZSTD_PATCH_VERSION}") endif() include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - ZSTD - REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR - VERSION_VAR ZSTD_VERSION_STRING) +find_package_handle_standard_args(ZSTD REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR VERSION_VAR ZSTD_VERSION_STRING) if(ZSTD_FOUND) set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR}) @@ -104,18 +77,12 @@ if(ZSTD_FOUND) set_target_properties(ZSTD::ZSTD PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}") if(ZSTD_LIBRARY_RELEASE) - set_property( - TARGET ZSTD::ZSTD - APPEND - PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_RELEASE "${ZSTD_LIBRARY_RELEASE}") endif() if(ZSTD_LIBRARY_DEBUG) - set_property( - TARGET ZSTD::ZSTD - APPEND - PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION_DEBUG "${ZSTD_LIBRARY_DEBUG}") endif() diff --git a/cmake/modules/PcapPlusPlusUtils.cmake b/cmake/modules/PcapPlusPlusUtils.cmake index 0298ff90ad..f88ae1b95c 100644 --- a/cmake/modules/PcapPlusPlusUtils.cmake +++ b/cmake/modules/PcapPlusPlusUtils.cmake @@ -1,92 +1,55 @@ function(pcapp_detect_compiler TARGET) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - set(${TARGET}_COMPILER_MSVC - 1 - PARENT_SCOPE) - set(${TARGET}_COMPILER - "msvc" - PARENT_SCOPE) + set(${TARGET}_COMPILER_MSVC 1 PARENT_SCOPE) + set(${TARGET}_COMPILER "msvc" PARENT_SCOPE) if(MSVC_TOOLSET_VERSION EQUAL 80) - set(MSVC_YEAR - "2005" - PARENT_SCOPE) + set(MSVC_YEAR "2005" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 90) - set(MSVC_YEAR - "2008" - PARENT_SCOPE) + set(MSVC_YEAR "2008" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 100) - set(MSVC_YEAR - "2010" - PARENT_SCOPE) + set(MSVC_YEAR "2010" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 110) - set(MSVC_YEAR - "2012" - PARENT_SCOPE) + set(MSVC_YEAR "2012" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 120) - set(MSVC_YEAR - "2013" - PARENT_SCOPE) + set(MSVC_YEAR "2013" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 140) - set(MSVC_YEAR - "2015" - PARENT_SCOPE) + set(MSVC_YEAR "2015" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 141) - set(MSVC_YEAR - "2017" - PARENT_SCOPE) + set(MSVC_YEAR "2017" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 142) - set(MSVC_YEAR - "2019" - PARENT_SCOPE) + set(MSVC_YEAR "2019" PARENT_SCOPE) elseif(MSVC_TOOLSET_VERSION EQUAL 143) - set(MSVC_YEAR - "2022" - PARENT_SCOPE) + set(MSVC_YEAR "2022" PARENT_SCOPE) else() message(WARNING "Unsupported MSVC_TOOLSET_VERSION: ${MSVC_TOOLSET_VERSION}") - set(MSVC_YEAR - "2099" - PARENT_SCOPE) + set(MSVC_YEAR "2099" PARENT_SCOPE) endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") - set(${TARGET}_COMPILER_CLANG - 1 - PARENT_SCOPE) - set(${TARGET}_COMPILER - "xcode" - PARENT_SCOPE) + set(${TARGET}_COMPILER_CLANG 1 PARENT_SCOPE) + set(${TARGET}_COMPILER "xcode" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(${TARGET}_COMPILER_CLANG - 1 - PARENT_SCOPE) - set(${TARGET}_COMPILER - "clang" - PARENT_SCOPE) + set(${TARGET}_COMPILER_CLANG 1 PARENT_SCOPE) + set(${TARGET}_COMPILER "clang" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - set(${TARGET}_COMPILER_GCC - 1 - PARENT_SCOPE) - set(${TARGET}_COMPILER - "gcc" - PARENT_SCOPE) + set(${TARGET}_COMPILER_GCC 1 PARENT_SCOPE) + set(${TARGET}_COMPILER "gcc" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel") - set(${TARGET}_COMPILER_INTEL - 1 - PARENT_SCOPE) - set(${TARGET}_COMPILER - "intel" - PARENT_SCOPE) + set(${TARGET}_COMPILER_INTEL 1 PARENT_SCOPE) + set(${TARGET}_COMPILER "intel" PARENT_SCOPE) else() message(FATAL_ERROR "Unsupported Compiler: ${CMAKE_CXX_COMPILER_ID}") endif() endfunction() function(pcapp_install_cmake_module MODULE) - set(_PCAPPP_CONFIG_DEPENDENCY - "${_PCAPPP_CONFIG_DEPENDENCY}if(NOT ${MODULE}_FOUND)\nfind_dependency(${MODULE})\nendif()\n" - PARENT_SCOPE) + set( + _PCAPPP_CONFIG_DEPENDENCY + "${_PCAPPP_CONFIG_DEPENDENCY}if(NOT ${MODULE}_FOUND)\nfind_dependency(${MODULE})\nendif()\n" + PARENT_SCOPE + ) install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/Find${MODULE}.cmake" COMPONENT devel - DESTINATION "${PCAPPP_INSTALL_CMAKEDIR}") + DESTINATION "${PCAPPP_INSTALL_CMAKEDIR}" + ) endfunction() diff --git a/cmake/modules/TargetArch.cmake b/cmake/modules/TargetArch.cmake index f6af13ec73..3ec9df0275 100644 --- a/cmake/modules/TargetArch.cmake +++ b/cmake/modules/TargetArch.cmake @@ -2,8 +2,9 @@ # https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h Currently handles arm (v5, # v6, v7), x86 (32/64), ia64, and ppc (32/64) -set(archdetect_c_code - " +set( + archdetect_c_code + " #if defined(__arm__) || defined(__TARGET_ARCH_ARM) #if defined(__ARM_ARCH_7__) \\ || defined(__ARM_ARCH_7A__) \\ @@ -43,7 +44,8 @@ set(archdetect_c_code #endif #error cmake_ARCH unknown -") +" +) # Set ppc_support to TRUE before including this file or ppc and ppc64 will be treated as invalid architectures since # they are no longer supported by Apple @@ -65,21 +67,14 @@ function(target_architecture output_var) "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/arch.c" COMPILE_OUTPUT_VARIABLE ARCH - CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}) + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + ) # Parse the architecture name from the compiler output - string( - REGEX MATCH - "cmake_ARCH ([a-zA-Z0-9_]+)" - ARCH - "${ARCH}") + string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") # Get rid of the value marker leaving just the architecture name - string( - REPLACE "cmake_ARCH " - "" - ARCH - "${ARCH}") + string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") # If we are compiling with an unknown architecture this variable should already be set to "unknown" but in the case # that it's empty (i.e. due to a typo in the code), then set it to unknown @@ -87,7 +82,5 @@ function(target_architecture output_var) set(ARCH unknown) endif() - set(${output_var} - "${ARCH}" - PARENT_SCOPE) + set(${output_var} "${ARCH}" PARENT_SCOPE) endfunction()