forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThriftGenerate.cmake
138 lines (125 loc) · 4.25 KB
/
ThriftGenerate.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# Requirements:
# Please provide the following two variables before using these macros:
# ${THRIFT1} - path/to/bin/thrift1
# ${THRIFT_TEMPLATES} - path/to/include/thrift/templates
# ${THRIFTCPP2} - path/to/lib/thriftcpp2
#
#
# bypass_source_check
# This tells cmake to ignore if it doesn't see the following sources in
# the library that will be installed. Thrift files are generated at compile
# time so they do not exist at source check time
#
# Params:
# @sources - The list of files to ignore in source check
#
macro(bypass_source_check sources)
set_source_files_properties(
${sources}
PROPERTIES GENERATED TRUE
)
endmacro()
#
# thrift_generate
# This is used to codegen thrift files using the thrift compiler
# Params:
# @file_name - The name of tge thrift file
# @services - A list of services that are declared in the thrift file
# @output_path - The directory where the thrift file lives
#
# Output:
# file-cpp2-target - A custom target to add a dependency
# ${file-cpp2-HEADERS} - The generated Header Files.
# ${file-cpp2-SOURCES} - The generated Source Files.
#
# Notes:
# If any of the fields is empty, it is still required to provide an empty string
#
# When using file_cpp2-SOURCES it should always call:
# bypass_source_check(${file_cpp2-SOURCES})
# This will prevent cmake from complaining about missing source files
#
macro(thrift_generate file_name services file_path output_path include_prefix)
set("${file_name}-cpp2-HEADERS"
${output_path}/gen-cpp2/${file_name}_constants.h
${output_path}/gen-cpp2/${file_name}_data.h
${output_path}/gen-cpp2/${file_name}_types.h
${output_path}/gen-cpp2/${file_name}_types_custom_protocol.h
${output_path}/gen-cpp2/${file_name}_types.tcc
)
set("${file_name}-cpp2-SOURCES"
${output_path}/gen-cpp2/${file_name}_constants.cpp
${output_path}/gen-cpp2/${file_name}_data.cpp
${output_path}/gen-cpp2/${file_name}_metadata.cpp
${output_path}/gen-cpp2/${file_name}_types.cpp
)
foreach(service ${services})
set("${file_name}-cpp2-HEADERS"
${${file_name}-cpp2-HEADERS}
${output_path}/gen-cpp2/${service}.h
${output_path}/gen-cpp2/${service}.tcc
${output_path}/gen-cpp2/${service}AsyncClient.h
${output_path}/gen-cpp2/${service}_custom_protocol.h
)
set("${file_name}-cpp2-SOURCES"
${${file_name}-cpp2-SOURCES}
${output_path}/gen-cpp2/${service}.cpp
${output_path}/gen-cpp2/${service}AsyncClient.cpp
${output_path}/gen-cpp2/${service}_processmap_binary.cpp
${output_path}/gen-cpp2/${service}_processmap_compact.cpp
)
endforeach()
add_custom_command(
OUTPUT ${${file_name}-cpp2-HEADERS} ${${file_name}-cpp2-SOURCES}
COMMAND ${THRIFT1}
--strict "--allow-neg-enum-vals"
--gen "mstch_cpp2:include_prefix=${include_prefix},stack_arguments"
--gen "py"
--gen "js:node:"
--gen "csharp"
--gen "java:hashcode"
--gen "go:thrift_import=github.com/facebook/fbthrift/thrift/lib/go/thrift,package_prefix=github.com/vesoft-inc/nebula-go/v3/,use_context"
-o "." "${file_path}/${file_name}.thrift"
COMMAND
mkdir -p "./gen-rust/${file_name}"
&& ${THRIFT1}
--strict "--allow-neg-enum-vals"
--gen "mstch_rust"
-o "gen-rust/${file_name}"
"${file_path}/${file_name}.thrift"
&& ( mv ./gen-rust/${file_name}/gen-rust/lib.rs ./gen-rust/${file_name} )
&& ( rm -r ./gen-rust/${file_name}/gen-rust/ )
DEPENDS "${file_path}/${file_name}.thrift"
COMMENT "Generating thrift files for ${file_name}"
)
bypass_source_check(${${file_name}-cpp2-SOURCES})
add_custom_target(
${file_name}_thrift_generator
DEPENDS ${${file_name}-cpp2-HEADERS} ${${file_name}-cpp2-SOURCES}
)
add_library(
"${file_name}_thrift_obj"
OBJECT
${${file_name}-cpp2-SOURCES}
)
add_dependencies(${file_name}_thrift_obj ${file_name}_thrift_generator)
set_target_properties(
"${file_name}_thrift_obj"
PROPERTIES CXX_CLANG_TIDY ""
)
target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-pedantic")
target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-extra")
if(NOT "${file_name}" STREQUAL "common")
add_dependencies(
${file_name}_thrift_obj
common_thrift_generator
)
endif()
if("${file_name}" STREQUAL "storage")
add_dependencies(
${file_name}_thrift_obj
meta_thrift_generator
)
endif()
endmacro()