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")
18 # XXX - this assumes that there's only one -I flag in the output
19 # of pcap-config --cflags. That *should* be the case.
21 string(REGEX REPLACE "-I" "" PCAP_INCLUDE_DIRS ${PCAP_CONFIG_OUTPUT})
22 set(PCAP_INCLUDE_DIR ${PCAP_INCLUDE_DIRS})
24 # Now, get the libraries.
25 execute_process(COMMAND "${PCAP_CONFIG}" "--libs"
26 RESULT_VARIABLE PCAP_CONFIG_RESULT
27 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
28 OUTPUT_STRIP_TRAILING_WHITESPACE
30 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
31 message(FATAL_ERROR "pcap-config --libs failed")
33 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
34 set(_pcap_library_dirs)
36 foreach(_arg IN LISTS LIBS_LIST)
37 if(_arg MATCHES "^-L")
38 # Add this directory to _pcap_library_dirs
39 string(REGEX REPLACE "-L" "" _dir ${_arg})
40 list(APPEND _pcap_library_dirs ${_dir})
41 elseif(_arg MATCHES "^-l")
42 string(REGEX REPLACE "-l" "" _lib ${_arg})
44 # Try to find that library, so we get its full path.
45 # CMake *really* doesn't like the notion of specifying "here are
46 # the directories in which to look for libraries" except in
47 # find_library() calls; it *really* prefers using full paths to
48 # library files, rather than library names.
50 find_library(_libfullpath ${_lib} HINTS ${__pcap_library_dirs})
51 list(APPEND PCAP_LIBRARIES ${_libfullpath})
55 # Now, get the library directories and libraries for static linking.
56 execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static"
57 RESULT_VARIABLE PCAP_CONFIG_RESULT
58 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
60 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
61 message(FATAL_ERROR "pcap-config --libs --static failed")
63 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
64 set(_pcap_static_library_dirs)
65 set(PCAP_STATIC_LIBRARIES)
66 foreach(_arg IN LISTS LIBS_LIST)
67 if(_arg MATCHES "^-L")
68 # Add this directory to _pcap_static_library_dirs
69 string(REGEX REPLACE "-L" "" _dir ${_arg})
70 list(APPEND _pcap_static_library_dirs ${_dir})
71 elseif(_arg MATCHES "^-l")
72 string(REGEX REPLACE "-l" "" _lib ${_arg})
74 # Try to find that library, so we get its full path, as
75 # we do with dynamic libraries.
77 find_library(_libfullpath ${_lib} HINTS ${__pcap_static_library_dirs})
78 list(APPEND PCAP_STATIC_LIBRARIES ${_libfullpath})
82 # Try to find the header
83 find_path(PCAP_INCLUDE_DIR pcap.h HINTS ${PCAP_INCLUDE_DIRS})
85 # Try to find the library
86 find_library(PCAP_LIBRARY pcap HINTS ${_pcap_library_dirs})
88 # Try to find the static library (XXX - what about AIX?)
89 include(CMakePushCheckState)
90 cmake_push_check_state()
91 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
92 find_library(PCAP_STATIC_LIBRARY pcap HINTS ${_pcap_static_library_dirs})
93 cmake_pop_check_state()
95 # Try to find the header
96 find_path(PCAP_INCLUDE_DIR pcap.h)
98 # Try to find the library
99 find_library(PCAP_LIBRARY pcap)
101 # Try to find the static library (XXX - what about AIX?)
102 include(CMakePushCheckState)
103 cmake_push_check_state()
104 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
105 find_library(PCAP_STATIC_LIBRARY pcap)
106 cmake_pop_check_state()
108 set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
109 set(PCAP_LIBRARIES ${PCAP_LIBRARY})
110 set(PCAP_STATIC_LIBRARIES ${PCAP_STATIC_LIBRARY})
113 include(FindPackageHandleStandardArgs)
114 find_package_handle_standard_args(PCAP