ceph/cmake/modules/FindZstd.cmake
Kefu Chai 16fd07244d cmake: allow use libzstd in system
since we are moving the test nodes from bionic to focal, we are able to
use the prebuilt libzstd libraries when running "make check". to speed
up the build and test, in this change:

* add FindZstd.cmake which allows us to use the libzstd in system
* extract BuildZstd.cmake for better readability
* add an option named "WITH_SYSTEM_ZSTD", which defaults to "OFF",
  so user can enable it on demand.

Signed-off-by: Kefu Chai <kchai@redhat.com>
2021-03-31 12:53:39 +08:00

52 lines
1.5 KiB
CMake

# Try to find liblz4
#
# Once done, this will define
#
# Zstd_FOUND
# Zstd_INCLUDE_DIRS
# Zstd_LIBRARIES
# Zstd_VERSION_STRING
# Zstd_VERSION_MAJOR
# Zstd_VERSION_MINOR
# Zstd_VERSION_RELEASE
find_path(Zstd_INCLUDE_DIR
NAMES zstd.h
HINTS ${Zstd_ROOT_DIR}/include)
if(Zstd_INCLUDE_DIR AND EXISTS "${Zstd_INCLUDE_DIR}/zstd.h")
foreach(ver "MAJOR" "MINOR" "RELEASE")
file(STRINGS "${Zstd_INCLUDE_DIR}/zstd.h" Zstd_VER_${ver}_LINE
REGEX "^#define[ \t]+ZSTD_VERSION_${ver}[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+ZSTD_VERSION_${ver}[ \t]+([0-9]+)$"
"\\1" Zstd_VERSION_${ver} "${Zstd_VER_${ver}_LINE}")
unset(${Zstd_VER_${ver}_LINE})
endforeach()
set(Zstd_VERSION_STRING
"${Zstd_VERSION_MAJOR}.${Zstd_VERSION_MINOR}.${Zstd_VERSION_RELEASE}")
endif()
find_library(Zstd_LIBRARY
NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}zstd.${CMAKE_STATIC_LIBRARY_SUFFIX}" zstd
HINTS ${Zstd_ROOT_DIR}/lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Zstd
REQUIRED_VARS Zstd_LIBRARY Zstd_INCLUDE_DIR
VERSION_VAR Zstd_VERSION_STRING)
mark_as_advanced(
Zstd_LIBRARY
Zstd_INCLUDE_DIR)
if(Zstd_FOUND AND NOT (TARGET Zstd::Zstd))
set(Zstd_INCLUDE_DIRS ${Zstd_INCLUDE_DIR})
set(Zstd_LIBRARIES ${Zstd_LIBRARY})
add_library (Zstd::Zstd UNKNOWN IMPORTED)
set_target_properties(Zstd::Zstd PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Zstd_INCLUDE_DIR}
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION ${Zstd_LIBRARY}
VERSION "${Zstd_VERSION_STRING}")
endif()