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