]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: rewrite Findgenl to support components argument
authorKefu Chai <kchai@redhat.com>
Sun, 9 Jun 2019 09:12:27 +0000 (17:12 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 19 Jun 2019 13:21:00 +0000 (21:21 +0800)
* rename genl to nl:
  "genl" is not very specific without more context. and libnl is actually
  a library suite. so it would be better if we can rename the library to
  be found to "libnl", and by following the naming convention of CMake,
  in this change, Findgenl.cmake is renamed to Findnl.cmake
* Findnl.cmake: support the component argument, in our specific case,
  what we want is "libnl-genl" library, which is one of the libraries
  offered by libnl. so let's just make it a component.
* Findnl.cmake: should pass the names of the required variables instead of
  their values to `find_package_handle_standard_args()`. before this
  change, we pass `GENL_LIBRARIES` to this function. it was correct at the
  first glance. but it is not able to handle the case where case where
  libnl-genl is not installed. so the fix is to pass all the names of
  required library paths to this function. in this change, their name
  are concatenated to a single variable -- `nl_LIBRARIES`, and the
  value of this variable is passed to
  `find_package_handle_standard_args()`. and the error message would
  be more specific this way if libnl-genl is not found:
    Could NOT find nl (missing: nl_genl_LIBRARY)
* Findnl.cmake: add nl::<component> as imported library, it helps the
  consumer of these libraries to import them -- no need to
  specify the `target_include_directories()` separately anymore.
* move the find_package() code to where it is used. it helps to improve
  the readability.
* remove `HAVE_GENL` variable: it's not used anywhere.
* drop the messages of "Not using foobar", they do not help.

Signed-off-by: Kefu Chai <kchai@redhat.com>
CMakeLists.txt
cmake/modules/Findgenl.cmake [deleted file]
cmake/modules/Findnl.cmake [new file with mode: 0644]
src/tools/rbd_nbd/CMakeLists.txt

index 050dfe059b40bba6f0c2552c75033281bb3b601e..4418099f77a46443032035f955d158c186d125c9 100644 (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)
diff --git a/cmake/modules/Findgenl.cmake b/cmake/modules/Findgenl.cmake
deleted file mode 100644 (file)
index 07c5f35..0000000
+++ /dev/null
@@ -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)
diff --git a/cmake/modules/Findnl.cmake b/cmake/modules/Findnl.cmake
new file mode 100644 (file)
index 0000000..1fd2fcd
--- /dev/null
@@ -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()
index 5356fae4f9bdc51241c4d55a56932d4a6589158b..da758f514701ec389f8817d1c050b93e1b26cbd0 100644 (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)