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)
25 find_package(PkgConfig)
26 pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 libnl-route-3.0)
28 pkg_search_module(NL2 libnl-2.0)
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
40 "${NL3_libnl-3.0_INCLUDEDIR}"
47 find_library(NL3_LIBRARY
53 "${NL3_libnl-3.0_LIBDIR}"
58 find_library(NLGENL_LIBRARY
64 "${NL3_libnl-genl-3.0_LIBDIR}"
69 find_library(NLROUTE_LIBRARY
75 "${NL3_libnl-route-3.0_LIBDIR}"
81 # If we don't have all of those libraries, we can't use libnl.
83 if(NL3_LIBRARY AND NLGENL_LIBRARY AND NLROUTE_LIBRARY)
84 set(NL_LIBRARY ${NL3_LIBRARY})
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)
96 set(NL_INCLUDE_DIR ${NL3_INCLUDE_DIR})
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
110 find_library(NL1_LIBRARY
120 set(NL_LIBRARY ${NL1_LIBRARY})
121 set(NL_INCLUDE_DIR ${NL1_INCLUDE_DIR})
122 if(NL1_LIBRARY AND NL1_INCLUDE_DIR)
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)
135 set(NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY})
136 set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIR})
143 MARK_AS_ADVANCED( NL_LIBRARIES NL_INCLUDE_DIRS )