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