diff options
-rw-r--r-- | cmake/modules/FindNL.cmake | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/cmake/modules/FindNL.cmake b/cmake/modules/FindNL.cmake index 46ca03dbef..5b12a15319 100644 --- a/cmake/modules/FindNL.cmake +++ b/cmake/modules/FindNL.cmake @@ -3,17 +3,18 @@ # # If they exist, differentiate between versions 1, 2 and 3. # Version 1 does not have netlink/version.h -# Version 3 does have the major version number as a suffix -# to the libnl name (libnl-3) +# Version 2 started separating libraries (libnl{,-genl,-route}). +# Version 3 (>= 3.2) started appending the major version number as suffix to +# library names (libnl-3) # # NL_INCLUDE_DIRS - where to find libnl.h, etc. -# NL_LIBRARIES - List of libraries when using libnl3. +# NL_LIBRARIES - List of libraries when using libnl. # NL_FOUND - True if libnl found. -IF (NL_LIBRARIES AND NL_INCLUDE_DIRS ) +if(NL_LIBRARIES AND NL_INCLUDE_DIRS) # in cache already SET(NL_FOUND TRUE) -ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) +else() SET( SEARCHPATHS /opt/local /sw @@ -23,11 +24,16 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) find_package(PkgConfig) pkg_check_modules(NL3 libnl-3.0 libnl-genl-3.0 libnl-route-3.0) - pkg_search_module(NL2 libnl-2.0) + if(NOT NL3_FOUND) + pkg_search_module(NL2 libnl-2.0) + endif() - FIND_PATH( NL_INCLUDE_DIR + # Try to find NL 2.0, 3.0 or 3.1 (/usr/include/netlink/version.h) or + # NL >= 3.2 (/usr/include/libnl3/netlink/version.h) + find_path(NL3_INCLUDE_DIR PATH_SUFFIXES include/libnl3 + include NAMES netlink/version.h HINTS @@ -37,8 +43,8 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) $(SEARCHPATHS) ) # NL version >= 2 - IF ( NL_INCLUDE_DIR ) - FIND_LIBRARY( NL_LIBRARY + if(NL3_INCLUDE_DIR) + find_library(NL3_LIBRARY NAMES nl-3 nl PATH_SUFFIXES @@ -49,7 +55,7 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) PATHS $(SEARCHPATHS) ) - FIND_LIBRARY( NLGENL_LIBRARY + find_library(NLGENL_LIBRARY NAMES nl-genl-3 nl-genl PATH_SUFFIXES @@ -60,7 +66,7 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) PATHS $(SEARCHPATHS) ) - FIND_LIBRARY( NLROUTE_LIBRARY + find_library(NLROUTE_LIBRARY NAMES nl-route-3 nl-route PATH_SUFFIXES @@ -74,22 +80,26 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) # # If we don't have all of those libraries, we can't use libnl. # - IF ( NOT NLGENL_LIBRARY AND NOT NLROUTE_LIBRARY ) - SET( NL_LIBRARY NOTFOUND ) - ENDIF ( NOT NLGENL_LIBRARY AND NOT NLROUTE_LIBRARY ) - IF( NL_LIBRARY ) - STRING(REGEX REPLACE ".*nl-([^.,;]*).*" "\\1" NLSUFFIX ${NL_LIBRARY}) - IF ( NLSUFFIX ) - SET( HAVE_LIBNL3 1 ) - ELSE ( NLSUFFIX ) - SET( HAVE_LIBNL2 1 ) - ENDIF (NLSUFFIX ) - SET( HAVE_LIBNL 1 ) - ENDIF( NL_LIBRARY ) - ELSE( NL_INCLUDE_DIR ) - # NL version 1 ? + if(NL3_LIBRARY AND NLGENL_LIBRARY AND NLROUTE_LIBRARY) + set(NL_LIBRARY ${NL3_LIBRARY}) + if(NL3_INCLUDE_DIR) + # NL2 and NL3 are similar and just affect how the version is reported in + # the --version output. In cast of doubt, assume NL3 since a library + # without version number could be any of 2.0, 3.0 or 3.1. + if(NOT NL3_FOUND AND NL2_FOUND) + set(HAVE_LIBNL2 1) + else() + set(HAVE_LIBNL3 1) + endif() + endif() + endif() + set(NL_INCLUDE_DIR ${NL3_INCLUDE_DIR}) + endif() + + # libnl-2 and libnl-3 not found, try NL version 1 + if(NOT (NL_LIBRARY AND NL_INCLUDE_DIR)) pkg_search_module(NL1 libnl-1) - FIND_PATH( NL_INCLUDE_DIR + find_path(NL1_INCLUDE_DIR NAMES netlink/netlink.h HINTS @@ -97,7 +107,7 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) PATHS $(SEARCHPATHS) ) - FIND_LIBRARY( NL_LIBRARY + find_library(NL1_LIBRARY NAMES nl PATH_SUFFIXES @@ -107,11 +117,13 @@ ELSE (NL_LIBRARIES AND NL_INCLUDE_DIRS ) PATHS $(SEARCHPATHS) ) - if ( NL_INCLUDE_DIR ) - SET( HAVE_LIBNL1 1 ) - ENDIF ( NL_INCLUDE_DIR ) - ENDIF( NL_INCLUDE_DIR ) -ENDIF(NL_LIBRARIES AND NL_INCLUDE_DIRS) + set(NL_LIBRARY ${NL1_LIBRARY}) + set(NL_INCLUDE_DIR ${NL1_INCLUDE_DIR}) + if(NL1_LIBRARY AND NL1_INCLUDE_DIR) + set(HAVE_LIBNL1 1) + endif() + endif() +endif() # MESSAGE(STATUS "LIB Found: ${NL_LIBRARY}, Suffix: ${NLSUFFIX}\n 1:${HAVE_LIBNL1}, 2:${HAVE_LIBNL2}, 3:${HAVE_LIBNL3}.") # handle the QUIETLY and REQUIRED arguments and set NL_FOUND to TRUE if @@ -120,12 +132,17 @@ INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(NL DEFAULT_MSG NL_LIBRARY NL_INCLUDE_DIR) IF(NL_FOUND) - SET( NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY} ) - SET( NL_INCLUDE_DIRS ${NL_INCLUDE_DIR}) -ELSE() - SET( NL_LIBRARIES ) - SET( NL_INCLUDE_DIRS ) -ENDIF() + if(HAVE_LIBNL3) + set(NL_LIBRARIES ${NLGENL_LIBRARY} ${NLROUTE_LIBRARY} ${NL_LIBRARY}) + else() + set(NL_LIBRARIES ${NL_LIBRARY}) + endif() + set(NL_INCLUDE_DIRS ${NL_INCLUDE_DIR}) + set(HAVE_LIBNL 1) +else() + set(NL_LIBRARIES ) + set(NL_INCLUDE_DIRS) +endif() MARK_AS_ADVANCED( NL_LIBRARIES NL_INCLUDE_DIRS ) |