]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: find motr libraries and header before using them 47534/head
authorKefu Chai <tchaikov@gmail.com>
Wed, 10 Aug 2022 12:10:42 +0000 (20:10 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 10 Aug 2022 13:15:12 +0000 (21:15 +0800)
cmake should fail when generating the building system, if the necessary
development libraries or the header files are missing.

in this change, Findmotr.cmake is added to detect the motr library
and header so that we can use it to find the motr package before using
it.

See-also: https://tracker.ceph.com/issues/57079
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
cmake/modules/Findmotr.cmake [new file with mode: 0644]
src/rgw/CMakeLists.txt

diff --git a/cmake/modules/Findmotr.cmake b/cmake/modules/Findmotr.cmake
new file mode 100644 (file)
index 0000000..5ac0ef6
--- /dev/null
@@ -0,0 +1,50 @@
+# - Find libmotr
+# Find the motr and motrhl libraries and includes
+#
+# motr_INCLUDE_DIR - where to find motr.hpp etc.
+# motr_LIBRARIES - List of libraries when using motr.
+# motr_FOUND - True if motr found.
+
+find_package(PkgConfig QUIET REQUIRED)
+pkg_search_module(PC_motr QUIET motr)
+
+find_path(motr_INCLUDE_DIR
+  NAMES motr/config.h
+  HINTS ${PC_motr_INCLUDE_DIRS})
+find_library(motr_LIBRARY
+  NAMES motr
+  HINTS ${PC_motr_LIBRARY_DIRS})
+find_library(motr_helpers_LIBRARY
+  NAMES motr-helpers
+  HINTS ${PC_motr_LIBRARY_DIRS})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(motr
+  DEFAULT_MSG
+  motr_INCLUDE_DIR
+  motr_LIBRARY
+  motr_helpers_LIBRARY)
+
+mark_as_advanced(
+  motr_INCLUDE_DIR
+  motr_LIBRARY
+  motr_helpers_LIBRARY)
+
+if(motr_FOUND)
+  set(motr_LIBRARIES ${motr_LIBRARY} ${motr_helpers_LIBRARY})
+  if(NOT (TARGET motr::helpers))
+    add_library(motr::helpers UNKNOWN IMPORTED)
+    set_target_properties(motr::helpers PROPERTIES
+      IMPORTED_LOCATION "${motr_helpers_LIBRARY}")
+  endif()
+  if(NOT (TARGET motr::motr))
+    add_library(motr::motr UNKNOWN IMPORTED)
+    set_target_properties(motr::motr PROPERTIES
+      INTERFACE_COMPILE_DEFINITIONS "M0_EXTERN=extern;M0_INTERNAL="
+      INTERFACE_COMPILE_OPTIONS "-Wno-attributes"
+      INTERFACE_INCLUDE_DIRECTORIES "${motr_INCLUDE_DIR}"
+      INTERFACE_LINK_LIBRARIES motr::helpers
+      IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+      IMPORTED_LOCATION "${motr_LIBRARY}")
+  endif()
+endif()
index 1b392cdf7958294d1d1ec24e38f58e8d9b792915..3ac721f0fd692d0b4d50bb8fe11934ca21698b6f 100644 (file)
@@ -264,11 +264,8 @@ if(WITH_RADOSGW_DBSTORE)
 endif()
 
 if(WITH_RADOSGW_MOTR)
-  target_include_directories(rgw_common PRIVATE "/usr/include/motr")
-  target_compile_options(rgw_common PRIVATE "-Wno-attributes")
-  target_compile_definitions(rgw_common
-    PRIVATE "M0_EXTERN=extern" "M0_INTERNAL=")
-  target_link_libraries(rgw_common PRIVATE motr motr-helpers)
+  find_package(motr REQUIRED)
+  target_link_libraries(rgw_common PRIVATE motr::motr)
 endif()
 
 set(rgw_a_srcs