build: cmake: find Thrift before using it

we should find Thrift library before using it. in this change,
FindThrift.cmake is added to find Thrift library.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
Kefu Chai
2023-02-25 10:27:12 +08:00
parent f30e7f9da1
commit 607858db51
2 changed files with 49 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ find_package(ZLIB REQUIRED)
find_package(ICU COMPONENTS uc i18n REQUIRED)
find_package(absl REQUIRED)
find_package(libdeflate REQUIRED)
find_package(Thrift REQUIRED)
find_package(xxHash REQUIRED)
set(scylla_gen_build_dir "${CMAKE_BINARY_DIR}/gen")
@@ -326,10 +327,10 @@ target_link_libraries(scylla PRIVATE
ZLIB::ZLIB
ICU::uc
systemd
Thrift::thrift
zstd
snappy
${LUA_LIBRARIES}
thrift
crypt
xxHash::xxhash)

47
cmake/FindThrift.cmake Normal file
View File

@@ -0,0 +1,47 @@
#
# Copyright 2023-present ScyllaDB
#
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_thrift QUIET thrift)
find_library(thrift_LIBRARY
NAMES thrift
HINTS
${PC_thrift_LIBDIR}
${PC_thrift_LIBRARY_DIRS})
find_path(thrift_INCLUDE_DIR
NAMES thrift/Thrift.h
HINTS
${PC_thrift_INCLUDEDIR}
${PC_thrift_INCLUDE_DIRS})
mark_as_advanced(
thrift_LIBRARY
thrift_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Thrift
REQUIRED_VARS
thrift_LIBRARY
thrift_INCLUDE_DIR
VERSION_VAR PC_thrift_VERSION)
if(Thrift_FOUND)
set(thrift_LIBRARIES ${thrift_LIBRARY})
set(thrift_INCLUDE_DIRS ${thrift_INCLUDE_DIR})
if(NOT(TARGET Thrift::thrift))
add_library(Thrift::thrift UNKNOWN IMPORTED)
set_target_properties(Thrift::thrift
PROPERTIES
IMPORTED_LOCATION ${thrift_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${thrift_INCLUDE_DIRS})
endif()
endif()