]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: consolidate the find logic in Findpmem.cmake
authorKefu Chai <kchai@redhat.com>
Sat, 3 Apr 2021 12:57:41 +0000 (20:57 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Apr 2021 15:58:53 +0000 (23:58 +0800)
less repeating this way

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Findpmem.cmake

index 603b3fbf60b93380d3b2a7701d5c6049209579ba..2f5366eb5406e6ed4e5a1511935897ee8c222b3b 100644 (file)
@@ -4,30 +4,21 @@
 # pmem_LIBRARIES - List of libraries when using libpmem.
 # pmem_FOUND - True if pmem found.
 
-find_package(PkgConfig QUIET)
-if(PKG_CONFIG_FOUND)
-  pkg_check_modules(PKG_pmem QUIET libpmem)
-  pkg_check_modules(PKG_pmemobj QUIET libpmemobj)
-endif()
+find_package(PkgConfig QUIET REQUIRED)
 
 foreach(component pmem ${pmem_FIND_COMPONENTS})
-  if(component STREQUAL pmem)
-    find_path(pmem_${component}_INCLUDE_DIR
-      NAMES libpmem.h
-      HINTS ${PKG_pmem_INCLUDE_DIRS})
-    find_library(pmem_${component}_LIBRARY
-      NAMES pmem
-      HINTS ${PKG_pmem_LIBRARY_DIRS})
-  elseif(component STREQUAL pmemobj)
-    find_path(pmem_${component}_INCLUDE_DIR
-      NAMES libpmemobj.h
-      HINTS ${PKG_pmemobj_INCLUDE_DIRS})
-    find_library(pmem_${component}_LIBRARY
-      NAMES pmemobj
-      HINTS ${PKG_pmemobj_LIBRARY_DIRS}))
-  else()
+  set(pmem_COMPONENTS pmem pmemobj)
+  list(FIND pmem_COMPONENTS "${component}" found)
+  if(found EQUAL -1)
     message(FATAL_ERROR "unknown libpmem component: ${component}")
   endif()
+  pkg_check_modules(PKG_${component} QUIET lib${component})
+  find_path(pmem_${component}_INCLUDE_DIR
+    NAMES lib${component}.h
+    HINTS ${PKG_${component}_INCLUDE_DIRS})
+  find_library(pmem_${component}_LIBRARY
+    NAMES ${component}
+    HINTS ${PKG_${component}_LIBRARY_DIRS})
   mark_as_advanced(
     pmem_${component}_INCLUDE_DIR
     pmem_${component}_LIBRARY)