2019-07-10 15:30:47 +00:00
|
|
|
# - Find pmem
|
|
|
|
#
|
2021-03-05 06:04:23 +00:00
|
|
|
# pmem_INCLUDE_DIRS - Where to find libpmem headers
|
|
|
|
# pmem_LIBRARIES - List of libraries when using libpmem.
|
2019-07-10 15:30:47 +00:00
|
|
|
# pmem_FOUND - True if pmem found.
|
|
|
|
|
2021-04-03 12:57:41 +00:00
|
|
|
find_package(PkgConfig QUIET REQUIRED)
|
2021-04-03 12:49:46 +00:00
|
|
|
|
2021-04-03 13:59:05 +00:00
|
|
|
# all pmem libraries depend on pmem, so always find it
|
|
|
|
set(pmem_FIND_COMPONENTS ${pmem_FIND_COMPONENTS} pmem)
|
|
|
|
list(REMOVE_DUPLICATES pmem_FIND_COMPONENTS)
|
|
|
|
|
|
|
|
foreach(component ${pmem_FIND_COMPONENTS})
|
2021-04-03 12:57:41 +00:00
|
|
|
set(pmem_COMPONENTS pmem pmemobj)
|
|
|
|
list(FIND pmem_COMPONENTS "${component}" found)
|
|
|
|
if(found EQUAL -1)
|
2021-03-05 06:04:23 +00:00
|
|
|
message(FATAL_ERROR "unknown libpmem component: ${component}")
|
|
|
|
endif()
|
cmake/modules/Findpmem: always set pmem_VERSION_STRING
before this change, `pmem_VERSION_STRING` is not set if it is not able
to fulfill the specified version requirement. the intention was to check
if the version is able to satisfy the requirement. but actually, passing
an empty `pmem_VERSION_STRING` to `find_package_handle_standard_args()`
as the option of `VERSION_VAR` does not fail this check. on the
contrary, it prints
-- Found pmem: pmem_pmemobj_INCLUDE_DIR;pmem_pmem_INCLUDE_DIR (Required
is at least version "1.17")
if we requires pmem 1.17, while the found version is, for instance,
1.10.
if the required version is 1.7, and the found version is 1.10, the
output from cmake is:
-- Found pmem: pmem_pmemobj_INCLUDE_DIR;pmem_pmem_INCLUDE_DIR (found
suitable version "1.10", minimum required is "1.7")
in this change, the version spec is not specified when calling
`pkg_check_modules()`. so, `PKG_${component}_VERSION` is always set.
and we can always delegate the version checking to
`find_package_handle_standard_args()`. please note, we use the lower
version returned by pkg-config if multiple components are required and
both pkg-config settings return their versions.
Signed-off-by: Kefu Chai <kchai@redhat.com>
2021-04-26 03:26:11 +00:00
|
|
|
pkg_check_modules(PKG_${component} QUIET "lib${component}")
|
2021-04-03 13:32:36 +00:00
|
|
|
if(NOT pmem_VERSION_STRING OR PKG_${component}_VERSION VERSION_LESS pmem_VERSION_STRING)
|
|
|
|
set(pmem_VERSION_STRING ${PKG_${component}_VERSION})
|
|
|
|
endif()
|
2021-04-03 12:57:41 +00:00
|
|
|
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})
|
2021-03-05 06:04:23 +00:00
|
|
|
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()
|
2019-07-10 15:30:47 +00:00
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(pmem
|
2021-04-03 13:32:36 +00:00
|
|
|
REQUIRED_VARS pmem_INCLUDE_DIRS pmem_LIBRARIES
|
|
|
|
VERSION_VAR pmem_VERSION_STRING)
|
2019-07-10 15:30:47 +00:00
|
|
|
|
|
|
|
mark_as_advanced(
|
2021-03-05 06:04:23 +00:00
|
|
|
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()
|
2019-07-10 15:30:47 +00:00
|
|
|
endif()
|