5 find_program(PCAP_CONFIG pcap-config)
8 # We have pcap-config; use it.
9 # XXX - what if this is on Windows? If you're using, for example,
10 # MinGW, that might be the right thing to do, *if* pcap-config
11 # were made to work properly on Windows, but what about MSVC?
13 # First, get the include directory.
15 execute_process(COMMAND "${PCAP_CONFIG}" "--cflags"
16 RESULT_VARIABLE PCAP_CONFIG_RESULT
17 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
18 OUTPUT_STRIP_TRAILING_WHITESPACE
20 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
21 message(FATAL_ERROR "pcap-config --cflags failed")
24 # XXX - this assumes that there's only one -I flag in the output
25 # of pcap-config --cflags. That *should* be the case.
27 string(REGEX REPLACE "-I" "" PCAP_INCLUDE_DIRS ${PCAP_CONFIG_OUTPUT})
28 set(PCAP_INCLUDE_DIR ${PCAP_INCLUDE_DIRS})
30 # Now, get the libraries.
31 execute_process(COMMAND "${PCAP_CONFIG}" "--libs"
32 RESULT_VARIABLE PCAP_CONFIG_RESULT
33 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
34 OUTPUT_STRIP_TRAILING_WHITESPACE
36 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
37 message(FATAL_ERROR "pcap-config --libs failed")
39 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
40 set(_pcap_library_dirs)
42 foreach(_arg IN LISTS LIBS_LIST)
43 if(_arg MATCHES "^-L")
44 # Add this directory to _pcap_library_dirs
45 string(REGEX REPLACE "-L" "" _dir ${_arg})
46 list(APPEND _pcap_library_dirs ${_dir})
47 elseif(_arg MATCHES "^-l")
48 string(REGEX REPLACE "-l" "" _lib ${_arg})
50 # Try to find that library, so we get its full path.
51 # CMake *really* doesn't like the notion of specifying "here are
52 # the directories in which to look for libraries" except in
53 # find_library() calls; it *really* prefers using full paths to
54 # library files, rather than library names.
56 find_library(_libfullpath ${_lib} HINTS ${__pcap_library_dirs})
57 list(APPEND PCAP_LIBRARIES ${_libfullpath})
61 # Now, get the library directories and libraries for static linking.
62 execute_process(COMMAND "${PCAP_CONFIG}" "--libs" "--static"
63 RESULT_VARIABLE PCAP_CONFIG_RESULT
64 OUTPUT_VARIABLE PCAP_CONFIG_OUTPUT
66 if(NOT PCAP_CONFIG_RESULT EQUAL 0)
67 message(FATAL_ERROR "pcap-config --libs --static failed")
69 separate_arguments(LIBS_LIST UNIX_COMMAND ${PCAP_CONFIG_OUTPUT})
70 set(_pcap_static_library_dirs)
71 set(PCAP_STATIC_LIBRARIES)
72 foreach(_arg IN LISTS LIBS_LIST)
73 if(_arg MATCHES "^-L")
74 # Add this directory to _pcap_static_library_dirs
75 string(REGEX REPLACE "-L" "" _dir ${_arg})
76 list(APPEND _pcap_static_library_dirs ${_dir})
77 elseif(_arg MATCHES "^-l")
78 string(REGEX REPLACE "-l" "" _lib ${_arg})
80 # Try to find that library, so we get its full path, as
81 # we do with dynamic libraries.
83 find_library(_libfullpath ${_lib} HINTS ${__pcap_static_library_dirs})
84 list(APPEND PCAP_STATIC_LIBRARIES ${_libfullpath})
88 # Try to find the header
89 find_path(PCAP_INCLUDE_DIR pcap.h HINTS ${PCAP_INCLUDE_DIRS})
91 # Try to find the library
92 find_library(PCAP_LIBRARY pcap HINTS ${_pcap_library_dirs})
94 # Try to find the static library (XXX - what about AIX?)
95 include(CMakePushCheckState)
96 cmake_push_check_state()
97 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
98 find_library(PCAP_STATIC_LIBRARY pcap HINTS ${_pcap_static_library_dirs})
99 cmake_pop_check_state()
101 # Try to find the header
102 find_path(PCAP_INCLUDE_DIR pcap.h)
104 # Try to find the library
105 find_library(PCAP_LIBRARY pcap)
109 # OK, look for it under the name wpcap.
111 find_library(PCAP_LIBRARY wpcap)
112 endif(NOT PCAP_LIBRARY)
115 # Try to find the static library (XXX - what about AIX?)
116 include(CMakePushCheckState)
117 cmake_push_check_state()
118 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
119 find_library(PCAP_STATIC_LIBRARY pcap)
120 cmake_pop_check_state()
123 set(PCAP_INCLUDE_DIRS ${PCAP_INCLUDE_DIR})
124 set(PCAP_LIBRARIES ${PCAP_LIBRARY})
125 set(PCAP_STATIC_LIBRARIES ${PCAP_STATIC_LIBRARY})
128 include(FindPackageHandleStandardArgs)
129 find_package_handle_standard_args(PCAP