]> git.stg.codes - stg.git/blob - cmake/modules/FindPCap.cmake
Enable some more libs.
[stg.git] / cmake / modules / FindPCap.cmake
1 find_path ( PCap_INCLUDE_DIR NAMES pcap.h pcap/pcap.h DOC "Path to PCap header files." )
2 mark_as_advanced ( PCap_INCLUDE_DIR )
3
4 find_library ( PCap_LIB NAMES pcap DOC "Location of PCap library." )
5 mark_as_advanced ( PCap_LIB )
6
7 if ( PCap_INCLUDE_DIR )
8     file ( READ "${PCap_INCLUDE_DIR}/pcap/pcap.h" ver )
9
10     string ( REGEX MATCH "PCAP_VERSION_MAJOR ([0-9]*)" _ ${ver} )
11     set ( ver_major ${CMAKE_MATCH_1} )
12
13     string ( REGEX MATCH "PCAP_VERSION_MINOR ([0-9]*)" _ ${ver} )
14     set ( ver_minor ${CMAKE_MATCH_1} )
15
16     set ( PCap_VERSION "${ver_major}.${ver_minor}" )
17
18     unset ( ver )
19     unset ( ver_major )
20     unset ( ver_minor )
21 endif ( PCap_INCLUDE_DIR )
22
23 include ( FindPackageHandleStandardArgs )
24 find_package_handle_standard_args ( PCap
25                                     REQUIRED_VARS PCap_LIB PCap_INCLUDE_DIR
26                                     VERSION_VAR PCap_VERSION )
27
28 # Create the imported target
29 if ( PCap_FOUND )
30     set ( PCap_INCLUDE_DIRS ${PCap_INCLUDE_DIR} )
31     set ( PCap_LIBRARIES ${PCap_LIB} )
32     if ( NOT TARGET PCap::PCap )
33         add_library ( PCap::PCap UNKNOWN IMPORTED )
34         set_target_properties ( PCap::PCap PROPERTIES
35                                 IMPORTED_LOCATION "${PCap_LIB}"
36                                 INTERFACE_INCLUDE_DIRECTORIES "${PCap_INCLUDE_DIR}" )
37     endif ( NOT TARGET PCap::PCap )
38 endif ( PCap_FOUND )