+ #
+ # Now get the include directories.
+ #
+ execute_process(COMMAND "${PCAP_CONFIG}" "--cflags"
+ RESULT_VARIABLE PCAP_CONFIG_RESULT
+ OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT PCAP_CONFIG_RESULT EQUAL 0)
+ message(FATAL_ERROR "pcap-config --cflags failed")
+ endif()
+ separate_arguments(CFLAGS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
+ set(CONFIG_PCAP_INCLUDE_DIRS "")
+ foreach(_arg IN LISTS CFLAGS_LIST)
+ if(_arg MATCHES "^-I")
+ #
+ # Extract the directory by removing the -I.
+ #
+ string(REGEX REPLACE "-I" "" _dir ${_arg})
+ #
+ # Work around macOS (and probably other Darwin) brokenness,
+ # by not adding /usr/local/include if it's from the broken
+ # Apple pcap-config.
+ #
+ if(NOT _broken_apple_pcap_config OR
+ NOT "${_dir}" STREQUAL /usr/local/include)
+ # Add it to CONFIG_PCAP_INCLUDE_DIRS
+ list(APPEND CONFIG_PCAP_INCLUDE_DIRS ${_dir})
+ endif()
+ endif()
+ endforeach()
+
+ #
+ # Now, get the library directories and libraries for dynamic linking.
+ #
+ execute_process(COMMAND "${PCAP_CONFIG}" "--libs"
+ RESULT_VARIABLE PCAP_CONFIG_RESULT
+ OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT PCAP_CONFIG_RESULT EQUAL 0)
+ message(FATAL_ERROR "pcap-config --libs failed")
+ endif()
+ separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
+ set(CONFIG_PCAP_LIBRARY_DIRS "")
+ set(CONFIG_PCAP_LIBRARIES "")
+ foreach(_arg IN LISTS LIBS_LIST)
+ if(_arg MATCHES "^-L")
+ #
+ # Extract the directory by removing the -L.
+ #
+ string(REGEX REPLACE "-L" "" _dir ${_arg})
+ #
+ # Work around macOS (and probably other Darwin) brokenness,
+ # by not adding /usr/local/lib if it's from the broken
+ # Apple pcap-config.
+ #
+ if(NOT _broken_apple_pcap_config OR
+ NOT "${_dir}" STREQUAL /usr/local/lib)
+ # Add this directory to CONFIG_PCAP_LIBRARY_DIRS
+ list(APPEND CONFIG_PCAP_LIBRARY_DIRS ${_dir})
+ endif()
+ elseif(_arg MATCHES "^-l")
+ string(REGEX REPLACE "-l" "" _lib ${_arg})
+ list(APPEND CONFIG_PCAP_LIBRARIES ${_lib})
+ endif()
+ endforeach()
+
+ #
+ # Now, get the library directories and libraries for static linking.
+ #
+ execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static"
+ RESULT_VARIABLE PCAP_CONFIG_RESULT
+ OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
+ )
+ if(NOT PCAP_CONFIG_RESULT EQUAL 0)
+ message(FATAL_ERROR "pcap-config --libs --static failed")
+ endif()
+ separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
+ set(CONFIG_PCAP_STATIC_LIBRARY_DIRS "")
+ set(CONFIG_PCAP_STATIC_LIBRARIES "")
+ foreach(_arg IN LISTS LIBS_LIST)
+ if(_arg MATCHES "^-L")
+ #
+ # Extract the directory by removing the -L.
+ #
+ string(REGEX REPLACE "-L" "" _dir ${_arg})
+ #
+ # Work around macOS (and probably other Darwin) brokenness,
+ # by not adding /usr/local/lib if it's from the broken
+ # Apple pcap-config.
+ #
+ if(NOT _broken_apple_pcap_config OR
+ NOT "${_dir}" STREQUAL /usr/local/lib)
+ # Add this directory to CONFIG_PCAP_STATIC_LIBRARY_DIRS
+ list(APPEND CONFIG_PCAP_STATIC_LIBRARY_DIRS ${_dir})
+ endif()
+ elseif(_arg MATCHES "^-l")
+ string(REGEX REPLACE "-l" "" _lib ${_arg})
+ #
+ # Try to find that library, so we get its full path, as
+ # we do with dynamic libraries.
+ #
+ list(APPEND CONFIG_PCAP_STATIC_LIBRARIES ${_lib})
+ endif()
+ endforeach()
+
+ #
+ # We've set CONFIG_PCAP_INCLUDE_DIRS, CONFIG_PCAP_LIBRARIES, and
+ # CONFIG_PCAP_STATIC_LIBRARIES above; set CONFIG_PCAP_FOUND.
+ #
+ set(CONFIG_PCAP_FOUND YES)