-
Notifications
You must be signed in to change notification settings - Fork 62
/
CMakeLists.txt
209 lines (185 loc) · 7.86 KB
/
CMakeLists.txt
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#----------------------------------------------------------------------
#----------------------------------------------------------------------
cmake_minimum_required(VERSION 3.5.1)
cmake_policy(SET CMP0091 NEW)
project(labview-grpc C CXX)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
# Set default visibility to hidden, only export LIBRARY_EXPORT symbols from the shared library
add_compile_options(-fvisibility=hidden)
else()
add_definitions(-D_WIN32_WINNT=0x600)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244")
add_compile_options("$<$<NOT:$<CONFIG:Debug>>:/Zi>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/DEBUG>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:REF>")
add_link_options("$<$<NOT:$<CONFIG:Debug>>:/OPT:ICF>")
endif()
find_package(Threads REQUIRED)
# Setup ASIO
set(ASIO_ROOT "${CMAKE_SOURCE_DIR}/third_party/asio")
set(ASIO_INCLUDE_DIRS "${ASIO_ROOT}/asio/include")
#----------------------------------------------------------------------
#----------------------------------------------------------------------
message( ${CMAKE_SIZEOF_VOID_P} )
#----------------------------------------------------------------------
#----------------------------------------------------------------------
add_definitions(-D_PS_${CMAKE_SIZEOF_VOID_P})
#----------------------------------------------------------------------
# Include the gRPC's cmake build
#----------------------------------------------------------------------
add_subdirectory(third_party/grpc ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL)
#----------------------------------------------------------------------
# Use the grpc targets directly from this build.
#----------------------------------------------------------------------
set(_PROTOBUF_LIBPROTOBUF libprotobuf)
set(_REFLECTION grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
else()
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()
set(_GRPC_GRPCPP grpc++)
if(CMAKE_CROSSCOMPILING)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)
endif()
#----------------------------------------------------------------------
# Include generated *.pb.h files
#----------------------------------------------------------------------
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "./src" "./third_party/grpc" "${CMAKE_CURRENT_BINARY_DIR}/gens" "${ASIO_INCLUDE_DIRS}")
#----------------------------------------------------------------------
# LabVIEW support for grpc and protobuf
#----------------------------------------------------------------------
add_custom_target(Detect_Compatibility_Breaks
COMMAND ${CMAKE_COMMAND} -E echo "Detecting backward compatibility breakage ..."
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeTests/run_test.py
RESULT_VARIABLE shell_command_result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_library(labview_grpc_server SHARED
src/any_support.cc
src/cluster_copier.cc
src/event_data.cc
src/feature_toggles.cc
src/grpc_client.cc
src/grpc_interop.cc
src/grpc_load.cc
src/grpc_server.cc
src/lv_interop.cc
src/lv_message.cc
src/lv_message_efficient.cc
src/lv_message_value.cc
src/lv_proto_server_reflection_plugin.cc
src/lv_proto_server_reflection_service.cc
src/message_element_metadata_owner.cc
src/unpacked_fields.cc
)
target_link_libraries(labview_grpc_server
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
#----------------------------------------------------------------------
# LabVIEW code generator support library to generate client and
# server VIs from a .proto file
#----------------------------------------------------------------------
add_library(labview_grpc_generator SHARED
src/feature_toggles.cc
src/lv_interop.cc
src/proto_parser.cc
)
target_link_libraries(labview_grpc_generator
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
#######################################################################
# QueryServer Example
#######################################################################
#----------------------------------------------------------------------
# Proto file
#----------------------------------------------------------------------
get_filename_component(qs_proto "examples/query_server/Protos/query_server.proto" ABSOLUTE)
get_filename_component(qs_proto_path "${qs_proto}" PATH)
#----------------------------------------------------------------------
# Generated sources
#----------------------------------------------------------------------
set(qs_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/query_server.pb.cc")
set(qs_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/query_server.pb.h")
set(qs_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/query_server.grpc.pb.cc")
set(qs_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/query_server.grpc.pb.h")
add_custom_command(
OUTPUT "${qs_proto_srcs}" "${qs_proto_hdrs}" "${qs_grpc_srcs}" "${qs_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
-I="${qs_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${qs_proto}"
DEPENDS "${qs_proto}")
#----------------------------------------------------------------------
# Example C++ application to talk to the example query server
#----------------------------------------------------------------------
add_executable(example_client
"src/example_client.cc"
${qs_proto_srcs}
${qs_grpc_srcs}
)
target_link_libraries(example_client
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
#######################################################################
# Testing Project
#######################################################################
#----------------------------------------------------------------------
# Proto file
#----------------------------------------------------------------------
get_filename_component(dm_proto "tests/Deprecated/Protos/data_marshal.proto" ABSOLUTE)
get_filename_component(dm_proto_path "${dm_proto}" PATH)
#----------------------------------------------------------------------
# Generated sources
#----------------------------------------------------------------------
set(dm_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/data_marshal.pb.cc")
set(dm_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/data_marshal.pb.h")
set(dm_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/data_marshal.grpc.pb.cc")
set(dm_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/data_marshal.grpc.pb.h")
add_custom_command(
OUTPUT "${dm_proto_srcs}" "${dm_proto_hdrs}" "${dm_grpc_srcs}" "${dm_grpc_hdrs}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
-I="${dm_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${dm_proto}"
DEPENDS "${dm_proto}")
#----------------------------------------------------------------------
# Test client application
#----------------------------------------------------------------------
add_executable(test_client
"src/test_client.cc"
${dm_proto_srcs}
${dm_grpc_srcs}
)
target_link_libraries(test_client
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
#----------------------------------------------------------------------
# Test server application
#----------------------------------------------------------------------
add_executable(test_server
"src/test_server.cc"
${dm_proto_srcs}
${dm_grpc_srcs}
)
target_link_libraries(test_server
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
add_dependencies(labview_grpc_server Detect_Compatibility_Breaks)
add_dependencies(labview_grpc_generator Detect_Compatibility_Breaks)
add_dependencies(test_client Detect_Compatibility_Breaks)
add_dependencies(test_server Detect_Compatibility_Breaks)
add_dependencies(example_client Detect_Compatibility_Breaks)