Merge pull request #28460 from tchaikov/wip-cmake-detect-libnl

cmake: rewrite Findgenl to support components argument

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Kefu Chai 2019-06-20 00:36:53 +08:00 committed by GitHub
commit b2f75ba2aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 35 deletions

View File

@ -218,22 +218,13 @@ if(LINUX)
set(HAVE_UDEV ${UDEV_FOUND})
find_package(blkid REQUIRED)
set(HAVE_BLKID ${BLKID_FOUND})
if(WITH_RBD)
find_package(genl REQUIRED)
set(HAVE_GENL $GENL_FOUND)
endif()
elseif(FREEBSD)
set(HAVE_UDEV OFF)
set(HAVE_LIBAIO OFF)
set(HAVE_BLKID OFF)
set(HAVE_GENL OFF)
else()
set(HAVE_UDEV OFF)
message(STATUS "Not using udev")
set(HAVE_BLKID OFF)
message(STATUS "Not using BLKID")
set(HAVE_GENL OFF)
message(STATUS "Not using GENL")
endif(LINUX)
option(WITH_OPENLDAP "OPENLDAP is here" ON)

View File

@ -1,23 +0,0 @@
# - Find libnl-genl3
# Find the genl library and includes
#
# GENL_INCLUDE_DIR - where to find netlink.h, etc.
# GENL_LIBRARIES - List of libraries when using genl.
# GENL_FOUND - True if genl found.
find_path(GENL_INCLUDE_DIR NAMES netlink/netlink.h PATH_SUFFIXES libnl3)
find_library(LIBNL_LIB nl-3)
find_library(LIBNL_GENL_LIB nl-genl-3)
set(GENL_LIBRARIES
${LIBNL_LIB}
${LIBNL_GENL_LIB}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(nl-genl-3
DEFAULT_MSG GENL_LIBRARIES GENL_INCLUDE_DIR)
mark_as_advanced(
GENL_LIBRARIES
GENL_INCLUDE_DIR)

View File

@ -0,0 +1,50 @@
# - Find libnl
# Find the libnl-3 library and includes
#
# nl_INCLUDE_DIR - where to find netlink.h, etc.
# nl_<COMPONENT>_LIBRARY - library when using nl::<COMPONENT>.
# nl_FOUND - True if nl found.
find_path(nl_INCLUDE_DIR
NAMES
netlink/netlink.h
PATH_SUFFIXES
libnl3)
foreach(component "core" ${nl_FIND_COMPONENTS})
set(nl_COMPONENTS core cli genl idiag nf route xfrm)
list(FIND nl_COMPONENTS "${component}" found)
if(found EQUAL -1)
message(FATAL_ERROR "unknown libnl-3 component: ${component}")
endif()
if(component STREQUAL "core")
find_library(nl_${component}_LIBRARY nl-3)
else()
find_library(nl_${component}_LIBRARY nl-${component}-3)
endif()
list(APPEND nl_LIBRARIES "nl_${component}_LIBRARY")
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(nl
DEFAULT_MSG ${nl_LIBRARIES} nl_INCLUDE_DIR)
mark_as_advanced(
${nl_LIBRARIES}
nl_INCLUDE_DIR)
if(nl_FOUND)
foreach(component "core" ${nl_FIND_COMPONENTS})
if(NOT TARGET nl::${component})
add_library(nl::${component} UNKNOWN IMPORTED)
set_target_properties(nl::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${nl_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${nl_${component}_LIBRARY}")
if(NOT component STREQUAL "core")
set_target_properties(nl::${component} PROPERTIES
INTERFACE_LINK_LIBRARIES "${nl_core_LIBRARY}")
endif()
endif()
endforeach()
endif()

1
debian/control vendored
View File

@ -53,7 +53,6 @@ Build-Depends: cmake (>= 3.5),
libssl-dev,
libtool,
libudev-dev,
libnl-3-dev,
libnl-genl-3-dev,
libxml2-dev,
# Crimson libyaml-cpp-dev,

View File

@ -1,4 +1,4 @@
find_package(nl REQUIRED genl)
add_executable(rbd-nbd rbd-nbd.cc)
target_include_directories(rbd-nbd PUBLIC ${GENL_INCLUDE_DIR})
target_link_libraries(rbd-nbd librbd librados global ${GENL_LIBRARIES})
target_link_libraries(rbd-nbd librbd librados global nl::genl)
install(TARGETS rbd-nbd DESTINATION bin)