-
Notifications
You must be signed in to change notification settings - Fork 21
/
FindThrift.cmake
91 lines (83 loc) · 3.05 KB
/
FindThrift.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# - Find Thrift (a cross platform RPC lib/tool)
# This module defines
# THRIFT_VERSION_STRING, version string of ant if found
# THRIFT_LIBRARIES, libraries to link
# THRIFT_INCLUDE_DIR, where to find THRIFT headers
# THRIFT_COMPILER, thrift compiler executable
# THRIFT_FOUND, If false, do not try to use ant
# Function
# thrift_gen_cpp(<path to thrift file> <output variable with file list>)
#
# Initial work was done by Cloudera https://github.com/cloudera/Impala
# 2014 - modified by snikulov
# prefer the thrift version supplied in THRIFT_HOME (cmake -DTHRIFT_HOME then environment)
find_path(THRIFT_INCLUDE_DIR
NAMES
thrift/Thrift.h
HINTS
${THRIFT_HOME}
ENV THRIFT_HOME
/usr/local
/opt/local
PATH_SUFFIXES
include
)
# prefer the thrift version supplied in THRIFT_HOME
find_library(THRIFT_LIBRARIES
NAMES
thrift libthrift
HINTS
${THRIFT_HOME}
ENV THRIFT_HOME
/usr/local
/opt/local
PATH_SUFFIXES
lib lib64
)
find_program(THRIFT_COMPILER
NAMES
thrift
HINTS
${THRIFT_HOME}
ENV THRIFT_HOME
/usr/local
/opt/local
PATH_SUFFIXES
bin bin64
)
if (THRIFT_COMPILER)
exec_program(${THRIFT_COMPILER}
ARGS -version OUTPUT_VARIABLE __thrift_OUT RETURN_VALUE THRIFT_RETURN)
string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+-[a-z]+$" THRIFT_VERSION_STRING ${__thrift_OUT})
# define utility function to generate cpp files
function(thrift_gen_cpp thrift_file THRIFT_CPP_FILES_LIST THRIFT_GEN_INCLUDE_DIR)
set(_res)
set(_res_inc_path)
if(EXISTS ${thrift_file})
get_filename_component(_target_dir ${thrift_file} NAME_WE)
message("thrif_gen_cpp: ${thrift_file}")
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${_target_dir})
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${_target_dir})
endif()
exec_program(${THRIFT_COMPILER}
ARGS -o "${CMAKE_BINARY_DIR}/${_target_dir}" --gen cpp ${thrift_file}
OUTPUT_VARIABLE __thrift_OUT
RETURN_VALUE THRIFT_RETURN)
file(GLOB_RECURSE __result_src "${CMAKE_BINARY_DIR}/${_target_dir}/*.cpp")
file(GLOB_RECURSE __result_hdr "${CMAKE_BINARY_DIR}/${_target_dir}/*.h")
list(APPEND _res ${__result_src})
list(APPEND _res ${__result_hdr})
if(__result_hdr)
list(GET __result_hdr 0 _res_inc_path)
get_filename_component(_res_inc_path ${_res_inc_path} DIRECTORY)
endif()
else()
message("thrift_gen_cpp: file ${thrift_file} does not exists")
endif()
set(${THRIFT_CPP_FILES_LIST} "${_res}" PARENT_SCOPE)
set(${THRIFT_GEN_INCLUDE_DIR} "${_res_inc_path}" PARENT_SCOPE)
endfunction()
endif ()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(THRIFT DEFAULT_MSG THRIFT_LIBRARIES THRIFT_INCLUDE_DIR THRIFT_COMPILER)
mark_as_advanced(THRIFT_LIBRARIES THRIFT_INCLUDE_DIR THRIFT_COMPILER THRIFT_VERSION_STRING)