5 find_program(PCAP_CONFIG pcap-config)
7 # We have pcap-config; use it.
8 # First, get the include directory.
9 execute_process(COMMAND "${PCAP_CONFIG}" "--cflags"
10 RESULT_VARIABLE PCAP_CONFIG_RESULT
11 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
12 OUTPUT_STRIP_TRAILING_WHITESPACE
14 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
15 message(FATAL_ERROR "pcap-config --cflags failed")
17 string(REGEX REPLACE "-I" "" PCAP_INCLUDE_DIR ${PCAP_CONFIG_OUTPUT})
19 # Now, get the libraries.
20 execute_process(COMMAND "${PCAP_CONFIG}" "--libs"
21 RESULT_VARIABLE PCAP_CONFIG_RESULT
22 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
23 OUTPUT_STRIP_TRAILING_WHITESPACE
25 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
26 message(FATAL_ERROR "pcap-config --libs failed")
28 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
29 set(_pcap_library_dirs)
31 foreach(_arg IN LISTS LIBS_LIST)
32 if(_arg MATCHES "^-L")
33 # Add this directory to _pcap_library_dirs
34 string(REGEX REPLACE "-L" "" _dir ${_arg})
35 list(APPEND _pcap_library_dirs ${_dir})
36 elseif(_arg MATCHES "^-l")
37 string(REGEX REPLACE "-l" "" _lib ${_arg})
39 # Try to find that library, so we get its full path.
40 # CMake *really* doesn't like the notion of specifying "here are
41 # the directories in which to look for libraries" except in
42 # find_library() calls; it *really* prefers using full paths to
43 # library files, rather than library names.
45 find_library(_libfullpath ${_lib} HINTS ${__pcap_library_dirs})
46 list(APPEND PCAP_LIBRARIES ${_libfullpath})
50 # Now, get the library directories and libraries for static linking.
51 execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static"
52 RESULT_VARIABLE PCAP_CONFIG_RESULT
53 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
55 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
56 message(FATAL_ERROR "pcap-config --libs --static failed")
58 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
59 set(_pcap_static_library_dirs)
60 set(PCAP_STATIC_LIBRARIES)
61 foreach(_arg IN LISTS LIBS_LIST)
62 if(_arg MATCHES "^-L")
63 # Add this directory to _pcap_static_library_dirs
64 string(REGEX REPLACE "-L" "" _dir ${_arg})
65 list(APPEND _pcap_static_library_dirs ${_dir})
66 elseif(_arg MATCHES "^-l")
67 string(REGEX REPLACE "-l" "" _lib ${_arg})
69 # Try to find that library, so we get its full path, as
70 # we do with dynamic libraries.
72 find_library(_libfullpath ${_lib} HINTS ${__pcap_static_library_dirs})
73 list(APPEND PCAP_STATIC_LIBRARIES ${_libfullpath})
77 # Try to find the header
78 find_path(PCAP_INCLUDE_DIR pcap.h HINTS ${PCAP_INCLUDE_DIRS})
80 # Try to find the library
81 find_library(PCAP_LIBRARY pcap HINTS ${_pcap_library_dirs})
83 # Try to find the static library (XXX - what about AIX?)
84 include(CMakePushCheckState)
85 cmake_push_check_state()
86 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
87 find_library(PCAP_STATIC_LIBRARY pcap HINTS ${_pcap_static_library_dirs})
88 cmake_pop_check_state()
90 # Try to find the header
91 find_path(PCAP_INCLUDE_DIR pcap.h)
93 # Try to find the library
94 find_library(PCAP_LIBRARY pcap)
96 # Try to find the static library (XXX - what about AIX?)
97 include(CMakePushCheckState)
98 cmake_push_check_state()
99 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
100 find_library(PCAP_STATIC_LIBRARY pcap)
101 cmake_pop_check_state()
103 set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
104 set(PCAP_LIBRARIES ${PCAP_LIBRARY})
105 set(PCAP_STATIC_LIBRARIES ${PCAP_STATIC_LIBRARY})
108 include(FindPackageHandleStandardArgs)
109 find_package_handle_standard_args(PCAP