From 3d13d3a0e5d75f8a6688d7f71844995d15759b1d Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 9 Apr 2024 12:50:00 -0700 Subject: [PATCH] Make sure that vcpkg isn't preferred if pcap_root_dir is passed in --- FindPCAP.cmake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/FindPCAP.cmake b/FindPCAP.cmake index 6a14636..5e9385a 100644 --- a/FindPCAP.cmake +++ b/FindPCAP.cmake @@ -21,7 +21,18 @@ find_path(PCAP_ROOT_DIR NAMES include/pcap.h Include/pcap.h) -find_path(PCAP_INCLUDE_DIR NAMES pcap.h HINTS ${PCAP_ROOT_DIR}/include) +# If this is MSVC and a different root path was provided to cmake, add the vcpkg paths to +# the list of ignored paths for the rest of this file. This prevents cmake from preferring +# vcpkg over the path requested. +set(_old_cmake_ignore_path ${CMAKE_IGNORE_PATH}) +string(FIND "${PCAP_ROOT_DIR}" "vcpkg" _is_vcpkg_root) +if (MSVC AND _is_vcpkg_root LESS 0) + set(CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include) + list(APPEND CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib) + list(APPEND CMAKE_IGNORE_PATH ${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib) +endif () + +find_path(PCAP_INCLUDE_DIR NAMES pcap.h HINTS ${PCAP_ROOT_DIR}/include ${PCAP_ROOT_DIR}/Include) if (MSVC AND COMPILER_ARCHITECTURE STREQUAL "x86_64") set(_pcap_lib_hint_path ${PCAP_ROOT_DIR}/lib/x64) @@ -72,3 +83,4 @@ check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND) set(CMAKE_REQUIRED_LIBRARIES) mark_as_advanced(PCAP_ROOT_DIR PCAP_INCLUDE_DIR PCAP_LIBRARY) +set(CMAKE_IGNORE_PATH ${_old_cmake_ignore_path})