decrypt drsuapi attributes
[wireshark-sm.git] / cmake / modules / FindNL.cmake
blobd4f003e886204ef75b830cecc36c92d05724a66c
2 # Find the native netlink includes and library
4 # If they exist, differentiate between versions 1, 2 and 3.
5 # Version 1 does not have netlink/version.h
6 # Version 2 started separating libraries (libnl{,-genl,-route}).
7 # Version 3 (>= 3.2) started appending the major version number as suffix to
8 # library names (libnl-3)
10 #  NL_INCLUDE_DIRS - where to find libnl.h, etc.
11 #  NL_LIBRARIES    - List of libraries when using libnl.
12 #  NL_FOUND        - True if libnl found.
14 if(NL_LIBRARIES AND NL_INCLUDE_DIRS)
15   # in cache already
16   SET(NL_FOUND TRUE)
17 else()
18   SET( SEARCHPATHS
19       /opt/local
20       /sw
21       /usr
22       /usr/local
23   )
25   find_package(PkgConfig)
26   pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 libnl-route-3.0)
27   if(NOT NL3_FOUND)
28     pkg_search_module(NL2 libnl-2.0)
29   endif()
31   # Try to find NL 2.0, 3.0 or 3.1 (/usr/include/netlink/version.h) or
32   # NL >= 3.2 (/usr/include/libnl3/netlink/version.h)
33   find_path(NL3_INCLUDE_DIR
34     PATH_SUFFIXES
35       include/libnl3
36       include
37     NAMES
38       netlink/version.h
39     HINTS
40       "${NL3_libnl-3.0_INCLUDEDIR}"
41       "${NL2_INCLUDEDIR}"
42     PATHS
43       $(SEARCHPATHS)
44   )
45   # NL version >= 2
46   if(NL3_INCLUDE_DIR)
47     find_library(NL3_LIBRARY
48       NAMES
49         nl-3 nl
50       PATH_SUFFIXES
51         lib64 lib
52       HINTS
53         "${NL3_libnl-3.0_LIBDIR}"
54         "${NL2_LIBDIR}"
55       PATHS
56         $(SEARCHPATHS)
57     )
58     find_library(NLGENL_LIBRARY
59       NAMES
60         nl-genl-3 nl-genl
61       PATH_SUFFIXES
62         lib64 lib
63       HINTS
64         "${NL3_libnl-genl-3.0_LIBDIR}"
65         "${NL2_LIBDIR}"
66       PATHS
67         $(SEARCHPATHS)
68     )
69     find_library(NLROUTE_LIBRARY
70       NAMES
71         nl-route-3 nl-route
72       PATH_SUFFIXES
73         lib64 lib
74       HINTS
75         "${NL3_libnl-route-3.0_LIBDIR}"
76         "${NL2_LIBDIR}"
77       PATHS
78         $(SEARCHPATHS)
79     )
80     #
81     # If we don't have all of those libraries, we can't use libnl.
82     #
83     if(NL3_LIBRARY AND NLGENL_LIBRARY AND NLROUTE_LIBRARY)
84       set(NL_LIBRARY ${NL3_LIBRARY})
85       if(NL3_INCLUDE_DIR)
86         # NL2 and NL3 are similar and just affect how the version is reported in
87         # the --version output. In cast of doubt, assume NL3 since a library
88         # without version number could be any of 2.0, 3.0 or 3.1.
89         if(NOT NL3_FOUND AND NL2_FOUND)
90           set(HAVE_LIBNL2 1)
91         else()
92           set(HAVE_LIBNL3 1)
93         endif()
94       endif()
95     endif()
96     set(NL_INCLUDE_DIR ${NL3_INCLUDE_DIR})
97   endif()
99   # libnl-2 and libnl-3 not found, try NL version 1
100   if(NOT (NL_LIBRARY AND NL_INCLUDE_DIR))
101     pkg_search_module(NL1 libnl-1)
102     find_path(NL1_INCLUDE_DIR
103       NAMES
104         netlink/netlink.h
105       HINTS
106         "${NL1_INCLUDEDIR}"
107       PATHS
108         $(SEARCHPATHS)
109     )
110     find_library(NL1_LIBRARY
111       NAMES
112         nl
113       PATH_SUFFIXES
114         lib64 lib
115       HINTS
116         "${NL1_LIBDIR}"
117       PATHS
118         $(SEARCHPATHS)
119     )
120     set(NL_LIBRARY ${NL1_LIBRARY})
121     set(NL_INCLUDE_DIR ${NL1_INCLUDE_DIR})
122     if(NL1_LIBRARY AND NL1_INCLUDE_DIR)
123       set(HAVE_LIBNL1 1)
124     endif()
125   endif()
126 endif()
127 # MESSAGE(STATUS "LIB Found: ${NL_LIBRARY}, Suffix: ${NLSUFFIX}\n  1:${HAVE_LIBNL1}, 2:${HAVE_LIBNL2}, 3:${HAVE_LIBNL3}.")
129 # handle the QUIETLY and REQUIRED arguments and set NL_FOUND to TRUE if
130 # all listed variables are TRUE
131 INCLUDE(FindPackageHandleStandardArgs)
132 FIND_PACKAGE_HANDLE_STANDARD_ARGS(NL DEFAULT_MSG NL_LIBRARY NL_INCLUDE_DIR)
134 IF(NL_FOUND)
135   set(NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY})
136   set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIR})
137   set(HAVE_LIBNL 1)
138 else()
139   set(NL_LIBRARIES )
140   set(NL_INCLUDE_DIRS)
141 endif()
143 MARK_AS_ADVANCED( NL_LIBRARIES NL_INCLUDE_DIRS )