There are two versions of pcap-config supplied on Solaris (or, at least,
on 64-bit Solaris) - a version that has the right --libs output to find
the 32-bit libraries and a version that has the right --libs output to
find the 64-bit libraries.
Try to figure out whether we're doing a 32-bit or 64-bit build (based on
the pointer size) and, for 64-bit builds, run the 64-bit version of
pcap-config.
(cherry picked from commit c39d40a767)
Pull in some code from CMake 3.12.4's FindPkgConfig.cmake to arrange
that, when running pkg-config, directories from CMAKE_PREFIX_PATH are in
the PKG_CONFIG_PATH environment variable.
We do this because we want to make sure that, if CMAKE_PREFIX_PATH is
set, and it points to a directory that contains a libpcap that has a .pc
file installed, we get that .pc file, but we don't yet want to require a
minimum of CMake 3.1 or later (CMake 3.1 and later do that
automatically) because there might be some long-term support OS version
that comes with an older version of CMake.
(cherry picked from commit 8ceef287ad)
We have messages for pkg-config and for the old-fashioned search; print
a message if pkg-config failed but we found pcap-config.
Fix the suppression of messages with a QUIET argument.
On Windows, don't bother with pkg-config or pcap-config. We make no
effort, in libpcap, to make them work on Windows, we don't install the
.pc files or pcap-config on Windows with the CMake build, and neither
WinPcap nor Npcap install them.
On UN*X:
For pkg-config and pcap-config, set variables named CONFIG_PCAP_xxx.
pkg-config's xxx_LIBRARIES and xxx_STATIC_LIBRARIES variables have only
library names, not library full paths, so we need to use find_library()
to convert them to full paths. For pcap-config, generate
library-name-only CONFIG_PCAP_LIBRARIES and CONFIG_PCAP_STATIC_LIBRARIES
variables, as well as CONFIG_PCAP_FOUND.
If CONFIG_PCAP_FOUND is true, meaning that either pkg-config or
pcap-config succeeded, copy CONFIG_PCAP_INCLUDE_DIRS to
PCAP_INCLUDE_DIRS, iterate over CONFIG_PCAP_LIBRARIES and
CONFIG_PCAP_STATIC_LIBRARIES to generate full paths for all of the
libraries and put them in PCAP_LIBRARIES and PCAP_STATIC_LIBRARIES, and
set PCAP_FOUND.
If CONFIG_PCAP_FOUND is false, search for headers and libraries
ourselves.
If we have pkg-config, *and* it has .pc files for libpcap, use it to get
the C compiler flags and linker flags for libpcap.
find_library() sets a cache variable; when we're looping over libraries,
trying to find their full paths, we really want the variable to act as a
local variable, as we're looking up different libraries, so unset it
after we're finished processing a particular library.
When we're searching for static libraries, save the current value of
CMAKE_FIND_LIBRARY_SUFFIXES, set it to ".a", and then restore it when
we're done. Don't use cmake_push_check_state() for that, as
CMAKE_FIND_LIBRARY_SUFFIXES is *not* one of the variables that it's
guaranteed to save and restore.
Also, while there may not be a convention for "look for package XXX
here", there is a convention for "look for stuff here" - put "here" in
CMAKE_PREFIX_PATH. So don't use PCAP_DLL_DIR, just let find_path() and
find_library() search where you tell it (on Windows *or* UN*X).
CMake *hates* that. -L considered harmful, I guess (and I don't know
how that's done with tools other than UN*X linkers - do all of them
support an equivalent to -L?).
This should fix the checks for pcap functions to look in the library we
found.