]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/cmake_modules/FindThrift.cmake
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / arrow / cpp / cmake_modules / FindThrift.cmake
CommitLineData
1d09f67e
TL
1# Copyright 2012 Cloudera Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# - Find Thrift (a cross platform RPC lib/tool)
16#
17# Variables used by this module, they can change the default behaviour and need
18# to be set before calling find_package:
19#
20# Thrift_ROOT - When set, this path is inspected instead of standard library
21# locations as the root of the Thrift installation.
22# The environment variable THRIFT_HOME overrides this variable.
23#
24# This module defines
25# THRIFT_VERSION, version string of ant if found
26# THRIFT_INCLUDE_DIR, where to find THRIFT headers
27# THRIFT_LIB, THRIFT library
28# THRIFT_FOUND, If false, do not try to use ant
29
30function(EXTRACT_THRIFT_VERSION)
31 if(THRIFT_INCLUDE_DIR)
32 file(READ "${THRIFT_INCLUDE_DIR}/thrift/config.h" THRIFT_CONFIG_H_CONTENT)
33 string(REGEX MATCH "#define PACKAGE_VERSION \"[0-9.]+\"" THRIFT_VERSION_DEFINITION
34 "${THRIFT_CONFIG_H_CONTENT}")
35 string(REGEX MATCH "[0-9.]+" THRIFT_VERSION "${THRIFT_VERSION_DEFINITION}")
36 set(THRIFT_VERSION
37 "${THRIFT_VERSION}"
38 PARENT_SCOPE)
39 else()
40 set(THRIFT_VERSION
41 ""
42 PARENT_SCOPE)
43 endif()
44endfunction(EXTRACT_THRIFT_VERSION)
45
46if(MSVC_TOOLCHAIN AND NOT DEFINED THRIFT_MSVC_LIB_SUFFIX)
47 if(NOT ARROW_THRIFT_USE_SHARED)
48 if(ARROW_USE_STATIC_CRT)
49 set(THRIFT_MSVC_LIB_SUFFIX "mt")
50 else()
51 set(THRIFT_MSVC_LIB_SUFFIX "md")
52 endif()
53 endif()
54endif()
55set(THRIFT_LIB_NAME_BASE "thrift${THRIFT_MSVC_LIB_SUFFIX}")
56
57if(ARROW_THRIFT_USE_SHARED)
58 set(THRIFT_LIB_NAMES thrift)
59 if(CMAKE_IMPORT_LIBRARY_SUFFIX)
60 list(APPEND
61 THRIFT_LIB_NAMES
62 "${CMAKE_IMPORT_LIBRARY_PREFIX}${THRIFT_LIB_NAME_BASE}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
63 )
64 endif()
65 list(APPEND
66 THRIFT_LIB_NAMES
67 "${CMAKE_SHARED_LIBRARY_PREFIX}${THRIFT_LIB_NAME_BASE}${CMAKE_SHARED_LIBRARY_SUFFIX}"
68 )
69else()
70 set(THRIFT_LIB_NAMES
71 "${CMAKE_STATIC_LIBRARY_PREFIX}${THRIFT_LIB_NAME_BASE}${CMAKE_STATIC_LIBRARY_SUFFIX}"
72 )
73endif()
74
75if(Thrift_ROOT)
76 find_library(THRIFT_LIB
77 NAMES ${THRIFT_LIB_NAMES}
78 PATHS ${Thrift_ROOT}
79 PATH_SUFFIXES "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "lib")
80 find_path(THRIFT_INCLUDE_DIR thrift/Thrift.h
81 PATHS ${Thrift_ROOT}
82 PATH_SUFFIXES "include")
83 find_program(THRIFT_COMPILER thrift
84 PATHS ${Thrift_ROOT}
85 PATH_SUFFIXES "bin")
86 extract_thrift_version()
87else()
88 # THRIFT-4760: The pkgconfig files are currently only installed when using autotools.
89 # Starting with 0.13, they are also installed for the CMake-based installations of Thrift.
90 find_package(PkgConfig QUIET)
91 pkg_check_modules(THRIFT_PC thrift)
92 if(THRIFT_PC_FOUND)
93 set(THRIFT_INCLUDE_DIR "${THRIFT_PC_INCLUDEDIR}")
94
95 list(APPEND THRIFT_PC_LIBRARY_DIRS "${THRIFT_PC_LIBDIR}")
96
97 find_library(THRIFT_LIB
98 NAMES ${THRIFT_LIB_NAMES}
99 PATHS ${THRIFT_PC_LIBRARY_DIRS}
100 NO_DEFAULT_PATH)
101 find_program(THRIFT_COMPILER thrift
102 HINTS ${THRIFT_PC_PREFIX}
103 NO_DEFAULT_PATH
104 PATH_SUFFIXES "bin")
105 set(THRIFT_VERSION ${THRIFT_PC_VERSION})
106 else()
107 find_library(THRIFT_LIB
108 NAMES ${THRIFT_LIB_NAMES}
109 PATH_SUFFIXES "lib/${CMAKE_LIBRARY_ARCHITECTURE}" "lib")
110 find_path(THRIFT_INCLUDE_DIR thrift/Thrift.h PATH_SUFFIXES "include")
111 find_program(THRIFT_COMPILER thrift PATH_SUFFIXES "bin")
112 extract_thrift_version()
113 endif()
114endif()
115
116if(THRIFT_COMPILER)
117 set(Thrift_COMPILER_FOUND TRUE)
118else()
119 set(Thrift_COMPILER_FOUND FALSE)
120endif()
121
122find_package_handle_standard_args(
123 Thrift
124 REQUIRED_VARS THRIFT_LIB THRIFT_INCLUDE_DIR
125 VERSION_VAR THRIFT_VERSION
126 HANDLE_COMPONENTS)
127
128if(Thrift_FOUND OR THRIFT_FOUND)
129 set(Thrift_FOUND TRUE)
130 if(ARROW_THRIFT_USE_SHARED)
131 add_library(thrift::thrift SHARED IMPORTED)
132 else()
133 add_library(thrift::thrift STATIC IMPORTED)
134 endif()
135 set_target_properties(thrift::thrift
136 PROPERTIES IMPORTED_LOCATION "${THRIFT_LIB}"
137 INTERFACE_INCLUDE_DIRECTORIES "${THRIFT_INCLUDE_DIR}")
138 if(WIN32 AND NOT MSVC_TOOLCHAIN)
139 # We don't need this for Visual C++ because Thrift uses
140 # "#pragma comment(lib, "Ws2_32.lib")" in
141 # thrift/windows/config.h for Visual C++.
142 set_target_properties(thrift::thrift PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32")
143 endif()
144endif()