]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: support COMPONENTS param in Findpmem.cmake
authorKefu Chai <kchai@redhat.com>
Fri, 5 Mar 2021 06:04:23 +0000 (14:04 +0800)
committerNathan Cutler <ncutler@suse.com>
Mon, 8 Mar 2021 08:57:25 +0000 (09:57 +0100)
add two components: pmem and pmemobj to this package. so we can find
them and link against them in a more intuitive way.

before this change the COMPONENTS parameter passed to

find_package(pmem ...)

is dropped on the floor and ignored.

after this change, it is checked and taken into consideration.

also, in this change, the exposed variables are renamed from

PMEM_* to pmem_*

to be consistent with the package name. it's encouraged to be consistent
with the package name when it comes to the INCLUDE_DIR and LIBRARIES
variable names.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 48e4cd190f65ed92fa9ca41b147621b46b4ea278)

cmake/modules/Findpmem.cmake

index 8bf3c02d746a06a55b70135bac48a76637f7201b..b30d9ae6bbbb15fb9e273ae1e1d7c519a3b31200 100644 (file)
@@ -1,45 +1,47 @@
 # - Find pmem
 #
-# PMEM_INCLUDE_DIR - Where to find libpmem.h
-# PMEM_LIBRARIES - List of libraries when using pmdk.
+# pmem_INCLUDE_DIRS - Where to find libpmem headers
+# pmem_LIBRARIES - List of libraries when using libpmem.
 # pmem_FOUND - True if pmem found.
-# PMEMOBJ_INCLUDE_DIR - Where to find libpmemobj.h
-# PMEMOBJ_LIBRARIES - List of libraries when using pmdk obj.
-# pmemobj_FOUND - True if pmemobj found.
 
-find_path(PMEM_INCLUDE_DIR libpmem.h)
-find_library(PMEM_LIBRARIES pmem)
+foreach(component pmem ${pmem_FIND_COMPONENTS})
+  if(component STREQUAL pmem)
+    find_path(pmem_${component}_INCLUDE_DIR libpmem.h)
+    find_library(pmem_${component}_LIBRARY pmem)
+  elseif(component STREQUAL pmemobj)
+    find_path(pmem_${component}_INCLUDE_DIR libpmemobj.h)
+    find_library(pmem_${component}_LIBRARY pmemobj)
+  else()
+    message(FATAL_ERROR "unknown libpmem component: ${component}")
+  endif()
+  mark_as_advanced(
+    pmem_${component}_INCLUDE_DIR
+    pmem_${component}_LIBRARY)
+  list(APPEND pmem_INCLUDE_DIRS "pmem_${component}_INCLUDE_DIR")
+  list(APPEND pmem_LIBRARIES "pmem_${component}_LIBRARY")
+endforeach()
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(pmem
-  DEFAULT_MSG PMEM_LIBRARIES PMEM_INCLUDE_DIR)
+  DEFAULT_MSG pmem_INCLUDE_DIRS pmem_LIBRARIES)
 
 mark_as_advanced(
-  PMEM_INCLUDE_DIR
-  PMEM_LIBRARIES)
-
-if(pmem_FOUND AND NOT TARGET pmem::pmem)
-  add_library(pmem::pmem UNKNOWN IMPORTED)
-  set_target_properties(pmem::pmem PROPERTIES
-    INTERFACE_INCLUDE_DIRECTORIES "${PMEM_INCLUDE_DIR}"
-    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
-    IMPORTED_LOCATION "${PMEM_LIBRARIES}")
-endif()
-
-find_path(PMEMOBJ_INCLUDE_DIR libpmemobj.h)
-find_library(PMEMOBJ_LIBRARIES pmemobj)
-
-find_package_handle_standard_args(pmemobj
-  DEFAULT_MSG PMEMOBJ_LIBRARIES PMEMOBJ_INCLUDE_DIR)
-
-mark_as_advanced(
-  PMEMOBJ_INCLUDE_DIR
-  PMEMOBJ_LIBRARIES)
-
-if(pmemobj_FOUND AND NOT TARGET pmem::pmemobj)
-  add_library(pmem::pmemobj UNKNOWN IMPORTED)
-  set_target_properties(pmem::pmemobj PROPERTIES
-    INTERFACE_INCLUDE_DIRECTORIES "${PMEMOBJ_INCLUDE_DIR}"
-    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
-    IMPORTED_LOCATION "${PMEMOBJ_LIBRARIES}")
+  pmem_INCLUDE_DIRS
+  pmem_LIBRARIES)
+
+if(pmem_FOUND)
+  foreach(component pmem ${pmem_FIND_COMPONENTS})
+    if(NOT TARGET pmem::${component})
+      add_library(pmem::${component} UNKNOWN IMPORTED)
+      set_target_properties(pmem::${component} PROPERTIES
+        INTERFACE_INCLUDE_DIRECTORIES "${pmem_${component}_INCLUDE_DIR}"
+        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+        IMPORTED_LOCATION "${pmem_${component}_LIBRARY}")
+      # all pmem libraries calls into pmem::pmem
+      if(NOT component STREQUAL pmem)
+        set_target_properties(pmem::${component} PROPERTIES
+          INTERFACE_LINK_LIBRARIES pmem::pmem)
+      endif()
+    endif()
+  endforeach()
 endif()